Ooad Notes Units 2
Ooad Notes Units 2
INTRODUCTION
• Object-oriented methodology is a set of methods, models, and rules for developing
systems.
• Modelling is the process of describing an existing or proposed system. It can be used
during any phase of the software life cycle.
21
Fig. 2.1. OMT object model of a bank system
Boxes- represents classes, Filled Triangle – represents Specialization, Association between
account and transaction represents one to many, Filled Circle – represents many (zero or more).
Association between Client and Account represents one to one.
Fig. 2. 2. State transition diagram for the bank application user interface. The roundboxes
represent states and the arrows represent transitions.
22
THE OMT FUNCTIONAL MODEL
• The OMT data flow diagram (DFD) shows the flow of data between different
processes in a business.
1. - The process is any function being performed; for example, verify Password
or PIN in the ATM system (see Fig .3).
2. - The data flow shows the direction of data element movement; for example,
PIN code.
3. - The data store is a location where data are stored; for example, account is a
data store in the ATM example.
4. - An external entity is a source or destination of a data element; for example, the
ATM card reader.
23
THE MACRO DEVELOPMENT PROCESS
• The macro process serves as a controlling framework for the micro process.
• The primary concern of the macro process is technical management of the system.
5. Maintenance. Make localized changes to the system to add new requirements and
eliminate bugs.
24
Fig. 2.4. Object modeling using Booch notation
The arrows represent specialization; for example, the class Taurus is subclass ofthe class
Ford.
Fig. 2.5. An alarm class state transition diagram with Booch notation.
This diagram can capture the state of a class based on a stimulus. For example, a stimulus
causes the class to perform some processing, followed by a transition to anotherstate. In this
case, the alarm silenced state can be changed to alarm sounding state and vice versa.
25
2.3 THE JACOBSON METHODOLOGIES
• The Jacobson et al. methodologies (e.g., object-oriented Business Engineering
(OOBE), object-oriented Software Engineering (OOSE), and Objectory) cover the
entire life cycle and stress traceability between the different phases, both forward and
backward.
• This traceability enables reuse of analysis and design work, possibly much bigger
factors in the reduction of development time than reuse of code.
• At the heart of their methodologies is the use-case concept, which evolved with
Objectory (Object Factory for Software Development).
USE CASES
• Use cases are scenarios for understanding system requirements.
• A use case is an interaction between users and a system.
• The use-case model captures
- the goal of the user and
- the responsibility of the system to its users
26
• How and when the use case will need data stored in the system or will store data in
the system.
Exceptions to the flow of events.
• How and when concepts of the problem domain are handled.
Fig. 2.7. The use case model is considered in every model and phase.
2.4 PATTERNS
Definition:
A pattern is [an] instructive information that captures the essential structure and insight
of a successful family of proven solutions to a recurring problem that arises within a
certain context and system of forces.
• A pattern involves a general description of a solution to a recurring problem bundle
with various goals and constraints.
proto-pattern.
• A "pattern in waiting," which is not yet known to recur, sometimes is called a proto-
pattern.
ANTIPATTERNS
• A pattern represents a "best practice," whereas an antipattern represents "worst
practice" or a "lesson learned."
Anti-patterns come in two varieties:
• Those describing a bad solution to a problem that resulted in a bad situation.
• Those describing how to get out of a bad situation and how to proceed from there toa
good solution.
Anti-patterns are valuable because often it is just as important to see and understand badsolutions
as to see and understand good ones.
Capturing Patterns
• Writing good patterns is very difficult
• A pattern should help its users comprehend existing systems, customize systems tofit
user needs, and construct new systems.
• The process of looking for patterns to document is called pattern mining (or
sometimes reverse architecting).
29
2.5. FRAMEWORKS
A framework is a way of presenting a generic solution to a problem that can be applied
to all levels in a development.
A definition of an object-oriented software framework is given by Gamma:
- A framework is a set of cooperating classes that make up a reusable
design for a specific class of software.
- A framework provides architectural guidance by partitioning the design
into abstract classes and defining their responsibilities and
collaborations.
- A developer customizes a framework to a particular application by
subclassing and composing instances of framework classes.
- The framework captures the design decisions that are common to its
application domain.
- A single framework typically encompasses several design patterns.
In fact, a framework can be viewed as the implementation of a system of designpatterns.
30
3. Repository for object-oriented system development patterns and frameworks.
4. Component based development.
OBJECT-ORIENTED ANALYSIS
- Analysis is the process of extracting the needs of a system and what the system must do
to satisfy the users' requirements.
- The goal of object-oriented analysis is to first understand the domain of the problem and
the system's responsibilities by understanding how the users use or will use the system.
- This is accomplished by constructing several models of the system.
- These models concentrate on describing what the system does rather than how it doesit.
Separating the behavior of a system from the way it is implemented requires viewingthe
system from the user's perspective rather than that of the machine.
31
OBJECT-ORIENTED DESIGN
OOD Process consists of:
• Designing classes, their attributes, methods, associations, structures and protocols,
apply design axioms
• Design the Access Layer
• Design and prototype User interface
• User Satisfaction and Usability Tests based on the Usage/Use Cases
• Iterate and refine the design
34
WHY MODELING?
Building a model for a software system prior to its construction is as essential as having
a blueprint for building a large building. Good models are essential forcommunication among
project teams. As the complexity of systems increases, so does the importance of good
modeling techniques. Many other factors add to a project's success, but having a rigorous
modeling language is essential. A modeling language must include Model elements-
fundamental modeling concepts and semantics.
Is
• A way to describe your software
35
• more precise than English
• less detailed than code
UML DIAGRAMS
The UML defines nine graphical diagrams:
1. Class diagram (static)
2. Use-case diagram
3. Behavior diagrams (dynamic):
– 3.1. Interaction diagram:
• 3.1.1. Sequence diagram
• 3.1.2. Collaboration diagram
– 3.2. State chart diagram
4. Implementation diagram:
4.1. Component diagram
4.2. Deployment diagram
36
UML CLASS DIAGRAM
The UML class diagram, also referred to as object modelling, is the main static
analysis diagram. These diagrams show the static structure of the model.
A class diagram is a collection of static modeling elements, such as classes and their
relationships, connected as a graph to each other and to their contents; for example, the things
that exist (such as classes), their internal structures, and their relationships to other classes.
Class diagrams do not show temporal information, which is required in dynamic
modeling.
□ A class diagram describes the types of objects in the system and the various kinds
of static relationships that exist among them.
□ A graphical representation of a static view on declarative static elements.
□ A central modelling technique that runs through nearly all object-oriented
methods.
□ The richest notation in UML.
□ A class diagram shows the existence of classes and their relationships in the logical
view of a system
37
Fig. 2.12. In class notation, either or both the attributes and operation compartmentsmay be
suppressed.
Attributes
– Classes have attributes that describe the characteristics of their objects.
– Attributes are atomic entities with no responsibilities.
– Attribute syntax (partial):
o [visibility] name [: type] [ = default Value]
– Class scope attributes are underlined
Visibility
• Visibility describes whether an attribute or operation is visible and can be referenced
from classes other than the one in which they are defined.
• Language dependent
o Means different things in different languages
• UML provides four visibility abbreviations: + (public) – (private) # (protected)
~(package)
Object Diagram
A static object diagram is an instance of a class diagram. It shows a snapshot of the
detailed state of the system at a point in time. Notation is the same for an object diagram
and a class diagram. Class diagrams can contain objects, so a class diagram with objects and
no classes is an object diagram.
Class interface notation is used to describe the externally visible behavior of a class;
for example, an operation with public visibility. Identifying class interfaces is a design activity
of object-oriented system development.
The UML notation for an interface is a small circle with the name of the interface
38
connected to the class. A class that requires the operations in the interface may be attachedto
the circle by a dashed arrow. The dependent class is not required to actually use all of the
operations.
For example, a Person object may need to interact with the BankAccount object to get
the Balance; this relationship is depicted in Fig13. with UML class interface notation.
Association Role
A simple association- binary association-is drawn as a solid line connecting two class
symbols. The end of an association, where it connects to a class, shows the association role.
The role is part of the association, not part of the class. Each association has two or more roles
to which it is connected.
In above Fig14. the association worksfor connects two roles, employee and employer.
A Person is an employee of a Company and a Company is an employer of a Person.
The UML uses the term association navigation or navigability to specify a roleaffiliated
with each end of an association relationship. An arrow may be attached to the end of the path
39
to indicate that navigation is supported in the direction of the class pointed to. An arrow may
be attached to neither, one, or both ends of the path. In particular, arrows could be shown
whenever navigation is supported in a given direction.
In the UML, association is represented by an open arrow, as represented in Fig.15.
Navigability is visually distinguished from inheritance, which is denoted by an unfilled
arrowhead symbol near the superclass.
Qualifier
40
A qualifier is shown as a small rectangle attached to the end of an association path,
between the final path segment and the symbol of the class to which it connects. The qualifier
rectangle is part of the association path, not part of the class. The qualifier rectangle usually is
smaller than the attached class rectangle (see above Fig).
Multiplicity
Multiplicity specifies the range of allowable associated classes. It is given for roles
within associations, parts within compositions, repetitions, and other purposes. A multiplicity
specification is shown as a text string comprising a period-separated sequence of integer
intervals, where an interval represents a range of integers in this format (see Fig 17):
lower bound. upper bound.
The terms lower bound and upper bound are integer values, specifying the range of
integers including the lower bound to the upper bound. The star character (*) may be used for
the upper bound, denoting an unlimited upper bound. If a single integer value is specified, then
the integer range contains the single values.
OR Association
An OR association indicates a situation in which only one of several potential
associations may be instantiated at one time for any single object. This is shown as a dashed
line connecting two or more associations, all of which must have a class in common,with the
constraint string {or} labeling the dashed line (see Fig 18). In other words, any instance of the
class may participate in, at most, one of the associations at one time.
41
Fig. 2.18. An OR association notation. A car may associate with a person or a company.
Association Class
An association class is an association that also has class properties. An association
class is shown as a class symbol attached by a dashed line to an association path. The name in
the class symbol and the name string attached to the association pathare the same (see Fig 19).
The name can be shown on the path or the class symbol or both.If an ssociation class has
attributes but no operations or other associations, then the name may be displayed on the
association path and omitted from the association class to emphasize its "association nature."
If it has operations and attributes, then the name may beomitted from the path and placed in
the class rectangle to emphasize its "class nature."
42
N-Ary Association
An n-ary association is an association among more than two classes. Since n-ary
association is more difficult to understand, it is better to convert an n-ary association to
binary association.
An n-ary association is shown as a large diamond with a path from the diamond to
each participant class. The name of the association (if any) is shown near the diamond. The
role attachment may appear on each path as with a binary association. Multiplicity may be
indicated; however, qualifiers and aggregation are not permitted. An association class symbol
may be attached to the diamond by a dashed line, indicating an n-ary association that has
attributes, operation, or associations. The example depicted in Fig 20 shows the grade book
of a class in each semester.
Fig. 2.20. An n-ary (ternary) association that shows association among class, year, and
student classes. The association class GradeBook which contains the attributes of the
associations such as grade, exam, and lab.
43
Fig. 2.21. Association Path
44
generalization of the superclass.
Fig. 2.24. Ellipses(...) indicate that additional classes exist and are not shown.
USE-CASE DIAGRAM
The use-case concept was introduced by Ivar Jacobson in the object-oriented software
engineering (OOSE) method. The functionality of a system is described in anumber of different
use cases, each of which represents a specific flow of events in the system.
A use case corresponds to a sequence of transactions, in which each transaction is
invoked from outside the system (actors) and engages internal objects to interact with
one another and with the system's surroundings.
The description of a use case defines what happens in the system when the use case
is performed. In essence, the use-case model defines the outside (actors) and inside(use case)
of the system's behavior. Use cases represent specific flows of events in the system. The use
cases are initiated by actors and describe the flow of events that these actors set off. An actor
is anything that interacts with a use case: It could be a human user, external hardware, or
another system. An actor represents a category of user rather
45
than a physical user. Several physical users can play the same role. For example, in termsof
a member actor, many people can be members of a library, which can be represented by one
actor called Member.
A use-case diagram is a graph of actors, a set of use cases enclosed by a system
boundary, communication (participation) associations between the actors and the use cases,
and generalization among the use cases.
Fig. 2 . 25. Use-case diagram shows the relationship among actors and use cases
within a system.
Fig 25. diagrams use cases for a Help Desk. A use-case diagram shows the relationship
among the actors and use cases within a system. A client makes a call that is taken by an
operator, who determines the nature of the problem. Some calls can beanswered immediately;
other calls require research and a return call.
A use case is shown as an ellipse containing the name of the use case. The name ofthe
use case can be placed below or inside the ellipse. Actors' names and use case names should
follow the capitalization and punctuation guidelines of the model.
46
An actor is shown as a class rectangle with the label < <actor> >, or the label and astick
fig, or just the stick fig with the name of the actor below the fig (see Fig 26).
Booch explains that describing a systematic event in a static medium such as on asheet of
paper is difficult, but the problem confronts almost every discipline.
The Dynamic semantics of a problem with the following diagrams:
Behavior diagrams (Dynamic)
□ Interaction Diagrams:
□ Sequence diagrams
□
□ Collaboration diagrams
State Chart diagrams
□ Activity diagrams
Each class may have an associated activity diagram that indicates the behavior of the
class's instance (its object). In conjunction with the use-case model, we may provide a scripts
or an interaction diagram to show the time or event ordering of messages as they are evaluated
.
47
UML Sequence Diagram: Sequence diagrams are an easy and intuitive way of describing
the behavior of a system by viewing the interaction between the system and its environment.A
sequence diagram shows an interaction arranged in a time sequence. It shows the objects
participating in the interaction by their lifelines and the messages they exchange, arrangedin
a time sequence.
A sequence diagram has two dimensions: the vertical dimension represents time, the
horizontal dimension represents different objects. The vertical line is called the object's
lifeline. The lifeline represents the object's existence during the interaction. This form was first
popularized by Jacobson. An object is shown as a box at the top of a dashed vertical line (see
Fig 27). A role is a slot for an object within a collaboration that describes the type ofobject that
may play the role and its relationships to other roles. a sequence diagram does not show the
relationships among the roles or the association among the objects. An object role is shown as
a vertical dashed line, the lifeline.
Each message is represented by an arrow between the lifelines of two objects. The order
in which these messages occur is shown top to bottom on the page. Each message is labeled
with the message name. The label also can include the argument and some control information
and show self-delegation, a message that an object sends to itself, by sending the message
arrow back to the same lifeline. The horizontal ordering of the lifelines is arbitrary. Often, call
arrows are arranged to proceed in one direction across the page, but this is not always possible
and the order conveys no information.
The sequence diagram is very simple and has immediate visual appeal-this is its great
strength. A sequence diagram is an alternative way to understand the overall flow of the control
of a program. Instead of looking at the code and trying to find out the overall sequence of
behavior, you can use the sequence diagram to quickly understand thatsequence.
48
UML Collaboration Diagram: Another type of interaction diagram is the collaboration
diagram. A collaboration diagram represents a collaboration, which is a set of objects related
in a particular context, and interaction, which is a set of messages exchanged among the objects
within the collaboration to achieve a desired outcome. In a collaboration diagram, objects are
shown as figs. As in a sequence diagram, arrows indicate the messagesent within the given use
case. In a collaboration diagram, the sequence is indicated by numbering the messages.
A collaboration diagram provides several numbering schemes. The simplest is
illustrated in Fig 28.
Fowler and Scott argue that the main advantage of interaction diagrams (both
collaboration and sequence) is simplicity. You easily can see the message by looking atthe
diagram. The disadvantage of interaction diagrams is that they are great only for representing
a single sequential process; they begin to break down when you want to represent conditional
looping behavior.
Conditional behavior can be represented in sequence or collaboration diagrams through
two methods.
*. The preferred method is to use separate diagrams for each scenario. *. Another way
is to use conditions on messages to indicate the
behavior.
49
the state symbols. A state chart diagram may contain sub diagrams.
A state diagram represents the state of the method execution (that is, the state of
the object executing the method), and the activities in the diagram represent the activities
of the object that performs the method.
The purpose of the state diagram is to understand the algorithm involved in performing
a method. To complete an object-oriented design, the activities within the diagram must be
assigned to objects and the control flows assigned to links in the object diagram.
A state is represented as a rounded box, which may contain one or more compartments.
The compartments are all optional. The name compartment and the internal transition
compartment are two such compartments:
□ The name compartment holds the optional name of the state. States without names
are "anonymous" and all are distinct. Do not show the same named state twice in
the same diagram, since it will be very confusing.
□ The internal transition compartment holds a list of internal actions or activities
performed in response to events received while the object is in the state, without
changing states:
51
Fig. 2. 31. An activity diagram for processing mortgage requests
(Loan: ProcessingMortgage Request).
An activity model is similar to a state chart diagram, where a token (shown by a black
dot) represents an operation. An activity is shown as a round box, containing the name of
the operation. When an operation symbol appears within an activity diagram or other state
diagram, it indicates the execution of the operation.
Executing a particular step within the diagram represents a state within the execution
of the overall method. The same operation name may appear more than once in a state diagram,
indicating the invocation of the same operation in different phases.
An outgoing solid arrow attached to an activity symbol indicates a transition triggered
by the completion of the activity. The name of this implicit event need not be written, but the
conditions that depend on the result of the activity or other values may be included (Fig. 31).
Several transitions with different conditions imply a branching off of control. If
conditions are not disjoint, then the branch is nondeterministic. The concurrent control is
represented by multiple arrows leaving a synchronization bar, which is represented by a short
thick bar with incoming and outgoing arrows. Joining concurrent control is expressedby
multiple arrows entering the synchronization bar.
52
Fig. 2.32. A decision.
An activity diagram is used mostly to show the internal state of an object, but external
events may appear in them. An external event appears when the object is in a "waitstate," a
state during which there is no internal activity by the object and the object is waitingfor some
external event to occur as the result of an activity by another object (such as a user input or
some other signal). The two states are wait state and activity state. More than one possible
event might take the object out of the wait state; the first one that occurs triggers the transition.
A wait state is the "normal" state.
Activity and state diagrams express a decision when conditions (the UML calls them
guard conditions) are used to indicate different possible transitions that depend on Boolean
conditions of container object. The fig 2.32 provided for a decision is the traditional diamond
shape, with one or more incoming arrows and two or more outgoing arrows, each labeled by a
distinct guard condition. All possible outcomes should appear on one
of the outgoing transitions (see Fig 2.32).
Actions may be organized into swimlanes, each separated from neighboring swimlanes
by vertical solid lines on both sides. Each swimlane represents responsibility for part of the
overall activity and may be implemented by one or more objects. The relative ordering of the
swimlanes has no semantic significance but might indicate some affinity. Each action is
assigned to one swimlane. A transition may cross lanes; there is no significance to the routing
of the transition path (see Fig 2.33 ).
53
UML IMPLEMENTATION DIAGRAMS
Implementation diagrams show the implementation phase of systems development,
such as the source code structure and the run-time implementation structure. There are 2 types
of implementation diagrams:
*. Component diagrams – Its Show the structure of the code itself.
*. Deployment Diagrams – Its show the structure of the runtime system. These are relatively
simple, high-level diagrams compared with other
UML diagrams.
Component Diagram:
Component diagrams model the physical components (such as source code,
executable program, user interface) in a design. These high-level physical components mayor
may not be equivalent to the many smaller components you use in the creation of your
application. For example, a user interface may contain many other off-the-shelf components
purchased to put together a graphical user interface.
Another way of looking at components is the concept of packages. A package is used
to show how you can group together classes, which in essence are smaller scale components.
A package usually will be used to group logical components of the application, such as classes,
and not necessarily physical components. However, the package could be a first approximation
of what eventually will turn into physical grouping. In that case, the package will become a
component.
A component diagram is a graph of the design's components connected by dependency
relationships. A component is represented by the boxed fig shown in Fig 34 Dependency is
shown as a dashed arrow.
54
Deployment Diagram
Deployment diagrams show the configuration of run-time processing elements and
the software components, processes, and objects that live in them. Software component
instances represent run-time manifestations of code units. In most cases, component diagrams
are used in conjunction with deployment diagrams to show how physical modules of code are
distributed on various hardware platforms. In many cases, component and deployment
diagrams can be combined.
A deployment diagram is a graph of nodes connected by communication association. Nodes
may contain component instances, which mean that the component lives or runs at that node.
Components may contain objects; this indicates that the object is part of the component.
Components are connected to other components by dashed arrow dependencies, usually
through interfaces, which indicate one component uses the services of another. Each node or
processing element in the system is represented by a three- dimensional box. Connections
between the nodes (or platforms) themselves are shown by solid lines (see Fig 35).
A real model would have many more classes in each package. The contents might be
shown if they are small, or they might be suppressed from higher levels. The entire system is
a package. Fig 37 also shows the hierarchical structure, with one packagedependent on other
packages. For example, the Customer depends on the package Business Model, meaning that
one or more elements within Customer depend on one or more elements within the other
packages. The package Business Model is shown partially expanded. In this case, we see that
the package Business Model owns the classes Bank, Checking, and Savings as well as the
packages Clients and Bank. Ownership may be shown by a graphic nesting of the figs or by
the expansion of a package in a separate drawing. Packages can be used to designate not only
logical and physical groupings but also use-case groups. A use-case group, as the name
suggests, is a package of use cases.
56
Fig. 2.37. A package and its dependencies
Model dependency represents a situation in which a change to the target element may
require a change to the source element in the dependency, thus indicating the relationship
between two or more model elements. It relates the model elements themselves and does not
require a set of instances for its meaning. A dependency is shown as a dashed arrow from one
model element to another on which the first element is dependent (see Fig 38).
Fig. 2.38. An example of constraints. A person is a manager of people who work for the
accounting department.
UML EXTENSIBILITY
1. Model Constraints and comments
3. Stereotype
Stereotype represent a built-in extensibility mechanism of the UML. User-defined
extensions of the UML are enabled through the use of stereotypes and constraints. A stereotype
is a new class of modeling element introduced during modeling, It represents a subclass of an
existing modeling element with the same form (attributed and relationships) but a different
intent. UML stereotype extend and tailor the UML for a specific domain or process.
The general presentation of a stereotype is to use a figure for the base element but place
a keyword string above the name of the element (if used, the keyword string is the name of a
stereotype within matched guillemets,
“<<”,”>>”, such as <<flow>.. Note that a guillemet looks like a angle-bracket, but it is a single
character in most fonts.
<< Flow >> copy
Number of Copy
MakeCopy
58
<< Flow >> copy
Number of Copy
Copy
Number of Copy
3. UML Meta-model
The UML defined notations as well as a meta model. UML graphic
notations can be used not only to describe the system’s components but also to describe a
model itself. This is known as a meta-model.
In other words, a meta-model is a model of modeling elements. The purpose of the
UML meta-model is to provide a single, common, and definitive statement of the syntax and
semantics of the elements of the UML.
The meta model provides us a means to comment different UML diagrams. The
connection between the different diagrams is very important, and the UML attempts to make
these coupling more explicit through defining the underlying model while imposing no
methodology.
59
The presence of this meta model has made it possible for its developers to agree on
semantics and how those semantics would be best rendered. This is an important step forward,
since it can assure consistency among diagrams. The meta-model also can serve as a means to
exchange data between different case tools. The fig 41 is an example for the UML meta-model
that describes relationship with association and generalization; association is depicted as a
composition of association roles.
Fig. 2.41. The UML meta-model describing the relationship between association and
generalization.
60