Ooad Unit-3
Ooad Unit-3
Advanced classes, advanced relationships, interfaces, types and roles, packages, terms, concepts,
modeling techniques for class and object diagrams; Interactions: Interaction diagrams; Use cases:
Use case diagrams, activity diagrams.
UNIT-III
CLASS & OBJECT DIAGRAMS
Class Diagrams:
TERMS AND CONCEPTS
A class diagram is a diagram that shows a set of classes, interfaces, and collaborations and their
relationships. Graphically, a class diagram is a collection of vertices and arcs.
Common Properties:
A class diagram is just a special kind of diagram and shares the same common properties as do all other
diagrams name and graphical content that are a projection into a model. What distinguishes a class
diagram from other kinds of diagrams is its particular content.
Contents:
Class diagrams commonly contain the following things:
• Classes
• Interfaces
• Collaborations
• Dependency, generalization, and association relationships. Like all other diagrams, class diagrams may
contain notes and constraints.
Class diagrams may also contain packages or subsystems, both of which are used to group elements of
your model into larger chunks. Sometimes you'll want to place instances in your class diagrams as well,
especially when you want to visualize the (possibly dynamic) type of an instance.
Common Uses :
You use class diagrams to model the static design view of a system. This view primarily
supports the functional requirements of a system the services the system should provide to its end users.
When you model the static design view of a system, you'll typically use class diagrams in one of three
ways.
1. To model the vocabulary of a system Modeling the vocabulary of a system involves making a
decision about which abstractions are a part of the system under consideration and which fall outside its
boundaries. You use class diagrams to specify these abstractions and their responsibilities.
2. To model simple collaborations
A collaboration is a society of classes, interfaces, and other elements that work together to provide some
cooperative behavior that's bigger than the sum of all the elements. For example, when you re modeling
the semantics of a transaction in a distributed system, you can't just stare at a single class to understand
what's going on. Rather, these semantics are carried out by a set of classes that work together. You use
class diagrams to visualize and specify this set of classes and their relationships.
Common Properties
An object diagram is a special kind of diagram and shares the same common properties as all other
diagrams that is, a name and graphical contents that are a projection into a model. What distinguishes an
object diagram from all other kinds of diagrams is its particular content.
Contents
Object diagrams commonly contain
•Objects
•Links
Like all other diagrams, object diagrams may contain notes and constraints.
Sometimes you'll want to place classes in your object diagrams as well, especially when you want to
visualize the classes behind each instance.
Common Uses
You use object diagrams to model the static design view or static process view of a
system just as you do with class diagrams, but from the perspective of real or prototypical
instances.
This view primarily supports the functional requirements of a systemthat is, the
services the system should provide to its end users. Object diagrams let you model static data structures.
When you model the static design view or static process view of a system, you typically use object
diagrams in one way:
To model object structures
Modeling object structures involves taking a snapshot of the objects in a system at a given moment in
time. An object diagram represents one static frame in the dynamic storyboard represented by an
interaction diagram. You use object diagrams to visualize, specify, construct,
and document the existence of certain instances in your system, together with their relationships to one
another.
Advanced Classes
1. public
Any outside classifier with visibility to the given classifier can use the feature specified by
prepending the symbol +.
2. protected
Any descendant of the classifier can use the feature; specified by prepending the symbol #.
3. private
Only the classifier itself can use the feature; specified by prepending the symbol -.
Scope- It 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.
1. Instance - Each instance of the classifier holds its own value for the feature.
2. Classifier - There is just one value of the feature for all instances of the classifier.
• Figure shows, a feature that is classifier scoped is rendered by underlining the feature's name
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.
• Specify the multiplicity of a class by writing a multiplicity expression in the upper-right
corner of the class icon.
• Multiplicity applies to attributes, as well. You can specify the multiplicity of an attribute
by writing a suitable expression in brackets just after the attribute name. For example, in
the figure, there are two or more consolePort instances in the instance of
NetworkController.
Attributes
• You can 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.
• In its full form, the syntax of an attribute in the UML is
• [visibility] name [multiplicity] [: type] [= initial-value] [{property-string}].
•
There are three defined properties that you can use with attributes.
addOnly For attributes with a multiplicity greater than one, additional values
may be added, but once created, a value may not be removed or altered
frozen The attribute's value may not be changed after the object is initialized.
Operations
• 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.
• The name of an operation plus its parameters (including its return type, if any) is
called the operation's signature.
• In its full form, the syntax of an operation in the UML is
[visibility] name [(parameter-list)] [: return-type] [{property-
string}]
• In an operation's signature, you may provide zero or more parameters, each of which
follows the syntax
• [direction] name : type [= default-value]
• Direction may be any of the following values
1) in 2) out 3) inout
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.
• A template includes slots for classes, objects, and values, and these slots serve as the
template's parameters.
• The most common use of template classes is to specify containers that can be
instantiated for specific elements, making them type-safe
template<class Item, class Value, int Buckets> class Map {
public:
virtual Boolean bind(const Item&,
constValue&); virtual Boolean isBound(const
Item&) const;
... };
Standard Elements - The UML defines four standard stereotypes that apply to classes.
Dependency
• A dependency is a using relationship, specifying that a change in the specification of
one thing may affect another thing that uses it but not necessarily the reverse.
Graphically, a dependency is rendered as a dashed line, directed to the thing that is
depended on.
Eight Stereotypes that apply to dependency relationships among classes and objects
Generalization
A generalization is a relationship between a general thing (called the superclass or parent) and
a more specific kind of that thing (called the subclass or child).
1. Complete - Specifies that all children in the generalization have been specified in the model
and that no additional children are permitted
2. Incomplete - Specifies that not all children in the generalization have been specified and that
additional children are permitted
3. Disjoint - Specifies that objects of the parent may have no more than one of the children
as a type 4.Overlapping - Specifies that objects of the parent may have more than one of the
children as a type
Association
• An association is a structural relationship, specifying that objects of one thing are
connected to object of another.
• Basic adornments: name, role, multiplicity, aggregation.
• Advanced adornments: navigation, qualification, various flavors of aggregation
Navigation
- Given a plain, 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.
Visibility
- 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
Constraints
1. implicit: The relationship is not manifest but, rather, is only conceptual.
2. ordered: the set of objects at one end of an association are in an explicit order.
3. changeable: links between objects may be changed.
4. add Only: new links may be added from an object on the opposite end of
association.
5. frozen: a link added may not be modified or deleted.
6. Xor: over a set of associations, exactly one is man fest for each associated
object.
Realization
• A realization is a semantic relationship between classifiers in which one
classifier specifies a contract that anther classifier guarantees to carry out.
• Use in two circumstances:
– In the context of interfaces.
– In the context of collaborations.
– Rendering as:
• 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.
• Next, identify opportunities for generalization/specialization relationships; use
multiple inheritance sparingly.
• Only after completing the preceding steps should you look for dependencies; they
generally represent more-subtle forms of semantic connection.
• For each kind of relationship, start with its basic form and apply advanced
features only as absolutely necessary to express your intent.
• Remember that it is both undesirable and unnecessary to model all relationships
among a set of abstractions in a single diagram or view. Rather, build up your
system's relationships by considering different views on the system. Highlight
interesting sets of relationships in individual diagrams.
Interfaces, Types and Roles
Operations:
• To distinguish an interface from a class, prepend an ‗I‘ to every interface name.
• Operations in an interface may be adorned with visibility properties,
concurrency properties, stereotypes, tagged values, and constraints.
• Interface don't have attributes. interfaces span model boundaries and it doesn't
have direct instances.
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.
Interface relationships
• 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.
• Package logically related sets of these operations and signals as interfaces.
• For each such collaboration in your system, identify the interfaces it relies on
(imports) and those it provides to others (exports). You model the importing of
interfaces by dependency relationships, and you model the exporting of interfaces
by realization relationships.
• For each such interface in your system, document its dynamics by using pre- and
postconditions for each operation, and use cases and state machines for the
interface as a whole.
2. Modeling Static and Dynamic Types
To model a dynamic type
• 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 class of the object may take on at any point in time. You
can do so in two ways:
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.
Second, also in a class diagram, specify the class-to-type relationships
using generalization.
• In an interaction diagram, properly render each instance of the dynamically
typed class. Display the role of the instance in brackets below the object's name.
• 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.
• For example, Figure shows the roles that instances of the class Person might play
in the context of a human resources system.
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.
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.
Importing and Exporting
• Suppose you have two classes named A and B sitting side by side. Because they
are peers, A can see B and B can see A, so both can depend on the other. Just two
classes makes for a trivial system, so you really don't need any kind of packaging.
• In the UML, you model an import relationship as a dependency adorned with the
stereotype import
• Actually, two stereotypes apply here—import and access— and both specify that
the source package has access to the contents of the target.
• Import adds the contents of the target to the source's namespace
• Access does not add the contents of the target
• The public parts of a package are called its exports.
• The parts that one package exports are visible only to the contents of those
packages that explicitly import the package.
• Import and access dependencies are not transitive
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).