Class Diagrams PPT5

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

Object Oriented Analysis & Design

What is class diagram

Class diagram is one of the important UML diagrams for software


development which shows the object classes in the system and the associations
between these classes.

Class diagram is UML structure diagram which shows structure of the


designed system at the level of classes and interfaces, shows their features,
constraints and relationships – associations, generalizations, dependencies.

Class diagram is a static type structure diagram that describes the structure of a
system by showing system’s classes, attributes and operations, and relationship
among the objects.
Purpose of the class diagram

➢ This is the only UML that can appropriately depict various aspects of the
OOPs concept.

➢ Proper design and analysis of the applications can be faster and efficient.

➢ It is the base for deployment and component diagram.

➢ Describes responsibilities of a system.


Representing class diagram

Student(classname) A significant piece of data containing values


Attributes that describe each instance of that class.
+ name :String
+ roll :Int Also called fields, variables, properties.
- add :String
# marks :Int

Operations
- addInfo(var1,var2) :Void Also called methods or functions.
+ cal_mark() :Void
+ getInfo() :Void Allow us to specify any behavioral feature of class.
Visibility

<<Customer>>
Customer Underlined if it’s Static.
✓ public +
- Id :Int
Optional to indicate allowable null value.
- add :String
✓ private - + name :String
+ dob :Int Ordered to present ‘em in a particular order.
✓ protected # +/ age :Int
In case of Abstract it’s written either in Italic
✓ package ~ # get_Id() :Int {ordered} or inside these << >> symbols.
- product() :bool [1..*]
✓ derived / + show() :Void Multiplicity denoted by [number..*]
Features of a class

▪ Non Static Features: Characterizes individual instances of class.

▪ Static Features: represents some characteristic of the class itself.

▪ Structural Features (attributes): is a typed feature of a class that specifies the structure of
instances of the class.

▪ Behavioral Features (Methods): is a feature of a class that specifies an aspect of the behavior
of its instances.
Types of relationship

1) Association

2) Multiplicity

3) Aggregation

4) Composition

5) Generalization/Inheritance

6) Dependency

7) Constraints
Association

An Association is a line connector with label association name connects multiple classes and
denotes a logical connection. Association can be binary or N-ary, a class may Reflexive.

Students Course
chooses
Attributes Attributes

Methods Methods

Professor Book
1..* wrote 0..*
Attributes Attributes

Methods Methods
Multiplicity
0..1 , n, 0..* , 1..* , m..n

Person House Customer Product


1..* lives 1..* buys 0..*
Attributes Attributes Attributes Attributes

Methods Methods Methods


Methods

Teacher Subject Passenger Airplane


teaches 2,4..* travels
Attributes Attributes Attributes Attributes

Methods Methods Methods Methods


Navigability
End property of association is navigable from the opposite end(s) of association if instances of
the classes at this end of the link can be accessed efficiently at run-time from instances at the
other ends of the link.

Navigable end is indicated by an open arrowhead on the end of an association.

Non navigable end is indicated with a small x on the end of an association.

A1 B1 A4 B4
Both ends of association are unspecified navigability A4 is not navigable while B4 is navigable from A4

A2 B2 A5 B5
A2 has unspecified navigability while B2 is navigable from A2 A5 is navigable from B5 and B5 is navigable from A5

A3 B3 A6 B6
A3 is not navigable while B3 as unspecified navigability A6 is not navigable from B6and B6 is not navigable from A6
Arity

Each associations has a specific arity as it could relate two or more classes.

Binary association:

N-ary association: It is drawn as diamond (larger than a terminator on a line) with a solid line
for each association end connecting the diamond to the classifier that is the end’s type.

design
car company Usman Valentina

friend

year Adesanya Francis

Rose
Aggregation

Aggregation is a special type of weaker whole – part (has) association relationship between two
classes where the part can exist separately from the whole. It is depicted as an association
decorated with a hollow diamond at the aggregate end of the association line.

College Studenst
1
0..*
Attributes Attributes

Methods Methods

College ‘has’ Students


Aggregation examples
1 *
Library Books

1 1..*
Copy Pages

1
Computer Mouse

1 1..*
Team Player

1 1..*
Hospital Doctor
Composition

Composition is a special type of whole – part (contain) relationship between two classes where
the part cannot exist on its own separately from the whole. It is depicted as a binary association
decorated with a filled black diamond at the aggregate end.

Building Office
1 1..*
Attributes Attributes

Methods Methods

Building ‘contain’ Office


Composition examples
1 1..*
Browser Tabs

1 1..*
Pound Fish

1 1..*
Forest Tree

1 0..*
Folder Files

1 1..*
Forest Animal
Generalization
A generalization is shown as a line with a hollow triangle as an arrowhead.

Account Account

Checking Savings Credit Checking Savings Credit


Account Account Account Account Account Account

Separate target style Shared target style


Inheritance
Inheritance means showing the parent-child relationship, showing the superclass and subclass
relationship.

Animal

Attribute

Method

Turtle Horse Whale


Attribute Attribute Attribute

Method Method Method


Multiple Inheritance
Multiple inheritance is implicitly allowed by UML standard, while the standard provides no
definition of what it is.
Employee

Temporary Permanent
Employee Employee

Manager

Consultant

Director Permanent
Consultant
Manager Manager
Dependency
Dependency is a directed relationship which is used to show that some UML element or a set
of elements requires, needs or depends on other model elements for specification or
implementation.

Dependency relationship is the weakest relationship that exists between two classes if the
changes to the definition of one may cause a change into the other but not the vice-versa.

Schedule Meeting

- scheduleIn - topic
+ scheduleGrp + time
- date
Schedule(Meeting) setMeeting()
Constraints
Vendor should be
listed in NSE

Purchased from
Stock Vendor
* *
Constraint on Vendor List

Regulated Water Cooler

Activates Activates

Heater Cooler

Constraint on Activation of Heater and Cooler


User
- UserId
Customer - Pswd
- name - Date
1 - Address + userlogin()
- email
Administrator
+ register()
+ login() - Name
0..*
1 - email
Shopping Cart
- cartId + update()
- productid
- quantity Shipping Info
1
- shippingId
+ add() - ShippingCost Order Details
0..*
+ update() - shippingType
Order 1 - orderId
+ checkout()
- orderId - ProductId
- Status + updateInfo() - quantity
- name 1 1 + calprice()
+ placeOrder()

You might also like