Ooad 3
Ooad 3
Ooad 3
The UML is a graphical language for visualizing, specifying, constructing, and documenting the
artifacts of a software-intensive system. The UML gives you a standard way to write a system's
blueprints, covering conceptual things, such as business processes and system functions, as well as
concrete things, such as classes written in a specific programming language, database schemas, and
reusable software components.
Model
A model is a simplification of reality. A model provides the blueprints of a system. A model may be
structural, emphasizing the organization of the system, or it may be behavioral, emphasizing the
dynamics of the system.
Why do we model
We build models so that we can better understand the system we are developing.
We build models of complex systems because we cannot comprehend such a system in its entirety.
Principles of Modeling
There are four basic principles of model
1. The choice of what models to create has a profound influence on how a problem is attacked and
how a solution is shaped.
2. Every model may be expressed at different levels of precision.
3. The best models are connected to reality.
4. No single model is sufficient. Every nontrivial system is best approached through a small set of
nearly independent models.
In software, there are several ways to approach a model. The two most common ways are
1. Algorithmic perspective
2. Object-oriented perspective
Algorithmic Perspective
Object-oriented perspective
The contemporary view of software development takes an object-oriented perspective.
In this approach, the main building block of all software systems is the object or class.
A class is a description of a set of common objects.
Every object has identity, state, and behavior.
Object-oriented development provides the conceptual foundation for assembling systems out of
components using technology such as Java Beans or COM+.
An Overview of UML
The Unified Modeling Language is a standard language for writing software blueprints. The
UML may be used to visualize, specify, construct, and document the artifacts of a software-
intensive system.
The UML is appropriate for modeling systems ranging from enterprise information systems to
distributed Web-based applications and even to hard real time embedded systems. It is a very
expressive language, addressing all the views needed to develop and then deploy such systems.
o Architecture
o Design
o Source code
o Project plans
o Tests
o Prototypes
o Releases
Interface
Interface is a collection of operations that specify a service of a class or component.
An interface therefore describes the externally visible behavior of that element.
An interface might represent the complete behavior of a class or component or only a part of that
behavior.
An interface is rendered as a circle together with its name. An interface rarely stands alone. Rather, it is
typically attached to the class or component that realizes the interface
Collaboration defines an interaction and is a society of roles and other elements that work together to
provide some cooperative behavior that's bigger than the sum of all the elements. Therefore,
collaborations have structural, as well as behavioral, dimensions. A given class might participate in
several collaborations.
Graphically, a collaboration is rendered as an ellipse with dashed lines, usually including only its name
Usecase
Use case is a description of set of sequence of actions that a system performs that yields an
observable result of value to a particular actor
Use case is used to structure the behavioral things in a model.
A use case is realized by a collaboration. Graphically, a use case is rendered as an ellipse with
solid lines, usually including only its name
Active class is just like a class except that its objects represent elements whose behavior is concurrent
with other elements. Graphically, an active class is rendered just like a class, but with heavy lines,
usually including its name, attributes, and operations
Component is a physical and replaceable part of a system that conforms to and provides the realization
of a set of interfaces. Graphically, a component is rendered as a rectangle with tabs
Node is a physical element that exists at run time and represents a computational resource, generally
having at least some memory and, often, processing capability. Graphically, a node is rendered as a
cube, usually including only its name
Behavioral Things are the dynamic parts of UML models. These are the verbs of a model, representing
behavior over time and space. In all, there are two primary kinds of behavioral things
Interaction
state machine
Interaction
Interaction is a behavior that comprises a set of messages exchanged among a set of objects within a
particular context to accomplish a specific purpose
An interaction involves a number of other elements, including messages, action sequences and links
Graphically a message is rendered as a directed line, almost always including the name of its operation
State Machine
State machine is a behavior that specifies the sequences of states an object or an interaction goes
through during its lifetime in response to events, together with its responses to those events
State machine involves a number of other elements, including states, transitions, events and activities
Graphically, a state is rendered as a rounded rectangle, usually including its name and its substates
Grouping Things:-
1. are the organizational parts of UML models. These are the boxes into which a model can be
decomposed
2. There is one primary kind of grouping thing, namely, packages.
Package:-
A package is a general-purpose mechanism for organizing elements into groups. Structural things,
behavioral things, and even other grouping things may be placed in a package
Graphically, a package is rendered as a tabbed folder, usually including only its name and,
sometimes, its contents
Annotational things are the explanatory parts of UML models. These are the comments you may apply
to describe about any element in a model.
A note is simply a symbol for rendering constraints and comments attached to an element or a
collection of elements.
Graphically, a note is rendered as a rectangle with a dog-eared corner, together with a textual or
graphical comment
Relationships in the UML: There are four kinds of relationships in the UML:
1. Dependency
2. Association
3. Generalization
4. Realization
Dependency:-
Dependency is a semantic relationship between two things in which a change to one thing may affect
the semantics of the other thing
Graphically a dependency is rendered as a dashed line, possibly directed, and occasionally including a
label
Association is a structural relationship that describes a set of links, a link being a connection among
objects.
Graphically an association is rendered as a solid line, possibly directed, occasionally including a label,
and often containing other adornments, such as multiplicity and role names
Diagram is the graphical presentation of a set of elements, most often rendered as a connected
graph of vertices (things) and arcs (relationships).
In theory, a diagram may contain any combination of things and relationships.
For this reason, the UML includes nine such diagrams:
Class diagram
Object diagram
Use case diagram
Sequence diagram
Collaboration diagram
Statechart diagram
Activity diagram
Component diagram
Deployment diagram
Class diagram
A class diagram shows a set of classes, interfaces, and collaborations and their relationships.
Class diagrams that include active classes address the static process view of a system.
Object diagram
Object diagrams represent static snapshots of instances of the things found in class diagrams
These diagrams address the static design view or static process view of a system
An object diagram shows a set of objects and their relationships
Models built during the development of a software-intensive system tend to evolve and may be viewed
by many stakeholders in different ways and at different times. For this reason, it is common for the
development team to not only build models that are well-formed, but also to build models that are
UML is made simpler by the presence of four common mechanisms that apply consistently throughout
the language.
1. Specifications
2. Adornments
3. Common divisions
4. Extensibility mechanisms
Specification that provides a textual statement of the syntax and semantics of that building block. The
UML's specifications provide a semantic backplane that contains all the parts of all the models of a
system, each part related to one another in a consistent fashion
Adornments Most elements in the UML have a unique and direct graphical notation that provides a
visual representation of the most important aspects of the element. A class's specification may include
other details, such as whether it is abstract or the visibility of its attributes and operations. Many of
these details can be rendered as graphical or textual adornments to the class's basic rectangular notation.
Extensibility Mechanisms
The UML's extensibility mechanisms include
1. Stereotypes
2. Tagged values
3. Constraints
Stereotype extends the vocabulary of the UML, allowing you to create new kinds of building
blocks that are derived from existing ones but that are specific to your problem
A tagged value extends the properties of a UML building block, allowing you to create new
information in that element's specification
A constraint extends the semantics of a UML building block, allowing you to add new rules or
modify existing ones
Architecture
A system's architecture is perhaps the most important artifact that can be used to manage these different
viewpoints and so control the iterative and incremental development of a system throughout its life
cycle.
Architecture is the set of significant decisions about
Software architecture is not only concerned with structure and behavior, but also with usage,
functionality, performance, resilience, reuse, comprehensibility, economic and technology constraints
and trade-offs, and aesthetic concerns.
Use
case
view Behavior
Process View Deployment view
Process View
The process view of a system encompasses the threads and processes that form the system's
concurrency and synchronization mechanisms.
This view primarily addresses the performance, scalability, and throughput of the system
Static aspects of are captured with Class and object diagrams
Dynamic aspects are captured with Interaction diagrams,activity diagrams and Statechart diagrams
Implementation View
The implementation view of a system encompasses the components and files that are used to assemble
and release the physical system.
This view primarily addresses the configuration management of the system's releases, made up of
somewhat independent components and files that can be assembled in various ways to produce a
running system.
Static aspects of are captured with Component diagrams
Dynamic aspects are captured with Interaction diagrams, activity diagrams and Statechart diagrams
Deployment Diagram
The deployment view of a system encompasses the nodes that form the system's hardware topology on
which the system executes.
This view primarily addresses the distribution, delivery, and installation of the parts that make up the
physical system.
Static aspects of are captured with deployment diagrams
Dynamic aspects are captured with Interaction diagrams,activity diagrams and Statechart diagrams
Class
A class is a description of a set of objects that share the same attributes, operations, relationships,
and semantics.
A class implements one or more interfaces.
The UML provides a graphical representation of class
Names
Every class must have a name that distinguishes it from other classes.
A name is a textual string that name alone is known as a simple name;
a path name is the class name prefixed by the name of the package in which that class lives.
Simple Name Path Name
Attributes
An attribute is a named property of a class that describes a range of values that instances of the
property may hold.
A class may have any number of attributes or no attributes at all.
An attribute represents some property of thing you are modeling that is shared by all objects of that
class
You can further specify an attribute by stating its class and possibly a default initial value
o Identify those things that users or implementers use to describe the problem or solution.
o Use CRC cards and use case-based analysis to help find these abstractions.
o For each abstraction, identify a set of responsibilities.
o Provide the attributes and operations that are needed to carry out these responsibilities for
each class.
Once you start modeling more than just a handful of classes, you will want to be sure that your
abstractions provide a balanced set of responsibilities.
To model the distribution of responsibilities in a system
o Identify a set of classes that work together closely to carry out some behavior.
o Identify a set of responsibilities for each of these classes.
o Look at this set of classes as a whole, split classes that have too many responsibilities into
smaller abstractions, collapse tiny classes that have trivial responsibilities into larger ones, and
reallocate responsibilities so that each abstraction reasonably stands on its own.
o Consider the ways in which those classes collaborate with one another, and redistribute their
responsibilities accordingly so that no class within a collaboration does too much or too little.
Sometimes, the things you model may never have an analog in software
Your application might not have any software that represents them
To model non software things
o Model the thing you are abstracting as a class.
o If you want to distinguish these things from the UML's defined building blocks, create a new
building block by using stereotypes to specify these new semantics and to give a distinctive
visual cue.
o If the thing you are modeling is some kind of hardware that itself contains software, consider
modeling it as a kind of node, as well, so that you can further expand on its structure.
Modeling Primitive Types
At the other extreme, the things you model may be drawn directly from the programming language you
are using to implement a solution.
Typically, these abstractions involve primitive types, such as integers, characters, strings, and even
enumeration types
To model primitive types
Model the thing you are abstracting as a type or an enumeration, which is rendered using class notation
with the appropriate stereotype.
If you need to specify the range of values associated with this type, use constraints.
Relationships
In the UML, the ways that things can connect to one another, either logically or physically, are modeled
as relationships.
Graphically, a relationship is rendered as a path, with different kinds of lines used to distinguish the
kinds of relationships
In object-oriented modeling, there are three kinds of relationships that are most important:
Dependencies
Generalizations
Associations
Dependency
A dependency is a using relationship that states that a change in specification of one thing may affect
another thing that uses it but not necessarily the reverse.
Graphically dependency is rendered as a dashed directed line, directed to the thing being depended on.
Most often, you will use dependencies in the context of classes to show that one class uses another class
as an argument in the signature of an operation
Generalization
o A generalization is a relationship between a general thing (called the super class or parent)and a
more specific kind of that thing (called the subclass or child).
o generalization means that the child is substitutable for the parent. A child inherits the properties of
its parents, especially their attributes and operations
o An operation of a child that has the same signature as an operation in a parent overrides the
operation of the parent; this is known as polymorphism.
o Graphically generalization is rendered as a solid directed line with a large open arrowhead, pointing
to the parent
Association
o An association is a structural relationship that specifies that objects of one thing are connected to
objects of another
o An association that connects exactly two classes is called a binary association
o An associations that connect more than two classes; these are called n-ary associations.
o Graphically, an association is rendered as a solid line connecting the same or different classes.
o Beyond this basic form, there are four adornments that apply to associations
Name
o An association can have a name, and you use that name to describe the nature of the relationship
Role
o When a class participates in an association, it has a specific role that it plays in that relationship;
o The same class can play the same or different roles in other associations.
o An instance of an association is called a link
Multiplicity
o In many modeling situations, it's important for you to state how many objects may be connected
across an instance of an association
o This "how many" is called the multiplicity of an association's role
o You can show a multiplicity of exactly one (1), zero or one (0..1), many (0..*), or one or more (1..*).
You can even state an exact number (for example, 3).
Aggregation
o Sometimes, you will want to model a "whole/part" relationship, in which one class represents a
larger thing (the "whole"), which consists of smaller things (the "parts").
o This kind of relationship is called aggregation, which represents a "has-a" relationship, meaning that
an object of the whole has objects of the part
o Aggregation is really just a special kind of association and is specified by adorning a plain
association with an open diamond at the whole end
Create a dependency pointing from the class with the operation to the class used as a parameter in the
operation.
This figure shows a dependency from CourseSchedule to Course, because Course is used in both the
add and remove operations of CourseSchedule.
The dependency from Iterator shows that the Iterator uses the CourseSchedule; the CourseSchedule
knows nothing about the Iterator. The dependency is marked with a stereotype, which specifies that this
is not a plain dependency, but, rather, it represents a friend, as in C++.
When you model with dependencies or generalization relationships, you are modeling classes that
represent different levels of importance or different levels of abstraction
Given a generalization relationship between two classes, the child inherits from its parent but the
parent has no specific knowledge of its children.
Dependency and generalization relationships are one-sided.
Associations are, by default, bidirectional; you can limit their direction
Given an association between two classes, both rely on the other in some way, and you can navigate
in either direction
An association specifies a structural path across which objects of the classes interact.
For each pair of classes, if you need to navigate from objects of one to objects of another, specify an
association between the two. This is a data-driven view of associations.
For each pair of classes, if objects of one class need to interact with objects of the other class other
than as parameters to an operation, specify an association between the two. This is more of a
behavior-driven view of associations.
For each of these associations, specify a multiplicity (especially when the multiplicity is not *,
which is the default), as well as role names (especially if it helps to explain the model).
If one of the classes in an association is structurally or organizationally a whole compared with the
classes at the other end that look like parts, mark this as an aggregation by adorning the association
at the end near the whole
Common Mechanisms
Note
A note is a graphical symbol for rendering constraints or comments attached to an element or a
collection of elements
Graphically, a note is rendered as a rectangle with a dog-eared corner, together with a textual or
graphical comment.
A note may contain any combination of text or graphics
Stereotypes
A stereotype is an extension of the vocabulary of the UML, allowing you to create new kinds of
building blocks similar to existing ones but specific to your problem.
Graphically, a stereotype is rendered as a name enclosed by guillemets and placed above the name of
another element
Tagged Values
Every thing in the UML has its own set of properties: classes have names, attributes, and
operations; associations have names and two or more ends (each with its own properties); and so
on.
With stereotypes, you can add new things to the UML; with tagged values, you can add new
properties.
A tagged value is not the same as a class attribute. Rather, you can think of a tagged value as
metadata because its value applies to the element itself, not its instances.
A tagged value is an extension of the properties of a UML element, allowing you to create new
information in that element's specification.
Graphically, a tagged value is rendered as a string enclosed by brackets and placed below the
name of another element..
That string includes a name (the tag), a separator (the symbol =), and a value (of the tag).
Constraints
A constraint specifies conditions that must be held true for the model to be well-formed.
Graphically, a constraint is rendered as a string enclosed by brackets and placed near the associated
element or connected to that element or elements by dependency relationships.
Modeling Comments
To model a comment,
Put your comment as text in a note and place it adjacent to the element to which it refers
Remember that you can hide or make visible the elements of your model as you see fit.
If your comment is lengthy or involves something richer than plain text, consider putting your comment
in an external document and linking or embedding that document in a note attached to your model
If you're convinced there's no other way to express these semantics, add this new property to an
individual element or a stereotype.
Common Properties AClass 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 a class diagram from all other kinds of diagram is its particular content.
Contents
Class diagrams commonly contain the following things:
o Classes
o Interfaces
o Collaborations
o Dependency, generalization, and association relationships
Like all other diagrams, class diagrams may contain notes and constraints
Class diagrams may also contain packages or subsystems
Note: Component diagrams and deployment diagrams are similar to class diagrams, except that instead
of containing classes, they contain components and nodes
Common Uses
o You use class diagrams to model the static design view of a system. This view primarily supports
the functional requirements of a system
o We'll typically use class diagrams in one of three ways:
o Identify the mechanism you'd like to model. A mechanism represents some function or behavior
of the part of the system you are modeling that results from the interaction of a society of
classes, interfaces, and other things.
o For each mechanism, identify the classes, interfaces, and other collaborations that participate in
this collaboration. Identify the relationships among these things, as well.
o Use scenarios to walk through these things. Along the way, you'll discover parts of your model
that were missing and parts that were just plain semantically wrong.
o Be sure to populate these elements with their contents. For classes, start with getting a good
balance of responsibilities. Then, over time, turn these into concrete attributes and operations.
Modeling a Logical Database Schema
o The UML is well-suited to modeling logical database schemas, as well as physical databases
themselves.
o The UML's class diagrams are a superset of entity-relationship (E-R) diagrams, Whereas classical
E-R diagrams focus only on data, class diagrams go a step further by permitting the modeling of
behavior, as well. In the physical database these logical operations are generally turned into triggers
or stored procedures.
o To model a schema,
o Identify those classes in your model whose state must transcend the lifetime of their
applications.
o Create a class diagram that contains these classes and mark them as persistent (a standard tagged
value). You can define your own set of tagged values to address database-specific details.
o Expand the structural details of these classes. In general, this means specifying the details of
their attributes and focusing on the associations and their cardinalities that structure these
classes.
o Watch for common patterns that complicate physical database design, such as cyclic
associations, one-to-one associations, and n-ary associations. Where necessary, create
intermediate abstractions to simplify your logical structure.
o Consider also the behavior of these classes by expanding operations that are important for data
access and data integrity. In general, to provide a better separation of concerns, business rules
concerned with the manipulation of sets of these objects should be encapsulated in a layer above
these persistent classes.
o Where possible, use tools to help you transform your logical design into a physical design.
Forward and Reverse Engineering
o Forward engineering is the process of transforming a model into code through a mapping to an
implementation language
o Forward engineering results in a loss of information, because models written in the UML are
semantically richer than any current object-oriented programming language.
o To forward engineer a class diagram,
o Identify the rules for mapping to your implementation language or languages of choice. This is
something you'll want to do for your project or your organization as a whole.
o Depending on the semantics of the languages you choose, you may have to constrain your use of
certain UML features. For example, the UML permits you to model multiple inheritance, but
Smalltalk permits only single inheritance. You can either choose to prohibit developers from
modeling with multiple inheritance (which makes your models language-dependent) or develop
idioms that transform these richer features into the implementation language (which makes the
mapping more complex).
o Use tagged values to specify your target language. You can do this at the level of individual
classes if you need precise control. You can also do so at a higher level, such as with
collaborations or packages.
o Use tools to forward engineer your models.
Reverse engineering is the process of transforming code into a model through a mapping from a
specific implementation language.
Reverse engineering results in a flood of information, some of which is at a lower level of detail
than you'll need to build useful models.
Reverse engineering is incomplete. There is a loss of information when forward engineering models
into code, and so you can't completely recreate a model from code unless your tools encode
information in the source comments that goes beyond the semantics of the implementation
language.
To reverse engineer a class diagram,
o Identify the rules for mapping from your implementation language or languages of choice.
This is something you'll want to do for your project or your organization as a whole.
o Using a tool, point to the code you'd like to reverse engineer. Use your tool to generate a
new model or modify an existing one that was previously forward engineered.
o Using your tool, create a class diagram by querying the model. For example, you might start
with one or more classes, then expand the diagram by following specific relationships or
other neighboring classes. Expose or hide details of the contents of this class diagram as
necessary to communicate your intent.
Object Diagram
Terms & Concepts
An object diagram is a diagram that shows a set of objects and their relationships at a point in time.
Graphically, an object diagram is a collection of vertices and arcs
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 a class diagram from all other kinds of diagram is its particular content.
Contents
Object diagrams commonly contain
Objects
Links
Like all other diagrams, object diagrams may contain notes and constraints.
Object diagrams may also contain packages or subsystems
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
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
Identify the mechanism you'd like to model. A mechanism represents some function or behavior
of the part of the system you are modeling that results from the interaction of a society of
classes, interfaces, and other things.
For each mechanism, identify the classes, interfaces, and other elements that participate in this
collaboration; identify the relationships among these things, as well.
Consider one scenario that walks through this mechanism. Freeze that scenario at a moment in
time, and render each object that participates in the mechanism.
Expose the state and attribute values of each such object, as necessary, to understand the
scenario.
Similarly, expose the links among these objects, representing instances of associations among
them.