Beruflich Dokumente
Kultur Dokumente
Instructor: <Name>
04e-BM/NS/HDCV/FSOFT v2/3
Agenda
General Introduction Class Modeling Dynamic Modeling Functional Modeling Add Operations to the Class Model
OMT: Four phases
04e-BM/NS/HDCV/FSOFT v2/3
General Introduction
Object Oriented Software Development
Object-Oriented Methodology
development approach used to build complex systems using the concepts of object, class, polymorphism, and inheritance with a view towards reusability encourages software engineers to think of the problem in terms of the application domain early and apply a consistent approach throughout the entire life-cycle
04e-BM/NS/HDCV/FSOFT v2/3
General Introduction
Software Design
a detailed design
a specification of the abstract interface, data structures, and algorithms of each module
Also develops
a review plan for ensuring the design meets the requirements a test plan for ensuring the implementation meets the design
04e-BM/NS/HDCV/FSOFT v2/3
General Introduction
Object-Oriented Analysis 1/2
Model is more precise and concise than the informal problem definition The model addresses three aspects of objects
class structure and relationships sequencing of interactions and events data transformations and computations
04e-BM/NS/HDCV/FSOFT v2/3
General Introduction
Object-Oriented Analysis 2/2
Class Model
static structure what objects are in the system? how are they related?
Data-Oriented
Dynamic Model
behavioral aspects what events occur in the system when do they occur and in what order?
Action-Oriented
04e-BM/NS/HDCV/FSOFT v2/3
General Introduction
OMT & UML (OMT turned into UML)
04e-BM/NS/HDCV/FSOFT v2/3
General Introduction
What is UML?
The Unified Modeling Language (UML) is a standard language for
Specifying
Visualizing
Constructing
Documenting
Business Modeling
Communications
General Introduction
OMT Stages & Models
Object Model - Static structure of objects and their relationships (object diagram) Analysis - Model of real-world situation - What ? System Design - Overall architecture (sub-systems) Object Design - Refinement of Design - Algorithms/data structures to implement each class Implementation - Translation of object classes and relationships to a particular object-oriented language
time
System
04e-BM/NS/HDCV/FSOFT v2/3
General Introduction
OO Analysis & Design Steps
Class Modeling Dynamic Modeling Functional Modeling Add Operations to the Class Model Iterate and refine the models
After the first iteration, steps may occur in parallel or out of order All models must be kept in synch as changes are made
04e-BM/NS/HDCV/FSOFT v2/3
Class Modeling
Identify objects and classes Prepare a data dictionary Identify associations between objects Identify class attributes and initial set of operations Organize object classes using inheritance
04e-BM/NS/HDCV/FSOFT v2/3
Class Modeling
What is an object?
Operation/Behavior Method inside class Consists of things that the object know how to do
Class Modeling
Abstraction
Abstract info
Polygon Attributes: - vertices - border color - fill color Operations: - draw - erase - move
04e-BM/NS/HDCV/FSOFT v2/3
Class Modeling
Domain Analysis
Natural Language
Problem Domain
Some are attributes of another Class. Some are irrelevant, outside the scope of the application.
Class Modeling
Classes Identifying 1/2
Class is an abstract description of a set of objects Class defines methods, variables for a kind of object We actually write code for a class, not object Use class as a blue-print to create (instantiate) an object
Polygon Attributes: - vertices - border color - fill color Operations: - draw - erase - move
04e-BM/NS/HDCV/FSOFT v2/3
Class Modeling
Classes Identifying 2/2
Finding classes:
Use domain analysis as before. Derive them from the use cases (descriptions). Look for data which must be stored or analysed. Are there external systems? Are there any devices under the control of the system? Are there any organisational parts?
04e-BM/NS/HDCV/FSOFT v2/3
Class Modeling
Classes, Attributes & Operations
Class
ball football baseball
FPT SOFTWARE TRAINING MATERIAL Internal use
Attributes
radius, weight air pressure liveness
Operations
Class Modeling
Attributes
Describe the state and characteristics of the object. Must be typed, primitives like integer, real, Boolean, point, area, enumeration, these are primitives. May be language specific. Visibility may be public, private or protected. Class variables have scope across every instance of class, change one changes all (static attributes) Syntax
visibility name : type-expression = initial-value {property-string}
Class Modeling
Operations
Operations manipulate attributes and perform other tasks. Scope is the Class. Operation signature is composed of name, parameters and return type.
name(parameter-list) return-type-expression
19
04e-BM/NS/HDCV/FSOFT v2/3
Class Modeling
Object Model Notation
Class Name
InstanceVariable1 InstanceVariable2: type
Method1() Method2(arguments) return type
Classes are represented as rectangles; The class name is at the top, followed by attributes (instance variables) and methods (operations) Depending on context some information can be hidden such as types or method arguments
(Class Name)
InstanceVariable1 = value InstanceVariable2: type
Method1() Method2(arguments) return type
Objects are represented as rounded rectangles; The objects name is its classname surrounded by parentheses Instance variables can display the values that they have been assigned; pointer types will often point (not shown) to the object being referenced
04e-BM/NS/HDCV/FSOFT v2/3
Class Modeling
Encapsulation
Allow to show only the important methods as interface Hide detail information
Hide the data item Hide the implementation Access to data item only through member methods
04e-BM/NS/HDCV/FSOFT v2/3
Class Modeling
Access modifiers
04e-BM/NS/HDCV/FSOFT v2/3
Class Modeling
Information Hiding
Implemented by the Private access modifier Hidden methods, member data can only be accessed by member methods Benefit:
Your brains doesnt have to deal with it unless youre specifically concerned with it When change occurs, the effects are localized
04e-BM/NS/HDCV/FSOFT v2/3
Class Modeling
Class Diagram
Name
Class diagrams show the classes of the system, their interrelationships (including inheritance, aggregation, and association), and the operations and attributes of the classes. Inheritance
Relations Associations Aggregation
Attributes Operations
24
04e-BM/NS/HDCV/FSOFT v2/3
Class Modeling
Inheritance
Classes with a set of similar attributes and operations may be organized into a hierarchical relationship Common attributes and operations are factored out and assigned to a broad superclass (generalization)
generalization is the is-a relationship superclasses are ancestors, subclasses are descendants
A class can be iteratively refined into subclasses that inherit the attributes and operations of the superclass (specialization)
04e-BM/NS/HDCV/FSOFT v2/3
Class Modeling
OMT Inheritance Notation
Generalization
Superclass
Class Attributes Operations Ball Radius, Weight Throw, Catch
Subclasses Football air pressure pass, kick, hand-off Baseball liveness hit, pitch, tag Basketball air pressure , dimples shoot, dribble, pass
Specialization
04e-BM/NS/HDCV/FSOFT v2/3
Class Modeling
Multiple & Multilevel Inheritance
Single inheritance: Inherit from only one super class Multiple inheritance: a class have common characteristics with more than one super class
04e-BM/NS/HDCV/FSOFT v2/3
Class Modeling
Advantages of Inheritance
Development model closer to real life object model with hierarchical relationships Reusability reuse public methods of base class Extensibility Extend the base class Data hiding base class keeps some data private derive class cannot change it Rapid prototyping
04e-BM/NS/HDCV/FSOFT v2/3
Class Modeling
Associations
Associations model Class relationships. Associations should be named where appropriate. Usual to use verbs from the problem domain. Roles played by classes may also be named. Associations have a cardinality. Rules from programming about sensible names apply.
29
04e-BM/NS/HDCV/FSOFT v2/3
Class Modeling
Associations & Cardinality
Class1 Exactly One (default) Association Name Class2 Class * Class
Zero or more
Optional (zero or one) One or more Numerically specified
FPT SOFTWARE TRAINING MATERIAL Internal use
0..1 Class
1.. * Class
1..5,8 Class
04e-BM/NS/HDCV/FSOFT v2/3
30
Class Modeling
Aggregation
Aggregation is a special form of association that indicates a part-of relationship between a whole and its parts Useful when the parts do not have independent existence
A part is subordinate to the whole
In an aggregation, properties and operations may be propagated from the whole to its parts
04e-BM/NS/HDCV/FSOFT v2/3
Class Modeling
OMT Aggregation Notation
Window
TitleBar
ScrollBar
Border
04e-BM/NS/HDCV/FSOFT v2/3
Class Modeling
Multilevel Aggregation
Microcomputer
1+
Monitor
System box
Mouse
Keyboard
1+
1+
Chassis
CPU
RAM
Fan
04e-BM/NS/HDCV/FSOFT v2/3
Class Modeling
Abstract class 1/2
Class that contains one or more abstract methods Abstract method: Method that has only declaration but no implementation.
Classes that extend abstract class make them concrete by implementing those abstract methods
04e-BM/NS/HDCV/FSOFT v2/3
Class Modeling
Abstract class 2/2
class animal { protected: int speed; char color[20]; public: pure virtual void init(); float run(int distance){ float time = round(((float) distance)/speed,2); cout<<It runs "<<distance<<miles in <<time<<hour. <<endl; return time; } pure virtual void show() ; };
04e-BM/NS/HDCV/FSOFT v2/3
Class Modeling
Polymorphism
Implemented by:
Overloading
function overloading operator overloading
Override
04e-BM/NS/HDCV/FSOFT v2/3
Class Modeling
Polymorphism - Overloading
To assign an operator, identifier or literal more than one meaning, depending upon the data types associated with it at any given time during program execution.
Two or more method with the same name, different signature Example:
void display (int iX) void display (float fY) void display (char[] chC) void display (char[] chC, int offset, int numchar)
04e-BM/NS/HDCV/FSOFT v2/3
Class Modeling
Polymorphism - Overriding
Process of defining/re-defining the methods in the derived class Methods have same name/same signature
04e-BM/NS/HDCV/FSOFT v2/3
Class Modeling
Polymorphism Example 1/2
class animal { protected: int speed; char color[20]; public: virtual void init(){} float run(int distance) { float time = round(((float) distance)/speed,2); cout<<It runs "<<distance<<miles in <<time<<hour. <<endl; return time; } virtual void show() {} };
FPT SOFTWARE TRAINING MATERIAL Internal use
04e-BM/NS/HDCV/FSOFT v2/3
Class Modeling
Polymorphism Example 2/2
class dog: public animal { public: void init() { speed = 40; strcpy(color, Black); } void show() { cout<<"Speed of a dog is "<<speed<< miles/hour<<endl; cout<<"Color of a dog is "<<color<<endl; } class tiger: public animal { public: void init() { speed = 90; strcpy(color, Red); } void show() { cout<<"Speed of a tiger is "<<speed<<miles/hour<<endl; cout<<"Color of a tiger is "<<color<<endl; } };
04e-BM/NS/HDCV/FSOFT v2/3
};
FPT SOFTWARE TRAINING MATERIAL Internal use
Dynamic Modeling
Prepare scenarios Identify events between objects Prepare an event trace for each scenario Build a state diagram Match events between objects to verify consistency
04e-BM/NS/HDCV/FSOFT v2/3
Dynamic Modeling
Dynamic Model Diagrams
State Diagrams
relates events, states, and state transitions a scenario is a path through the state diagram
04e-BM/NS/HDCV/FSOFT v2/3
Dynamic Modeling
Events & Scenarios
A scenario is a specific sequence of events representing a path through a systems states Legitimate scenarios
Common paths (e.g. frequently used functionality) Error conditions and known exceptions
04e-BM/NS/HDCV/FSOFT v2/3
Dynamic Modeling
Event classes & attributes
Event Classes
airplane departs (airline, flight number, city) mouse button pushed (button, location) phone receiver lifted digit dialed (digit)
Events
United Flight 23 departs from Rome right mouse button pushed at (29, 30) phone receiver lifted digit dialed (2)
04e-BM/NS/HDCV/FSOFT v2/3
Dynamic Modeling
An example scenario
04e-BM/NS/HDCV/FSOFT v2/3
Dynamic Modeling
OMT Event Trace Notation
arrows indicate sender and receiver time passes from top to bottom Credit Corp
Pump
04e-BM/NS/HDCV/FSOFT v2/3
Dynamic Modeling
Event Trace Example
Caller
caller lifts receiver dial tone begins dials (2)
Phone line
Callee
04e-BM/NS/HDCV/FSOFT v2/3
Dynamic Modeling
Event Trace ~ Sequence Diagram
Object: Class
A sequence diagram is An interaction diagram that details how operations are carried out. What messages are sent and when. Sequence diagrams are organized according to time
Dynamic Modeling
States & Transitions
04e-BM/NS/HDCV/FSOFT v2/3
Dynamic Modeling
State Machine Diagram
A State Machine diagram shows the possible states of the object and the transitions that cause a change in state.
Functional Modeling
Hierarchical DFD
04e-BM/NS/HDCV/FSOFT v2/3
Functional Modeling
DFD Example: Office Supply
Employee DB verification Web Server input stream name/ password employee AccountDB verification account number
validate employee
validate order
order
response (receipt)
Product DB
verification item validated order
Order DB
order info
order
order
process order
finalize order
response (receipt)
FPT SOFTWARE TRAINING MATERIAL Internal use
04e-BM/NS/HDCV/FSOFT v2/3
04e-BM/NS/HDCV/FSOFT v2/3
Object-oriented analysis
builds a real-world model
System design
determines overall architecture of system
Object design
decides upon data structures and algorithms
Implementation
translates design into programming language
04e-BM/NS/HDCV/FSOFT v2/3
Full definition of all the classes in the system Implementation alternatives evaluated and chosen Combine three models to obtain class operations Design algorithms to implement operations Optimize access paths to data Implement control for external interactions Adjust class structure to increase inheritance Design associations Determine object representation Package classes and associations into implementable modules
04e-BM/NS/HDCV/FSOFT v2/3
Detailed design is the process of completely specifying an architectural design such that module implementation can proceed (independently) Interface specifications
brief description of each module attributes
brief description and specify types
operations
brief description list of parameters and parameter types return type (if applicable)
04e-BM/NS/HDCV/FSOFT v2/3
04e-BM/NS/HDCV/FSOFT v2/3
etc.
This means that, in general, operations can be expressed in many different languages
04e-BM/NS/HDCV/FSOFT v2/3
If a design takes advantage of, or depends on, one or more of these features then certain programming languages have to be excluded from implementation
04e-BM/NS/HDCV/FSOFT v2/3
One import feature of any programming language is how it can represent modules directly
C and C++ have separate header and body files Java, .NET has package names and class files Ada has a construct called a package with a specification and body (implementation) etc.
These features are important since it makes it easier to map the design into code and to trace a code module back to its design counterpart
04e-BM/NS/HDCV/FSOFT v2/3
Q&A
04e-BM/NS/HDCV/FSOFT v2/3