r19 UML Unit 1
r19 UML Unit 1
UNIT-1
Introduction to UML: Importance of modeling, principles of modeling, object oriented
modeling, conceptual model of the UML, Architecture, Software Development Life
Cycle.
Structural Modeling: Classes, Relationships, common Mechanisms, and diagrams.
Advanced classes, advanced relationships, Object diagrams: common modeling
techniques.
• Specifying means building models that are precise, unambiguous and complete.
• The UML addresses the specification of all the important analysis, design and
implementation decisions that must be made in developing and deploying a
software system.
• The UML is not a visual programming language, but its models can be directly
connected to a variety of programming languages, such as JAVA, C++ or Visual
Basic or even to Tables of database.
Why do we model?:
➢ Modeling is a central part of all the activities that lead to the development of
good software.
➢ A model is a simplification at some level of abstraction .
➢ We build models to better understand the systems we are developing:
• To help us visualize
• To specify structure or behavioral
• To provide template for building system
• To document decisions we have made
– simplify reality
– capture requirements
– visualize the system in its entirety
– specify the structure and/or behaviour of the system
• The choice of what models to create has a profound influence on how a problem
is attacked and how a solution is shaped.
• Every model may be expressed at different levels of precision.
• The best models are connected to reality.
• No single model is sufficient. Every nontrivial system is best approached
through a small set of nearly independent models.
UML is composed of three main building blocks, i.e., things, relationships, and
diagrams. Building blocks generate one complete UML model diagram by rotating
around several different blocks. It plays an essential role in developing UML diagrams.
1. Things
2. Relationships
3. Diagrams
These things are the basic object-oriented building blocks of the UML. You use them
to write well-formed models.
1. Structural Things
➢ Structural things are the nouns of UML models. These are mostly static parts
of a model, representing elements that are either conceptual or physical.
➢ Collectively, the structural things are called classifiers.
1. Class
2. Interface
3. Collaboration
4. Use case
5. Active class
6. Component
7. Node
❖ 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. Graphically, a class is
rendered as a rectangle, usually
including its name, attributes, and
operations.
❖ Interface:
• An 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.
• Interface is represented by a circle as shown
in the following figure. It has a name which is generally written below the
circle.
❖ Collaboration:
• A 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.
• Collaborations have structural, as well as
behavioral, dimensions. A given class or
object might participate in several
collaborations.
• Graphically, a collaboration is rendered as
an ellipse with dashed lines, sometimes including only its name.
❖ Use case:
• A use case is a description of sequences of
actions that a system performs that yield
observable results of value to a particular actor.
• A 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:
• An active class is a class whose objects own one or
more processes or threads and therefore can initiate
control activity.
• An 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 as a class
with dark line; it usually includes its name,
attributes, and operations.
❖ Component:
• A component is a physical and replaceable
part of a system that conforms to and provides
the realization of a set of interfaces.
❖ Node:
Behavioral Things
They are the verbs that encompass the dynamic parts of a model. It depicts the
behavior of a system.
1. Interaction
2. State machine.
❖ State machine − State machine is useful when the state of an object in its life
cycle is important. It defines the sequence of states an object goes through in
response to events. Events are external factors responsible for state change.
Graphically, a state is rendered as a rounded rectangle, usually including its
name and its substates
3.Grouping Things
Grouping things can be defined as a mechanism to group elements of a UML model
together. There is only one grouping thing available −
❖ Package − Package is the only one grouping thing
available for gathering structural and behavioral things.
4.Annotational Things
Annotational things can be defined as a mechanism to capture remarks,
descriptions, and comments of UML model elements.
• These relationships are the basic relational building blocks of the UML. These
are used to write well-formed models.
• Class diagram
• Object diagram
• Use case diagram
• Sequence diagram
• Collaboration diagram
• Activity diagram
• Statechart diagram
• Component diagram
• Deployment diagram
1.Class diagram:
• A class diagram shows a set of classes, interfaces, and collaborations and
their relationships.
• These diagrams are the most common diagram found in modeling object-
oriented systems.
• Class diagrams address the static design view of a system. Class diagrams
that include active classes address the static process view of a system.
2.Object diagram:
• An object diagram shows a set of objects and their relationships.
• 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 as do class diagrams, but from the perspective of real or
prototypical cases.
3.Use case diagram:
• A use case diagram shows a set of use cases and actors (a special kind of
class) and their relationships.
• Use case diagrams address the static use case view of a system.
• These diagrams are especially important in organizing and modeling the
behaviors of a system.
4.Sequence diagram:
• Both sequence diagrams and Collaboration diagrams are kinds of
interaction diagrams.
• An interaction diagram shows an interaction, consisting of a set of objects
or roles, including the messages that may be dispatched among them.
• Interaction diagrams address the dynamic view of a system.
• A sequence diagram is an interaction diagram that emphasizes the time-
ordering of messages
Collaboration diagram:
• A Collaboration diagram is an interaction diagram that emphasizes the
structural organization of the objects or roles that send and receive
messages.
• Sequence diagrams and Collaboration diagrams represent similar basic
concepts, but each diagram emphasizes a different view of the concepts.
• Sequence diagrams emphasize temporal ordering, and Collaboration
diagrams emphasize the data structure through which messages flow.
Activity diagram:
• An activity diagram shows the structure of a process or other computation
as the flow of control and data from step to step within the computation.
• Activity diagrams address the dynamic view of a system.
• They are especially important in modeling the function of a system and
emphasize the flow of control among objects.
Statechart diagram:
• A state diagram shows a state machine, consisting of states, transitions,
events, and activities.
• A state diagrams shows the dynamic view of an object.
• They are especially important in modeling the behavior of an interface,
class, or collaboration and emphasize the event-ordered behavior of an
object, which is especially useful in modeling reactive systems
Component diagram:
• A component diagram is shows an encapsulated class and its interfaces,
ports, and internal structure consisting of nested components and
connectors.
• Component diagrams address the static design implementation view of a
system. They are important for building large systems from smaller parts.
Deployment diagram:
• A deployment diagram shows the configuration of run-time processing
nodes and the components that live on them.
• Deployment diagrams address the static deployment view of an
architecture. A node typically hosts one or more artifacts.
1.5.2. Rules of the UML :
✓ The UML's building blocks can't simply be thrown together in a random fashion.
✓ Like any language, the UML has a number of rules that specify what a well-
formed model should look like.
✓ A well-formed model is one that is semantically self-consistent and in harmony
with all its related models
The UML has semantic rules for:-
▪ Names- What you can call things, relationships and diagrams.
▪ Scope- The context that gives specific meaning to a name.
▪ Visibility- How those names can be seen and used by others.
▪ Integrity- How things properly and consistently relate to one another.
▪ Execution- What it means to run or simulate a dynamic model.
– 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
Elided - Certain elements are hidden to simplify the view.
Incomplete - Certain elements may be missing.
Inconsistent - The integrity of the model is not guaranteed.
– These less-than-well-formed models are unavoidable as the details of a system
unfold and churn during the software development life cycle.
– The rules of the UML encourage youbut do not force youto address the most
important analysis, design, and implementation questions that push such
models to become well-formed over time.
1.5.3 Common Mechanisms
▪ The 4 common mechanisms that apply consistently throughout the language.
1. Specifications
2. Adornments
3. Common Divisions
4. Extensibility mechanisms
1. Specifications:-
➢ The UML is more than just a graphical language. Rather, behind every part of
graphical notation there is a specification that provides a textual statement of
the syntax and semantics of that building block.
➢ For example, behind a class icon is a specification that provides the full set of
attributes, operations and behaviors.
➢ You use the UML’s graphical notation to visualize a system; you use the UML’s
specification to state the system details.
2. 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.
• For example, the notation for a class is intentionally designed to be easy
to draw, because classes are the most common element found in modeling
object-oriented systems.
• The class notation also exposes the most important aspects of a class,
namely its name, attributes, and operations.
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.
For example a class, adorned to indicate that it is an abstract class with two
public, one protected, and one private operation.
3.Common Divisions:
In modeling object-oriented systems, the world often gets divided in several ways.
➢ Abstraction vs. manifestation
First, there is the division of class and object. A class is an abstraction; an object
is one concrete manifestation of that abstraction
• Class vs. object
• Most UML building blocks have this kind of class/object distinction.
4.Extensibility Mechanisms:
The UML provides a standard language for writing software blueprints, but it is not
possible for one closed language to ever be sufficient to express all possible nuances
of all models across all domains across all time.
The UML's extensibility mechanisms include:
Stereotypes
Tagged values
Constraints
1.Stereotypes:
Extend the vocabulary of the UML by creating new model elements derived from
existing ones but that have specific properties suitable for your
domain/problem.
2.Tagged values:-
Properties for specifying key-value pairs of model elements, where keywords
are attributes.
Extend the properties of a UML building block, allowing you to create new
information in that elements specification.
3.Constraints:-
Properties for specifying semantics or conditions that must be maintained as
true for model elements.
Extend the semantics of a UML building block, allowing you to add new rules,
or modify existing ones.
Example:- you might want to constrain the EventQueue class so that all
additions are done in order.
1.6 Architecture/ Modeling a System's Architecture:
– Any real world system is used by different users. The users can be developers,
testers, business people, analysts and many more.
– So before designing a system the architecture is made with different
perspectives in mind. T
– he most important part is to visualize the system from different viewer.s
perspective.
– The better we understand the better we make the system.
Elaboration is the second phase of the process, when the product vision and its
architecture are defined. In this phase, the system’s requirements are prioritized and
baselined.
Construction is the third phase of the process, when the software is brought from an
executable architectural baseline to being ready to be transitioned to the user
community.
Transition is the fourth phase of the process, when the software is turned into the
hands of the user community. Rarely does the software development process end here,
for even during this phase, the system is continuously improved, bugs are eradicated
and features that didn’t make an earlier release are added.
Structural Modeling:
Structural modeling captures the static features of a system. They consist of the
following −
• Classes diagrams
• Objects diagrams
• Component diagram
• Deployment diagrams
• Component diagram
Class diagram is the most widely used structural diagram.
1. Classes:
Terms and Concepts:
A class is a description of a set of objects that share the same attributes,
operations, relationships, and semantics. Graphically, a class is rendered as a
rectangle.
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 qualified name is the class name prefixed by the name of the package
in which that class lives. A class may be drawn showing only its 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 the thing you are modeling that is
shared by all objects of that class.
Operations
• An operation is the implementation of a service that can be requested from any
object of the class to affect behavior.
• an operation is an abstraction of something you can do to an object that is
shared by all objects of that class.
• A class may have any number of operations or no operations at all.
Responsibilities
2.Relationships:
Dependencies:
A dependency is a relationship that states that one thing (for example, class
Window) uses the information and services of another thing (for example, class
Event), but not necessarily the reverse.
Graphically, a dependency is rendered as a dashed directed line, directed to
the thing being depended on.
Choose dependencies when you want to show one thing using another.
Generalizations:
Name:
An association can have a name, and you use that name to describe the nature
of the relationship. So that there is no ambiguity about its meaning, you can give
a direction to the name by providing a direction triangle that points in the
direction you intend to read the name.
Role:
• When a class participates in an
association, it has a specific role that it
plays in that relationship; a role is just the
face the class at the far end of the
association presents to the class at the
near end of the association.
• You can explicitly name the role a class
plays in an association.
Multiplicity:
• An association represents a structural relationship among objects.
• In many modeling situations, it's important for you to state how many
objects may be connected across an instance of an association.
• This "how many" is called the multiplicity of an association's role.
• It represents a range of integers specifying the possible size of the set
of related objects.
The number of objects must be in the given range. You can show a multiplicity
of exactly one (1), zero or one (0..1), many (0..*), or one or more (1..*). You can
give an integer range (such as 2..5). You can even state an exact number (for
example, 3, which is equivalent to 3..3).
Aggregation:
A plain association between two classes represents a structural relationship
between peers, meaning that both classes are conceptually at the same level, no
one more important than the other.
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"). This kind of relationship is called aggregation, which represents a "has-
a" relationship
Composition:-
3.Common Mechanisms:
4.Diagrams:
▪ You'll often use five additional diagrams to view the dynamic parts of a
system:
1. Use case diagram
2. Sequence diagram
3. Collaboration diagram
4. State diagram
5. Activity diagram
Structural Diagrams:
• The UML's structural diagrams exist to visualize, specify, construct, and
document the static aspects of a system.
• The UML's structural diagrams are roughly organized around the major
groups of things you'll find when modeling a system.
1. Advanced Classes:
When you model, you'll discover abstractions that represent things in the real world
and things in your solution.
✓ The most important kind of classifier in the UML is the class.
✓ A class is a description of a set of objects that share the same attributes,
operations, relationships, and semantics.
✓ Classes are not the only kind of classifier, however. The UML provides a number
of other kinds of classifiers to help you model
Interface A collection of operations that are used to specify a service of a class or a component
Datatype A type whose values are immutable, including primitive built-in types (such as
numbers and strings) as well as enumeration types (such as Boolean)
Association A description of a set of links, each of which relates two or more objects.
Component A modular part of a system that hides its implementation behind a set of external
interfaces
Node A physical element that exists at run time and that represents a computational
resource, generally having at least some memory and often processing capability
Use case A description of a set of a sequence of actions, including variants, that a system
performs that yields an observable result of value to a particular actor
Subsystem A component that represents a major part of a system
Visibility:
One of the design details you can specify for an attribute or operation is visibility. The visibility
of a feature specifies whether it can be used by other classifiers. In the UML, you can specify any
of four levels of visibility.
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 -.
4. package Only classifiers declared in the same package can use the feature; specified by
prepending the symbol ~.
Abstract, Leaf, and Polymorphic Elements:
Multiplicity:
Whenever you use a class, it's reasonable to assume that there may be any
number of instances of that class.
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.
[visibility] name
[':' type] ['[' multiplicity] ']']
['=' initial-value]
[property-string {',' property-string}]
Operations:
At the most abstract level, when you model a class's behavioral features. 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 an operation's signature, you may provide zero or more parameters, each of which follows the
syntax
Template Classes:
A template may include slots for classes, objects, and values, and these slots serve as
the template's parameters.
};
You might then instantiate this template to map Customer objects to Order objects. m :
Standard Elements:
2.Advanced Relationships:
Terms and Concepts:
A relationship is a connection among things. In object-oriented modeling, the four
most important relationships are dependencies, generalizations, associations,
and realizations. Graphically, a relationship is rendered as a path, with different
kinds of lines used to distinguish the different relationships.
Dependencies:
• 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 the
reverse.
• Graphically, a dependency is rendered as a dashed line, directed to the thing
that is depended on. Apply dependencies when you want to show one thing
using another.
1. bind Specifies that the source instantiates the target template using the
given actual parameters
2.derive Specifies that the source may be computed from the target
3.permit 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.
Ordinarily shown using text notation in the form source : Target
5.instantiate Specifies that the source creates instances of the target
6.powertype Specifies that the target is a powertype of the source; a powertype is a
classifier whose objects are the children of a given parent
7. refine Specifies that the source is at a finer degree of
8. use Specifies that the semantics of the source element depends on the
semantics of the public part of the target
1.import Specifies that the public contents of the target package enter
the public namespace of the source, as if they had been declared
in the source.
2.access Specifies that the public contents of the target package enter
the private namespace of the source. The unqualified names
may be used within the source, but they may not be re-
exported.
1.extend Specifies that the target use case extends the behavior of the
source
2.inclue Specifies that the source use case explicitly incorporates the
behavior of another use case at a location specified by the source
1.send Specifies that the source class sends the target event
Finally, one stereotype that you'll encounter in the context of organizing the
elements of your system into subsystems and models is
1.TRace Specifies that the target is a historical predecessor of the source from an earlier
stage of
development
Generalizations:
Association:
• An association is a structural relationship, specifying that objects of one thing
are connected to objects of another.
• We use associations when you want to show structural relationships.
• There are four basic adornments that apply to an association:
✓ a name,
✓ the role at each end of the association,
✓ the multiplicity at each end of the association,
✓ and aggregation.
• For advanced uses, there are a number of other properties you can use to model
subtle details, such as
✓ Navigation
✓ Vision
✓ Qualification
✓ various flavors of aggregation.
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.
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.
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
Qualification
Interface Specifier:
An interface is a collection of operations that are used to specify a service of a
class or a component
Collectively, the interfaces realized by a class represent a complete
specification of the behavior of that class.
However, in the context of an association with another target class, a source
class may choose to present only part of its face to the world
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:
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
Association Classes
Constraints:
• UML defines five constraints that may be applied to association relationships.
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
• For example, in a User/Password association, the Passwords associated with the
User might be kept in a least-recently used order, and would be marked as ordered.
• Finally, there is one constraint for managing related sets of associations:
1 xor Specifies that, over a set of associations, exactly one is manfest for each
associated object
Realization
Realization of an Interface
Realization of a Use Case
• Chose the target you want to reverse engineer. Typically, you'll set your context
inside an operation or relative to an instance of one particular class.
• Using a tool or simply walking through a scenario, stop execution at a certain
moment in time.
• Identify the set of interesting objects that collaborate in that context and render
them in an object diagram.
• As necessary to understand their semantics, expose these object's states.
• As necessary to understand their semantics, identify the links that exist
among these objects.
• If your diagram ends up overly complicated, prune it by eliminating objects that
are not germane to the questions about the scenario you need answered. If your
diagram is too simplistic, expand the neighbors of certain interesting objects and
expose each object's state more deeply.