OOAD Merged
OOAD Merged
OOAD Merged
Advanced Classes
Classes are indeed the most important building block of any object-oriented system.
However, classes are just one kind of an even more general building block in the
UML• classifiers.
A classifier is a mechanism that describes structural and behavioral features.
Classifiers include classes, interfaces, datatypes, signals, components, nodes, use
cases, and subsystems.
Classifiers (and especially classes) have a number of advanced features beyond the
simpler properties of attributes and operations described in the previous section: You
can model multiplicity, visibility, signatures, polymorphism, and other
characteristics.
The UML provides a number of other kinds of classifiers to help you model.
Visibility
One of the most important details you can specify for a classifier's attributes and
operations is its visibility.
The visibility of a feature specifies whether it can be used by other classifiers. In the
UML, you can specify any of three levels of visibility.
The above Figure shows a mix of public, protected, and private figures for the class
Toolbar.
Scope
Another important detail you can specify for a classifier's attributes and operations is
its owner scope.
The owner scope of a feature specifies whether the feature appears in each instance
of the classifier or whether there is just a single instance of the feature for all
instances of the classifier.
In the UML, you can specify two kinds of owner scope.
As Figure (a simplification of the first figure) shows, a feature that is classifier scoped is
rendered by underlining the feature's name. No adornment means that the feature is
instance scoped.
Multiplicity
The number of instances a class may have is called its multiplicity. Multiplicity is a
specification of the range of allowable cardinalities an entity may assume.
In the UML, you can specify the multiplicity of a class by writing a multiplicity
expression in the upper-right corner of the class icon.
Fig: Multiplicity
Attributes
At the most abstract level, when you model a class's structural features (that is, its
attributes), you simply write each attribute's name.
That's usually enough information for the average reader to understand the intent of
your model.
You can also specify the visibility, scope, and multiplicity of each attribute. There's
still more. You can also specify the type, initial value, and changeability of each
attribute.
There are three defined properties that you can use with attributes.
Operations
At the most abstract level, when you model a class's behavioral features (that is, its
operations and its signals), you will simply write each operation's name
You can also specify the visibility and scope of each operation.
You can also specify the parameters, return type, concurrency semantics, and other
properties of each operation. Collectively, the name of an operation plus its
parameters (including its return type, if any) is called the operation's signature.
In addition to the leaf property described earlier, there are four defined properties that
you can use with operations
Template Classes
A template is a parameterized element. In such languages as C++ and Ada, you can
write template classes, each of which defines a family of classes (you can also write
template functions, each of which defines a family of functions).
A template includes slots for classes, objects, and values, and these slots serve as the
template's parameters.
You can't use a template directly; you have to instantiate it first. Instantiation
involves binding these formal template parameters to actual ones.
For a template class, the result is a concrete class that can be used just like any
ordinary class.
The most common use of template classes is to specify containers that can be
instantiated for specific elements, making them type-safe.
For example, the following C++ code fragment declares a parameterized Map class.
template<class Item, class Value, int Buckets>
class Map {
public:
You can model template classes in the UML as well. As Figure shows, you render a
Template class just as you do an ordinary class, but with an additional dashed box in the
upper right corner of the class icon, which lists the template parameters.
Standard Elements
All of the UML's extensibility mechanisms apply to classes. Most often, you'll use
tagged values to extend class properties (such as specifying the version of a class)
and stereotypes to specify new kinds of components (such as model- specific
components).
The UML defines four standard stereotypes that apply to classes.
To model the semantics of a class, choose among the following possibilities, arranged
from informal to formal.
Advanced Relationships
Dependency
Specifies that the source instantiates the target template using the given
1 bind actual parameters
2 derive Specifies that the source may be computed from the target
3 friend Specifies that the source is given special visibility into the target
4 instanceOf Specifies that the source object is an instance of the target classifier
bind:
bind includes a list of actual arguments that map to the formal arguments of the
template.
derive
When you want to model the relationship between two attributes or two
associations, one of which is concrete and the other is conceptual.
friend
When you want to model relationships such as found with C++ friend classes.
instanceOf
When you want to model the relationship between a class and an object in the
same diagram, or between a class and its metaclass.
instantiate
when you want to specify which element creates objects of another.
powertype
when you want to model classes that cover other classes, such as you'll find when
modeling databases
refine
* There are two stereotypes that apply to dependency relationships among packages.
Specifies that the source package is granted the right to reference the
9 access elements of the target package
A kind of access that specifies that the public contents of the target
package enter the flat namespace of the source, as if they had been
10 import declared in the source
11 extend Specifies that the target use case extends the behavior of the source
Specifies that the source use case explicitly incorporates the behavior of
12 include another use case at a location specified by the source
Specifies that the target is the same object as the source but at a later
13 become point in time and with possibly different values, state, or roles
14 call Specifies that the source operation invokes the target operation
Specifies that the target object is an exact, but independent, copy of the
15 copy source
* We'll use become and copy when you want to show the role, state, or attribute value
of one object at different points in time or space
* You'll use call when you want to model the calling dependencies among operations.
16 send Specifies that the source operation sends the target event
* We'll use send when you want to model an operation dispatching a given event to a
target object.
* The send dependency in effect lets you tie independent state machines together.
Finally, one stereotype that you'll encounter in the context of organizing the elements of
your system into subsystems and models is
* We’ll use trace when you want to model the relationships among elements in different
models
Generalization
For example, the above figure shows a set of classes drawn from a financial services
application. You see the class Asset with three children: BankAccount, RealEstate,
and Security. Two of these children (BankAccount and Security) have their own
children.
For example, Stock and Bond are both children of Security. Two of these children
(BankAccount and RealEstate) inherit from multiple parents. RealEstate, for
example, is a kind of Asset, as well as a kind of InsurableItem, and BankAccount is a
kind of Asset, as well as a kind of InterestBearingItem and an InsurableItem.
The UML defines one stereotype and four constraints that may be applied to
generalization relationships.
implementation
We'll use implementation when you want to model private inheritance, such as found
in C++.
Next, there are four standard constraints that apply to generalization relationships
Complete
We'll use the complete constraint when you want to show explicitly that you've fully
specified a hierarchy in the model (although no one diagram may show that
hierarchy);
Incomplete
We'll use incomplete to show explicitly that you have not stated the full specification
of the hierarchy in the model (although one diagram may show everything in the
model).
Association
Navigation
Unadorned association between two classes, such as Book and Library, it's possible
to navigate from objects of one kind to objects of the other kind. Unless otherwise
specified, navigation across an association is bidirectional.
However, there are some circumstances in which you'll want to limit navigation to
just one direction.
Fig: Navigation
Visibility
Given an association between two classes, objects of one class can see and navigate
to objects of the other, unless otherwise restricted by an explicit statement of
navigation.
However, there are circumstances in which you'll want to limit the visibility across
that association relative to objects outside the association.
In the UML, you can specify three levels of visibility for an association end, just as
you can for a class's features by appending a visibility symbol to a role name the
visibility of a role is public.
Private visibility indicates that objects at that end are not accessible to any objects
outside the association.
Protected visibility indicates that objects at that end are not accessible to any objects
outside the association, except for children of the other end.
Fig: Visibility
Qualification
In the context of an association, one of the most common modeling idioms you'll
encounter is the problem of lookup. Given an object at one end of an association,
how do you identify an object or set of objects at the other end.
In the UML, you'd model this idiom using a qualifier, which is an association
attribute whose values partition the set of objects related to an object across an
association.
You render a qualifier as a small rectangle attached to the end of an association,
placing the attributes in the rectangle.
Fig: Qualification
Interface Specifier
A Person class may realize many interfaces: IManager, IEmployee, IOfficer, and so
on you can model the relationship between a supervisor and her workers with a one-
to-many association, explicitly labeling the roles of this association as supervisor and
worker.
In the context of this association, a Person in the role of supervisor presents only the
IManager face to the worker; a Person in the role of worker presents only the
IEmployee face to the supervisor. As the figure shows, you can explicitly show the
type of role using the syntax rolename : iname, where iname is some interface of the
other classifier.
Composition
Simple aggregation is entirely conceptual and does nothing more than distinguish a
"whole" from a "part."
Composition is a form of aggregation, with strong ownership and coincident lifetime
as part of the whole.
Parts with non-fixed multiplicity may be created after the composite itself, but once
created they live and die with it. Such parts can also be explicitly removed before the
death of the composite.
Fig: Composition
The above figure shows, composition is really just a special kind of association and is
specified by adorning a plain association with a filled diamond at the whole end.
Association Classes
In an association between two classes, the association itself might have properties.
An association class can be seen as an association that also has class properties, or as
a class that also has association properties.
We render an association class as a class symbol attached by a dashed line to an
association.
Constraints
Implicit
If you have an association between two base classes, you can specify that same
association between two children of those base classes
You can specify that the objects at one end of an association (with a multiplicity
greater than one) are ordered or unordered.
Ordered
Specifies that, over a set of associations, exactly one is manfest for each
1 xor associated object
Realization
When you model the vocabulary of a complex system, you may encounter dozens, if
not hundreds or thousands, of classes, interfaces, components, nodes, and use cases.
Establishing a crisp boundary around each of these abstractions is hard
This requires you to form a balanced distribution of responsibilities in the system as a
whole, with individual abstractions that are tightly cohesive and with relationships
that are expressive, yet loosely coupled
Don't begin in isolation. Apply use cases and scenarios to drive your discovery of the
relationships among a set of abstractions.
In general, start by modeling the structural relationships that are present. These
reflect the static view of the system and are therefore fairly tangible.
For each kind of relationship, start with its basic form and apply advanced features
only as absolutely necessary to express your intent.
Fig: Interfaces
Interface
An interface is a collection of operations that are used to specify a service of a class
or a component
Type
A type is a stereotype of a class used to specify a domain of objects, together with the
operations (but not the methods) applicable to the object.
Role
A role is the behavior of an entity participating in a particular context.
an interface may be rendered as a stereotyped class in order to expose its operations and
other properties.
Operations
Fig: Operations
Relationships
Fig: Realizations
Understanding an Interface
In the UML, you can supply much more information to an interface in order to make
it understandable and approachable.
First, you may attach pre- and postconditions to each operation and invariants to the
class or component as a whole. By doing this, a client who needs to use an interface
will be able to understand what the interface does and how to use it, without having
to dive into an implementation.
We can attach a state machine to the interface. You can use this state machine to
specify the legal partial ordering of an interface's operations.
We can attach collaborations to the interface. You can use collaborations to specify
the expected behavior of the interface through a series of interaction diagrams.
Fig: Roles
A class diagram like this one is useful for modeling the static binding of an
abstraction to its interface. You can model the dynamic binding of an abstraction to
its interface by using the become stereotype in an interaction diagram, showing an
object changing from one role to another.
If you want to formally model the semantics of an abstraction and its conformance to
a specific interface, you'll want to use the defined stereotype type
Type is a stereotype of class, and you use it to specify a domain of objects, together
with the operations (but not the methods) applicable to the objects of that type. The
concept of type is closely related to that of interface, except that a type's definition
may include attributes while an interface may not.
The most common purpose for which you'll use interfaces is to model the seams in a
system composed of software components, such as COM+ or Java Beans.
Identifying the seams in a system involves identifying clear lines of demarcation in
your architecture. On either side of those lines, you'll find components that may
change independently, without affecting the components on the other side,
Within the collection of classes and components in your system, draw a line around
those that tend to be tightly coupled relative to other sets of classes and components.
Refine your grouping by considering the impact of change. Classes or components
that tend to change together should be grouped together as collaborations.
Consider the operations and the signals that cross these boundaries, from instances of
one set of classes or components to instances of other sets of classes and components.
The below figure shows the seams surrounding a component (the library ledger.dll)
drawn from a financial system. This component realizes three interfaces: IUnknown,
ILedger, and IReports. In this diagram, IUnknown is shown in its expanded form; the
other two are shown in their simple form, as lollipops. These three interfaces are
realized by ledger.dll and are exported to other components for them to build on.
As this diagram also shows, ledger.dll imports two interfaces, IStreaming and
ITransaction, the latter of which is shown in its expanded form. These two interfaces
are required by the ledger.dll component for its proper operation. Therefore, in a
running system, you must supply components that realize these two interfaces.
Most object-oriented programming languages are statically typed, which means that
the type of an object is bound at the time the object is created.
Even so, that object will likely play different roles over time.
Modeling the static nature of an object can be visualized in a class diagram.
However, when you are modeling things like business objects, which naturally
change their roles throughout a workflow,
Specify the different possible types of that object by rendering each type as a class
stereotyped as type (if the abstraction requires structure and behavior) or as interface
(if the abstraction requires only behavior).
Model all the roles the of the object may take on at any point in time. You can do so
in two ways:
a. First, in a class diagram, explicitly type each role that the class
plays in its association with other classes. Doing this specifies the
face instances of that class put on in the context of the associated
object.
b. Second, also in a class diagram, specify the class-to-type
relationships using generalization.
To show the change in role of an object, render the object once for each role it plays
in the interaction, and connect these objects with a message stereotyped as become.
Package
The UML provides a graphical representation of package, This notation permits you
to visualize groups of elements that can be manipulated as a whole and in a way that
lets you control the visibility of and access to individual elements.
Names
Every package must have a name that distinguishes it from other packages. A name
is a textual string.
That name alone is known as a simple name; a path name is the package name
prefixed by the name of the package in which that package lives
We may draw packages adorned with tagged values or with additional compartments
to expose their details.
Owned Elements
A package may own other elements, including classes, interfaces, components,
nodes, collaborations, use cases, diagrams, and even other packages.
Owning is a composite relationship, which means that the element is declared in the
package. If the package is destroyed, the element is destroyed. Every element is
uniquely owned by exactly one package.
Elements of different kinds may have the same name within a package. Thus, you
can have a class named Timer, as well as a component named Timer, within the same
package.
Visibility
You can control the visibility of the elements owned by a package just as you can
control the visibility of the attributes and operations owned by a class.
Typically, an element owned by a package is public, which means that it is visible to
the contents of any package that imports the element's enclosing package.
Conversely, protected elements can only be seen by children, and private elements
cannot be seen outside the package in which they are declared.
We specify the visibility of an element owned by a package by prefixing the
element's name with an appropriate visibility symbol.
Generalization
There are two kinds of relationships you can have between packages: import and
access dependencies used to import into one package elements exported from another
and generalizations, used to specify families of packages
Generalization among packages is very much like generalization among classes
Packages involved in generalization relationships follow the same principle of
substitutability as do classes. A specialized package (such as WindowsGUI) can be
used anywhere a more general package (such as GUI) is used
All of the UML's extensibility mechanisms apply to packages. Most often, you'll use
tagged values to add new package properties (such as specifying the author of a
package) and stereotypes to specify new kinds of packages (such as packages that
encapsulate operating system services).
The UML defines five standard stereotypes that apply to packages.
The UML does not specify icons for any of these stereotypes
The most common purpose for which you'll use packages is to organize modeling
elements into groups that you can name and manipulate as a set.
There is one important distinction between classes and packages:
Packages have no identity (meaning that you can't have instances of packages, so
they are invisible in the running system); classes do have identity (classes have
instances, which are elements of a running system).
Scan the modeling elements in a particular architectural view and look for clumps
defined by elements that are conceptually or semantically close to one another.
Surround each of these clumps in a package.
For each package, distinguish which elements should be accessible outside the
package. Mark them public, and all others protected or private. When in doubt, hide
the element.
Explicitly connect packages that build on others via import dependencies
In the case of families of packages, connect specialized packages to their more
general part via generalizations.
Place the elements (and diagrams) that are necessary and sufficient to visualize,
specify, construct, and document the semantics of each view into the appropriate
package.
There will typically be dependencies across the elements in different views. So, in
general, let each view at the top of a system be open to all others at that level.