You are on page 1of 15

Unified Modeling Language[UML]

UML stands for Unified Modeling Language


Unified Modeling Language [UML] is a modeling language for
Software systems.
It is a way of interaction between different stakeholders of a system.
It is developed for specifying, visualizing, constructing and documenting
the artifacts of a system.
Basic building blocks of Unified Modeling Language
Things
Relationships
Diagrams

Things
Things are the most important building blocks of UML. Things can be −

 Structural
 Behavioral
 Grouping
 Annotational

Structural Things

Structural things define the static part of the model. They represent the physical and
conceptual elements. Following are the brief descriptions of the structural things.
Class − Class represents a set of objects having similar responsibilities.

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. Following are the
behavioral things −
Interaction − Interaction is defined as a behavior that consists of a group of messages
exchanged among elements to accomplish a specific task.

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

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.

Annotational Things

Annotational things can be defined as a mechanism to capture remarks, descriptions,


and comments of UML model elements. Note - It is the only one Annotational thing
available. A note is used to render comments, constraints, etc. of an UML element.

Relationship
Relationship is another most important building block of UML. It shows how the
elements are associated with each other and this association describes the
functionality of an application.
There are four kinds of relationships available.

Dependency

Dependency is a relationship between two things in which change in one element also
affects the other.

Association

Association is basically a set of links that connects the elements of a UML model. It
also describes how many objects are taking part in that relationship.
Generalization

Generalization can be defined as a relationship which connects a specialized element


with a generalized element. It basically describes the inheritance relationship in the
world of objects.

Realization

Realization can be defined as a relationship in which two elements are connected. One
element describes some responsibility, which is not implemented and the other one
implements them. This relationship exists in case of interfaces.

Types of UML diagrams


Class Diagram
Object Diagram
Use Case Diagram
Sequence Diagram
Collaboration Diagram
State Char Diagram
Activity Diagram
Component Diagram
Deployment Diagram
Class Diagram
ClassName
Attributes
Operations

Attribute  A significant piece of data containing values that describe


each instance of that Class. also called fields, variables, properties.
Methods Also called as Operations or functions. Allows you to
specify any behavioral feature of a Class.
Example
Animal
-name : string
-id : int
-age : int
-setName()
-eat()

Visibility
-private : They can’t accessed by any other class or sub class. In UML
private visibility is denoted as -
+public : An attribute or method is public, which can be accessed by any
other class. In UML public visibility is denoted as +
#protected : An attribute or method is protected. These can be accessed
by the same class or sub – classes. In UML protected visibility is
denoted as #
~package / default : This sets the visibility to package or default, which
means it can be used by any other class.
Example :
Employee
-name : string
-empid : int
-phone : int
-dept : string
+updatePhone()

In the above example, Employee is the name the class. name, empid,
phone, dept are attributes for the class Employee and they are declared
as private.
updatePhone() is a method of class Employee and it is declared as
public.

Inheritance :

Animal
- name : string
- id : string
- age : string
- weight : int
- setName()
- eat()

Tortoise Camel
This is an Inheritance relationship.
These sub – classes will inherit all the attributes and methods of the
super class . These sub classes will use the attributes name, id and age.
Association / Multiplicity
Associations show relationships between classes.
There are 2 types of Associations.
Unary Association and Binary Association

Unary Association

Class A Class B

Between the classes we’ve a single line with one arrow.


Class A knows about Class B.
Class B knows nothing about Class A.
Example :

Person Address

There is an association between a Person and an Address.


Sometimes, people think as ‘has – a’ relationship in contrast to the ‘is –
a’ relationship of Inheritance.

has - a
Person Address
Person has – a Address.
Person knows its Address.
Address doesn’t know who is living there.
Class Address doesn’t know about Class Person.

Class A Class B

+doSomething() +actionB()

-myB

This is also possible in Association.


Here, Class A has a method ‘doSomething()’ and class B has another
method which is ‘actionB()’.
We’re also representing the Association with name called “myB”.

Class A Class B
-myB : Class B
+doSomething() +actionB()

In Class A also added a value in the attributes field. Here we’ve an


attribute it is called as myB and it is of type Class B.

Class A
Class B

+doSomething() +actionB()

-myB

The above representation has the emphasis on the relationship between


the Class A Class B. It has that Association drawn with the arrow.

Class A Class B
-myB : Class B
+doSomething() +actionB()

The above representation has the fact that Class A has a attribute of type
Class B written in the attribute’s column.
The above two representations are identical.
Which representation should we use.
It depends on where your emphasis is. If you’re going to emphasize the
relationship of Class A to Class B, the arrow is a great way to
emphasize.
Example :

Person
Address
-name : string -street : string
+doSomething() -city : string
-zip : string
+toString() :
-address string

Class Person has 2 attributes one is name of type string and the other is
address of type Address. Both types of representations are used in the
same diagram.
3 types of Associations :
Association  most general
Aggregation  Describe whole – part relationship.
Composition  Describe whole – part relationship.
Aggregation : Aggregation are associations with a whole – part
relationship.
Example :

Class A Class B

The hollow diamond is next to the Class that represents the whole. Class
B is part of Class A.
Example :

Lake Slide

Lake has a Slide.


Notice, the hollow diamond is next to the class that represents the whole.
Lake is the whole, Slide is the part.
Example :

Car Passengers

Composition : Composition are Aggregation where the life cycle of the


part class depends on that of the whole class.

This means that the construction and destruction of the ‘part’ depends on
the ‘whole’.
The filled diamond is next to the class that represents the whole.
Example :

We have a Company and we have a Department.


A Department is part of the Company.
The construction and destruction of a department depends on the
Company.
It means, the Department can only access in the context of a Company.
We can’t have a Department, if we don’t have a Company.
Existence of Department depends on the existence of the Company.
Multiplicity : Multiplicity allows us to specify how many objects are in
this relationships.
For example, a car has one engine, a car has 4 wheels.
So, we could say something as ‘exactly n items’ or may be ‘0 or 1’
0..1 An optional instance [0 or 1]
n Exactly n instances
* Zero or more instances
1 .. * One or more instances
n .. m n to m instances

So, if I say between 2 & 4 that would be 2, 3 or 4.


House has exactly 1 Kitchen, 1 Bath and 1 or more Bedrooms.
All 3 of these , that is Kitchen, Bath and Bedroom are rooms. Here we
have Inheritance.
The hollow diamonds with black color indicates that this is
Composition.
Kitchen is part of the House, Bath is part of the House, Bedroom is part
of the House.
Kitchen, Bath and Bedroom can only exist when the house exists. If you
don’t have a House anymore we don’t have Kitchen, Bath or Bedroom.
In addition, the House has a Mailbox. Mailbox is part of the House, but
it cannot be accessed independently.
We can create a Mailbox, create a House and then bring the Mailbox set
it up in front of the House.
Mailbox is part of the House, but the life cycle of the Mailbox is
independent of the House.
The House also has a Mortgage, but Mortgage is not part of the House.
If I take away the Mortgage, I don’t have less of the House, its still the
same House.
Mortgage is associated with the House. House has a Mortgage but it is
not part of the House. Some Houses has a Mortgage whereas some
don’t.
Draw a class diagram for Online Shopping Cart
Class : Customer, User, Administrator, Shopping Cart, Order, Shipping
Info, Order Details
Class : Customer
Attributes : Customer Name, Address, email, Credit Card Info, Shipping
Info, Account Balance.
Methods : register, login, updateProfile.
Class : User
Attributes : userid, password, loginstatus, registerDate
Methods : verifyLogin.

Class : Administrator
Attributes : adminName, email
Methods : updateCatalog.
Class : Shopping Cart
Attributes : Cart Id, Product Id, quantity, dateAdded.
Methods : addCartItem, updateQuantity, viewCarddetails, checkout.
Class : Order
Attributes : orderId, datecreated, dateshipped, customerName,
customerId, States, Shipping Id.
Methods : placeOrder
Class : Shipping Info
Attributes : Shipping id, Shipping type, Shipping Cost, Shipping Region
id.
Methods : updateShippinginfo
Class : Order Details
Attributes : order id, product id, product name, quantity, unit cost, sub
total.
Methods : calcPrice

You might also like