0% found this document useful (0 votes)
13 views87 pages

Unit-2 Intro To UML - OOP

The document provides an introduction to Unified Modeling Language (UML), detailing its purpose as a standard language for modeling software and non-software systems. It discusses UML's goals, building blocks, object-oriented concepts, and the significance of UML diagrams in visualizing system architecture. Additionally, it outlines the structural and behavioral components of UML, including various types of relationships and diagrams used in object-oriented design.

Uploaded by

tritik59
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views87 pages

Unit-2 Intro To UML - OOP

The document provides an introduction to Unified Modeling Language (UML), detailing its purpose as a standard language for modeling software and non-software systems. It discusses UML's goals, building blocks, object-oriented concepts, and the significance of UML diagrams in visualizing system architecture. Additionally, it outlines the structural and behavioral components of UML, including various types of relationships and diagrams used in object-oriented design.

Uploaded by

tritik59
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 87

Unit-2

introdUction to Unified Modeling langUage


(UMl)

Mr. Mandeep Singh


Assistant Professor
CSE Dept., RKGIT

B.Tech (CSE),GGSIPU,
M.Tech- IS, (AIACT&R, GGSIPU),
Ph.D.(P)-CSE, NIT Jalandhar
● UML is a standard language for specifying, visualizing, constructing, and
documenting the artifacts of software systems.
● UML was created by the Object Management Group (OMG) and UML 1.0
specification draft was proposed to the OMG in January 1997.

OMG is continuously making efforts to create a truly industry standard.


● UML stands for Unified Modeling Language.
● UML is different from the other common programming languages such as
C++, Java, COBOL, etc.
● UML is a pictorial language used to make software blueprints.
● UML can be described as a general purpose visual modeling language to
visualize, specify, construct, and document software system.
● Although UML is generally used to model software systems, it is not
limited within this boundary. It is also used to model non-software
systems as well. For example, the process flow in a manufacturing unit,
etc.
UML is not a programming language but tools can be used to generate code
in various languages using UML diagrams. UML has a direct relation with
object oriented analysis and design. After some standardization, UML has
become an OMG standard.
goals of UMl
● There are a number of goals for developing UML but the most important is
to define some general purpose modeling language, which all modelers can
use and it also needs to be made simple to understand and use.
● UML diagrams are not only made for developers but also for business
users, common people, and anybody interested to understand the system.
● The system can be a software or non-software system. Thus it must be
clear that UML is not a development method rather it accompanies with
processes to make it a successful system.
In conclusion, the goal of UML can be defined as a simple modeling
mechanism to model all possible practical systems in today’s complex
environment.
a conceptUal Model of UMl
● A conceptual model can be defined as a model which is made of concepts
and their relationships.
● A conceptual model is the first step before drawing a UML diagram. It helps
to understand the entities in the real world and how they interact with
each other.
● As UML describes the real-time systems, it is very important to make a
conceptual model and then proceed gradually.
The conceptual model of UML can be mastered by learning the following
three major elements −
UML building blocks

Rules to connect the building blocks


Common mechanisms of UML



object-oriented concepts
● An object contains both data and methods that control the data. The data
represents the state of the object.
● A class describes an object and they also form a hierarchy to model the
real-world system.
● The hierarchy is represented as inheritance and the classes can also be
associated in different ways as per the requirement.
● Objects are the real-world entities that exist around us and the basic
concepts such as abstraction, encapsulation, inheritance, and
polymorphism all can be represented using UML.
● UML diagrams are representation of object-oriented concepts only.

Following are some fundamental concepts of the object-oriented world:


● Objects − Objects represent an en ty and the basic building block.
● Class − Class is the blue print of an object.
● Abstraction − Abstrac on represents the behavior of an real world en ty.
● Encapsulation − Encapsula on is the mechanism of binding the data
together and hiding them from the outside world.
● Inheritance − Inheritance is the mechanism of making new classes from
existing ones.
● Polymorphism − It defines the mechanism to exists in different forms.
oo analysis and design
● The most important purpose of OO analysis is to identify objects of a
system to be designed.
● After identifying the objects, their relationships are identified and finally
the design is produced.

The purpose of OO analysis and design can described as −


● Identifying the objects of a system.
● Identifying their relationships.
● Making a design, which can be converted to executables using OO
languages.
● During OO analysis (First Phase), the most important purpose is to identify
objects and describe them in a proper way. If these objects are identified
efficiently, then the next job of design is easy. The objects should be
identified with responsibilities.
● Responsibilities are the functions performed by the object. Each and every
object has some type of responsibilities to be performed. When these
responsibilities are collaborated, the purpose of the system is fulfilled.

● The second phase is OO design. During this phase, emphasis is placed on


the requirements and their fulfilment. In this stage, the objects are
collaborated according to their intended association. After the association
is complete, the design is also complete.
● The third phase is OO implementation. In this phase, the design is
implemented using OO languages such as Java, C++, etc.
role of UMl in oo design
● UML is a modeling language used to model software and non-software
systems.
● The emphasis is on modeling OO software applications.
● The relation between OO design and UML is very important to understand.
The OO design is transformed into UML diagrams according to the
requirement.
UMl bUilding blocks
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. The basic UML
building blocks are enlisted below:

1. Things
2. Relationships
3. Diagrams
things
Anything that is a real world entity or object is termed as
things. It can be divided into several different categories:

● Structural things
● Behavioral things
● Grouping things
● Annotational things
strUctUral things
❖ Structural things define the static part of the model. In
other words, Nouns that depicts the static behavior of a
model is termed as structural things.
❖ They represent the physical and conceptual elements.

❖ They include class, object, interface, node,


collaboration, component, and a use case.
❖ Class
● A Class is a set of identical things that outlines the functionality and
properties of an object. It also represents the abstract class whose
functionalities are not defined.
● Class represents a set of objects having similar responsibilities.
● Its notation is as follows
Interface − Interface defines a set of operations, which specify the responsibility of a
class.

Collaboration −Collaboration defines an interaction between elements.

Use case −Use case represents a set of actions performed by a system for a specific
goal.

Component −Component describes the physical part of a system.


Node − A node can be defined as a physical element that exists at run time.
behavioral things

❖ A behavioral thing consists of the dynamic parts


of UML models.
❖ It depicts the behavior of a system.
❖ They involve interaction, state machine, grouping
things, annotation things.
❖ Interaction
Interaction is defined as a behavior that consists of a group of messages
exchanged among elements to accomplish a specific task.

Message

❖ State Machine
It defines a sequence of states that an entity goes through in the software
development lifecycle. It keeps a record of several distinct states of a system
component.
varioUs states of state
Machine
relationships
It illustrates the meaningful connections between things. It shows the association between
the entities and defines the functionality of an application. There are four types of
relationships given below:
Dependency: Dependency is a kind of relationship in which a change in target element
affects the source element, or simply we can say the source element is dependent on the
target element. It is one of the most important notations in UML. It depicts the dependency
from one entity to another.
It is denoted by a dotted line followed by an arrow at one side as shown below,
Association: A set of links that associates the entities to the UML model. It
tells how many elements are actually taking part in forming that relationship.
It is denoted by a dotted line with arrowheads on both sides to describe the
relationship with the element on both sides.

Generalization: It portrays the relationship between a general thing (a parent class or


superclass) and a specific kind of that thing (a child class or subclass). It is used to
describe the concept of inheritance.

It is denoted by a straight line followed by an empty arrowhead at one side.


Realization: It is a semantic kind of relationship between two things,
where one defines the behavior to be carried out, and the other one
implements the mentioned behavior. It exists in interfaces.
It is denoted by a dotted line with an empty arrowhead at one side.
UMl- architectUre
Any real-world system is used by different users. The users can be developers, testers,
business people, analysts, and many more. Hence, before designing a system, the
architecture is made with different perspectives in mind. The most important part is to
visualize the system from the perspective of different viewers. The better we understand
the better we can build the system.
UML plays an important role in defining different perspectives of a system. These
perspectives are −
● Design
● Implementation
● Process
● Deployment
❖ The center is the Use Case view which connects all these four. A Use
Case represents the functionality of the system. Hence, other perspectives
are connected with use case.
❖ Design of a system consists of classes, interfaces, and collaboration. UML
provides class diagram, object diagram to support this.
❖ Implementation defines the components assembled together to make a
complete physical system. UML component diagram is used to support
the implementation perspective.
❖ Process defines the flow of the system. Hence, the same elements as used
in Design are also used to support this perspective.
❖ Deployment represents the physical nodes of the system that forms the
hardware. UML deployment diagram is used to support this perspective.
UMl diagraMs
UML diagrams are the ultimate output of the entire discussion. All the elements, relationships
are used to make a complete UML diagram and the diagram represents a system.
The visual effect of the UML diagram is the most important part of the entire process. All the
other elements are used to make it complete.
UML includes the following nine diagrams, the details of which are described in the subsequent
chapters.
● Class diagram
● Object diagram
● Use case diagram
● Sequence diagram
● Collaboration diagram
● Activity diagram
● Statechart diagram
● Deployment diagram
● Component diagram
strUctUral diagraMs
The structural diagrams represent the static aspect of the system. These static
aspects represent those parts of a diagram, which forms the main structure and are
therefore stable.
These static parts are represented by classes, interfaces, objects, components, and
nodes. The four structural diagrams are −
● Class diagram
● Object diagram
● Component diagram
● Deployment diagram
class diagraMs

Class diagram is a static diagram. It represents the static view of an


application. Class diagram is not only used for visualizing, describing, and
documenting different aspects of a system but also for constructing executable
code of the software application.
Class diagram describes the attributes and operations of a class and also the
constraints imposed on the system. The class diagrams are widely used in the
modeling of object oriented systems because they are the only UML diagrams,
which can be mapped directly with object-oriented languages.
Class diagram shows a collection of classes, interfaces, associations,
collaborations, and constraints. It is also known as a structural diagram.
essential eleMents of a UMl class diagraM
Essential elements of UML class diagram are:

1. Class Name
2. Attributes
3. Operations
Class Name
The name of the class is only needed in the graphical representation of the class.
It appears in the topmost compartment. A class is the blueprint of an object which
can share the same relationships, attributes, operations, & semantics. The class is
rendered as a rectangle, including its name, attributes, and operations in separate
compartments.

Following rules must be taken care of while representing a class:

1. A class name should always start with a capital letter.


2. A class name should always be in the center of the first compartment.
3. A class name should always be written in bold format.
4. An abstract class name should be written in italics format.
Attributes:
An attribute is named property of a class which describes the object being
modeled. In the class diagram, this component is placed just below the name-
compartment.

Attributes characteristics:

● The attributes are generally written along with the visibility factor.
● Public, private, protected and package are the four visibilities which are
denoted by +, -, #, or ~ signs respectively.
● Visibility describes the accessibility of an attribute of a class.
● Attributes must have a meaningful name that describes the use of it in a
class.
Class Operations (Methods)
❖ Operations are shown in the third partition. They are services the
class provides.
❖ The return type of a method is shown after the colon at the end of
the method signature.
❖ The return type of method parameters is shown after the colon
following the parameter name.
❖ Operations map onto class methods in code.
Relationships in Class Diagrams
Classes are interrelated to each other in specific ways. In particular, relationships in
class diagrams include different types of logical connections. The following are such
types of logical connections that are possible in UML:

● Dependency
● Association
● Directed Association
● Reflexive Association
● Multiplicity
● Aggregation
● Composition
● Inheritance/Generalization
● Realization
Dependency
A dependency means the relation between two or more classes in which a change in
one may force changes in the other. However, it will always create a weaker
relationship. Dependency indicates that one class depends on another.

In the following example, Student has a dependency on College


Generalization:
A generalization helps to connect a subclass to its superclass. A sub-class is inherited
from its superclass. Generalization relationship can't be used to model interface
implementation. Class diagram allows inheriting from multiple superclasses.

In this example, the class Student is generalized from Person Class.


Association:
This kind of relationship represents static relationships between classes A and B. For
example; an employee works for an organization.
Here are some rules for Association:
● Association is mostly verb or a verb phrase or noun or noun phrase.
● It should be named to indicate the role played by the class attached at the end of the
association path.
● Mandatory for reflexive associations
In this example, the relationship between student and college is shown which is studies.
Multiplicity
A multiplicity is a factor associated with an attribute. It specifies how many instances of
attributes are created when a class is initialized. If a multiplicity is not specified, by default
one is considered as a default multiplicity.

Let's say that that there are 100 students in one college. The college can have multiple
students.
Aggregation

Aggregation is a special type of association that models a whole- part


relationship between aggregate and its parts.

For example, the class college is made up of one or more student. In


aggregation, the contained classes are never totally dependent on the
lifecycle of the container. Here, the college class will remain even if the
student is not available.
Composition:
The composition is a special type of aggregation which denotes strong ownership
between two classes when one class is a part of another class.

For example, if college is composed of classes student. The college could contain
many students, while each student belongs to only one college. So, if college is
not functioning all the students also removed.
Aggregation vs. Composition
Abstract Classes
It is a class with an operation prototype, but not the implementation. It is also possible to have
an abstract class with no operations declared inside of it. An abstract is useful for identifying
the functionalities across the classes. Let us consider an example of an abstract class. Suppose
we have an abstract class called as a motion with a method or an operation declared inside of it.
The method declared inside the abstract class is called a move ().

This abstract class method can be used by any object such as a car, an animal, robot, etc. for
changing the current position. It is efficient to use this abstract class method with an object
because no implementation is provided for the given function. We can use it in any way for
multiple objects.

In UML, the abstract class has the same notation as that of the class. The only difference
between a class and an abstract class is that the class name is strictly written in an italic font.

An abstract class cannot be initialized or instantiated.


pUrpose of class diagraMs
The purpose of class diagram is to model the static view of an application. Class
diagrams are the only diagrams which can be directly mapped with object-oriented
languages and thus widely used at the time of construction.
UML diagrams like activity diagram, sequence diagram can only give the sequence
flow of the application, however class diagram is a bit different. It is the most popular
UML diagram in the coder community.
The purpose of the class diagram can be summarized as −
● Analysis and design of the static view of an application.
● Describe responsibilities of a system.
● Base for component and deployment diagrams.
● Forward and reverse engineering.
How to Draw a Class Diagram?

Basically, Class diagrams are the most popular UML diagrams used for
construction of software applications. It is very important to learn the drawing
procedure of class diagram.
Class diagrams have a lot of properties to consider while drawing but here the
diagram will be considered from a top level view.
Class diagram is basically a graphical representation of the static view of the
system and represents different aspects of the application. A collection of class
diagrams represent the whole system.
The following points should be remembered while drawing a class
diagram −
● The name of the class diagram should be meaningful to describe the aspect
of the system.
● Each element and their relationships should be identified in advance.
● Responsibility (attributes and methods) of each class should be clearly
identified
● For each class, minimum number of properties should be specified, as
unnecessary properties will make the diagram complicated.
● Use notes whenever required to describe some aspect of the diagram. At
the end of the drawing it should be understandable to the developer/coder.
● Finally, before making the final version, the diagram should be drawn on
plain paper and reworked as many times as possible to make it correct.
Where to Use Class Diagrams?

Class diagrams are used for −


● Describing the static view of the system.
● Showing the collaboration among the elements of the
static view.
● Describing the functionalities performed by the system.
● Construction of software applications using object
oriented languages.
benefits of class diagraM

● Class Diagram Illustrates data models for even very complex


information systems
● It provides an overview of how the application is structured before
studying the actual code. This can easily reduce the maintenance time
● It helps for better understanding of general schematics of an application.
● Allows drawing detailed charts which highlights code required to be
programmed
● Helpful for developers and other stakeholders.
Class Diagram in Software Development Lifecycle
Class diagrams can be used in various software development phases. It helps in modeling
class diagrams in three different perspectives.

1. Conceptual perspective: Conceptual diagrams are describing things in the real world.
You should draw a diagram that represents the concepts in the domain under study. These
concepts related to class and it is always language-independent.

2. Specification perspective: Specification perspective describes software abstractions or


components with specifications and interfaces. However, it does not give any commitment to
specific implementation.

3. Implementation perspective: This type of class diagrams is used for implementations in


a specific language or application. Implementation perspective, use for software
implementation.
visibility in class diagraMs
The visibility of the attributes and operations can be represented in the following ways:
❖ Public − A public member is visible from anywhere in the system. In class
diagram, it is prefixed by the symbol ‘+’.
❖ Private − A private member is visible only from within the class. It cannot be
accessed from outside the class. A private member is prefixed by the symbol ‘−’.
❖ Protected − A protected member is visible from within the class and from the
subclasses inherited from this class, but not from outside. It is prefixed by the
symbol ‘#’.
tools for creating UMl diagraMs

❖ Rational Rose
❖ Violet
❖ Umbrello(for linux)
❖ Visual Paradigm UML Suite
class diagraM
eXaMples
eXaMples of class diagraM
The following diagram is an example of an Order System of an application. It
describes a particular aspect of the entire application.
● First of all, Order and Customer are identified as the two elements of the
system. They have a one-to-many relationship because a customer can have
multiple orders.
● Order class is an abstract class and it has two concrete classes (inheritance
relationship) SpecialOrder and NormalOrder.
● The two inherited classes have all the properties as the Order class. In
addition, they have additional functions like dispatch () and receive ().
The following class diagram has been drawn considering all the points mentioned
above.
2nd eXaMple
Creating a class diagram is a straightforward process. It does not involve
many technicalities.

Here, is an example:

ATMs system is very simple as customers need to press some buttons to


receive cash. However, there are multiple security layers that any ATM
system needs to pass. This helps to prevent fraud and provide cash or need
details to banking customers.

Below given is a UML Class Diagram example:


conclUsion
❖ UML is the standard language for specifying, designing, and visualizing the artifacts
of software systems
❖ A class is a blueprint for an object
❖ A class diagram describes the types of objects in the system and the different kinds of
relationships which exist among them
❖ It allows analysis and design of the static view of a software application
❖ Class diagrams are most important UML diagrams used for software application
development
❖ Essential elements of UML class diagram are 1) Class 2) Attributes 3) Relationships
❖ Class Diagram provides an overview of how the application is structured before
studying the actual code. It certainly reduces the maintenance time
❖ The class diagram is useful to map object-oriented programming languages like Java,
C++, Ruby, Python, etc.
object diagraMs
❖ Objects are the real-world entities whose behavior is defined by the classes.
Objects are used to represent the static view of an object-oriented system. We
cannot define an object without its class. Object and class diagrams are somewhat
similar.
❖ In other words, “An object diagram in the Unified Modeling Language (UML), is a
diagram that shows a complete or partial view of the structure of a modeled system at a
specific time.”
❖ An object diagram shows this relation between the instantiated classes and the defined
class, and the relation between these objects in the system. They are be useful to explain
smaller portions of your system, when your system class diagram is very complex, and
also sometimes modeling recursive relationship in diagram.
❖ Object diagrams are used to render a set of objects and their relationships as an
instance.
Basic Object Diagram Symbols and Notations

Object Names:

● Every object is actually symbolized like a rectangle, that offers the name from the object and its class

underlined as well as divided with a colon.

Object Attributes:

● Similar to classes, you are able to list object attributes inside a separate compartment. However,

unlike classes, object attributes should have values assigned for them.
Links:

● Links tend to be instances associated with associations. You can draw a link while

using the lines utilized in class diagrams.


Notation of an object diagram:
pUrpose of an object diagraM:

1. It is used to describe the static aspect of a system.


2. It is used to represent an instance of a class.
3. It can be used to perform forward and reverse engineering on
systems.
4. It is used to understand the behavior of an object.
5. It can be used to explore the relations of an object and can be
used to analyze other connecting objects.
how to draw an object diagraM?

1. Before drawing an object diagram, one should analyze all the objects
inside the system.
2. The relations of the object must be known before creating the diagram.
3. Association between various objects must be cleared before.
4. An object should have a meaningful name that describes its
functionality.
5. An object must be explored to analyze various functionalities of it.
applications of object diagraMs:

1. Object diagrams play an essential role while generating a


blueprint of an object-oriented system.
2. Object diagrams provide means of modeling the classes, data
and other information as a set or a single unit.
3. It is used for analyzing the online or offline system. The
functioning of a system can be visualized using object diagrams.
where to Use object diagraMs?

It can be said that object diagrams are used for −


● Making the prototype of a system.
● Reverse engineering.
● Modeling complex data structures.
● Understanding the system from practical perspective.
eXaMples:
The following diagram is an example of an object diagram. It represents the Order
management system which we have discussed in the chapter Class Diagram. The following
diagram is an instance of the system at a particular time of purchase. It has the following
objects.
● Customer
● Order
● SpecialOrder
● NormalOrder
Now the customer object (C) is associated with three order objects (O1, O2, and O3). These order
objects are associated with special order and normal order objects (S1, S2, and N1). The customer has
the following three orders with different numbers (12, 32 and 40) for the particular time considered.
The customer can increase the number of orders in future and in that scenario the object diagram will
reflect that. If order, special order, and normal order objects are observed then you will find that they
have some values.
Object Diagram Example II - POS
Object Diagram Example III - Writer
Object Diagram Example IV - Robot Moving Behavior
Object Diagram Example V - Deriving an Object Structure Similar to
Class Diagram

Besides showing the objects' state at a particular point in time, an object


diagram can also be used to represent the occurrences of interactions
between classes in runtime. The result looks a bit like a communication
diagram.

The figure below provides an example of such a class diagram and its
corresponding object diagram:
sUMMary of object diagraM

1. Class groups together things that share similar behavior.


2. A class represents a bird's eye view of a system, i.e., an abstraction
which is an object-oriented programming concept.
3. An object represents a static view of an object-oriented system.
4. One class can refer to multiple classes.
5. A single class can have any number of objects.
6. Objects are related to one another because they share the same class.
7. The object of different classes can also be connected.
thank yoU !!

You might also like