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

Ooad 2

Uploaded by

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

Ooad 2

Uploaded by

Sohit Chauhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

Object-Oriented Design using UML

Cont…

1
Identification of Use Cases
1. Actor-based:
- Identify the actors related to a system or organization.
- For each actor, identify the processes they initiate or participate
in.
2. Event-based
- Identify the external events that the system must respond to.
- Relate the events to actors and use cases.

2
Example 2: Use Case Model for Course Management Software
• At the beginning of each semester,
– Each professor shall register the courses that he is going to teach.
• A student can select up to four-course offerings.
– During registration a student can request a course catalogue showing course offerings for the
semester.
– Information about each course such as professor, department and prerequisites would be
displayed.
– The registration system sends information to the billing system, so that the students can be
billed for the semester.
• For each semester, there is a period of time during which dropping of courses is
permitted.
• Professors must be able to access the system to see which students signed up for each
of their course offerings.

3
Course Management Software

Register Example 2:
Course
offering
See
Model Solution
Course
Show
Professor List
registrati
on
<<Extend>>
{ reg courses<
5 Regist <<External>>
courses}
{i
ft
er Billing System
od
Student
ay
<s course
et
da
te
}
Drop
Course

Calendar

4
• Use case name should begin with a verb. Style Notes
• While use cases do not explicitly imply timing:
(Ambler, 2005)
– Order use cases from top to bottom to imply timing -- it improves readability.

• The primary actors should appear in the left.


• Actors are associated with one or more use cases.
• Do not use arrows on the actor-use case relationship.
• To initiate scheduled events include an actor called “time”, or
“calendar”
• Do not show actors interacting with each other.
• <<include>> should rarely nest more than 2 levels deep.
5
• Use cases should be named and organized from the perspective of
the users.
• Use cases should start off simple and at as much high view as
possible.
– Can be refined and detailed further. Effective Use Case Modelling

• Use case diagrams represent functionality:


– Should focus on the "what" and not the "how".

6
Use Case Packaging

Accounts

Print
Query balance
Balance sheet

Receive Make
grant payments

7
Class Diagram
• Classes:
– Entities with common features, i.e. attributes and operations.
– Represented as solid outline rectangle with compartments.
– Compartments for name, attributes, and operations.
– Attribute and operation compartments are optional depending on
the purpose of a diagram.

8
UML Class Representation
• A class represents a set of objects having similar attributes,
operations, relationships and behavior.
Class
Name Window
A class can
size: Size implicitly
Attributes visibility: have a few
boolean associatio
n
attributes
display()
Operations hide()

9
Different representations of the LibraryMember class

LibraryMember LibraryMember LibraryMember

Member Name issueBook( );


Membership Number findPendingBooks( );
Address findOverdueBooks( );
Phone Number returnBook( );
E-Mail Address findMembershipDetails( );
Membership Admission Date
Membership Expiry Date
Books Issued

issueBook( ); Example UML


findPendingBooks( );
findOverdueBooks( ); Classes
returnBook( );
findMembershipDetails( );

10
What are the Different Types of Relationships
Among Classes?
• Four types of relationships:
– Inheritance
– Association
– Aggregation/Composition
– Dependency

11
Inheritance
LibraryMember Base Class

• Allows to define a new class (derived class)


by extending an existing class (base class).
Derived
Faculty Students Staff
Classes

–Represents generalization-specialization

–Allows redefinition of the existing methods


UnderGrad PostGrad Research

(method overriding).

12
Inheritance Example
Animal “A Dog ISA
Animal”
“A Cat ISA
Animal”

Dog Cat

13
Inheritance
• Lets a subclass LibraryMember Base Class
inherit attributes
and methods from
Derived
a base class. Faculty Students Staff
Classes

UnderGrad PostGrad Research

14
Multiple Base Class
LibraryMember Base Class
LibraryMember

Inheritance

Derived
Faculty Students Staff Faculty Students Staff
Classes

Multiple
Inheritance

UnderGrad PostGrad Research UnderGrad PostGrad Research

15
Inheritance Implementation in Java
Inheritance is declared using the "extends" keyword
Even when no inheritance defined, the class implicitly extends a class called
Object. Person
class Person{ - name: String

private String name; - dob: Date


private Date dob;
...
}
class Employee extends
Person{ Employee
- employeeID: int
private int employeeID;
- salary: int
private int salary; - startDate: Date
private Date startDate;
... Employee anEmployee = new
} Employee();
16
Objects myRectangle and myBox Rectangle

Rectangle myRectangle = new


Box
Rectangle(5, 3);
Box myBox = new Box(6, 5, 4);

length 5.0 length 6.0


myRectangle
myBox

width 3.0 width 5.0

Object height 4.0


Reference
17
Quadrupe
Mammal
d

More
Generalization
Feline Lizard
Examples…

Tiger Lion Cat

18
Inheritance Example Library
Book

issuable reference

Issuable Reference
Issuable Reference
Single Volume Single Volume
BookSet BookSet
Book Book

Discriminator: allows one to group subclasses


clusters that correspond to a semantic category.

19
Inheritance Pitfalls
• Inheritance certainly promotes reuse.
• Indiscriminate use can result in poor quality
programs.
• Base class attributes and methods visible in derived
class…
– Leads to tight coupling
20
Association Relationship
• How implemented in program?
• Enables objects to communicate with each other:
–One object must “know” the ID of the corresponding
object in the association.
• Usually binary:
–But in general can be n-ary.
21
Association – example
• In a home theatre system,
– A TV object has an association with a VCR object
• It may receive a signal from the VCR
– VCR may be associated with remote
• It may receive a command to record
1 1 1 1
Remote commandsVCR Connected TV
to

22
1-1
Association – tax_file
example Rakesh Shukla 760901-1234

V. Ramesh
691205-5678
Keshab Parhi

People Tax_files

People1Associated 1
Tax_files
with

23
motherOf
Multiple
Bhim
Association – motherOf
example Kunti Yudhistir
motherOf
Arjun
Woman Person

Woman1 Mother of
*
Person

24
Association UML Syntax
role B
Class A role A Class B

• A Person works for a Company. Role

Person employee employe Company


r
works for

Association Name

25
Association - More Examples
1 borrowed
Library Member by *..5 Book

eats * Human
Lion *

Multiplicity: The number of objects from one class


that relate with a single object in an associated
class.
26
Navigability

opens 0..5
Key * Door

27
Association –
Multiplicity
• A teacher teaches 1 to 3 courses (subjects)
• Each course is taught by only one teacher.
• A student can take between 1 to 5 courses.
• A course can have 10 to 300 students.
1 teaches 1..3
Teacher Course
1..5

takes
Students
10..300

28
Quiz: Draw Class Diagram
• A Student can take up to five Courses.

• A student needs to enroll in at least one course.

• Up to 300 students can enroll in a course.

• An offered subject in a semester should have at least 10


registered students.

29
Student credit hasEnrolment Course
s10..30 Of in
Enrols 1..5
0

30
Student credit hasEnrolmen Course
Identify as s
20..30 tOf in
Enrols 1..5
0
Correct or
Wrong Student credit hasEnrolmen Course
s
20..30 tOf in
Enrols 1..5
0

Student credit hasEnrolmen Course


s
20..30 tOf in
Enrols 1..5
0

Student credit hasEnrolmen Course


s
20..30 tOf in
Enrols 1..5
0

31
Quiz: Read the Diagram

1..2 teaches 0..3


Teacher Course

opens 0..5
Key * Door

32
Association and Link
• A link:
– An instance of an association
– Exists between two or more objects
– Dynamically created and destroyed as the run of a
system proceeds
• For example:
– An employee joins an organization.
– Leaves that organization and joins a new organization.
33
Association Relationship
• A class can be associated with itself (unary association).
– Give an example?

• An arrowhead used along with name:


*
– Indicates direction of association. Person *
Friend
of
• Multiplicity indicates # of instances taking part in the
association.
34
Self Association: Example of
Computer Network

Connects
to
*

Computer *

35
Node1 Node2 Node3
Computer
Network: Object Node4
Diagram
Node5

Node6 Node7 Node8

36
Association Exercise 1
• A Person works for a Company.
Role Implicit attribute of type Company

Implicit attribute of type Person

Personemployee Company
employe
works for r

Association Name

Observe: Implicit bidirectional navigationImplementation?

37
Types of Class Relation
Relationships
Generalization Association Dependency

Binary Association N-ary


Association

Aggregation

Composition

38
Aggregation Relationship
• Represents whole-part relationship
• Represented by a diamond symbol at the composite end.
• Usually creates the components:
– Also, aggregate usually invokes the same operations of all its
components.
– This is in contras to plain association
• Usually owner of the components:
– But can share with other classes

39
Aggregation Relationship

Document 1
* Paragraph 1 * Line

1
Company
employs
* 0..1
Person* memberOf Club

40
Aggregation cont…

An aggregate object contains other objects.


Aggregation limited to tree hierarchy:


 No circular aggregate relation. Paragraph


1
Line

41
Aggregation vs. Inheritance
Cont…
Inheritance:
 Different object types with similar features.
 Necessary semantics for similarity of behavior is in place.

Aggregation:
 Containment allows construction of complex objects.

42
Composition
• A stronger form of aggregation
– The whole is the sole owner of its part.
• A component can belong to only one whole
– The life time of the part is dependent upon the whole.
• The composite must manage the creation and destruction of its
parts. 1
Circle Point Circle
3..* Point
Polygon

43
Composition Relationship
• Life of item is same as that of order

1
Order * Item

44
Composition: Alternate Notation
Car
4 1
Wheel Engin
e
2 1
Door
Chassis
1 1
Axle Steerin
g

45
Composition
Window whole
• An object may be a part of ONLY
1
one composite at a time.
 Whole is responsible for the
creation and disposition of its parts. *
Frame part

46
• Composition: Aggregation vs. Composition
– Composite and components have the same life line.
• Aggregation:
– Lifelines are different.
• Consider an order object:
– Aggregation: If order items can be
changed or deleted after placing order.
– Composition: Otherwise.
47
Composition versus Aggregation
1
* Compositi
Order Item
on

1
* Aggregatio
Order Item
n

48
Implementing public class Car{
Composition private Wheel wheels[4];
public Car (){
wheels[0] = new Wheel();
wheels[1] = new Wheel();
wheels[2] = new Wheel();
wheels[3] = new Wheel();
} 1 4 Wheel
Car
}
49
How to identify aggregation/composition?
• Lifetime of part is bound within lifetime of composite
–There is a create-delete dependency

• There is an obvious whole-part physical or logical assembly


• Some properties of composite propagate to parts (e.g.,
location)
• Operations applied to composite propagate to parts (e.g.,
destruction, movement, recording)
50
Class Dependency

Dependent Class Independent Class

51
Dependency
• Dependency relationship can arise due to a variety of reasons:
– Stereotypes are used to show the precise nature of the dependency.
Type of Stereotype Description
dependenc
y
Abstractio «abstraction» Dependency of concrete class on its abstract
n class.
Binding «bind» Binds template arguments to create model
elements from templates.
Realization «realize» Indicates that the client model element is an
implementation of the supplier model element
Substitutio «substitute» Indicates that the client model element takes
n place of the supplier.
Association Vs. Aggregation

• Is aggregation an association?

• Is composition an aggregation?

53
Car

• aggregation: "is part of" 1


Association 1 aggregati
– Symbolized by empty diamond on
Types Engine

• composition: is made of
Book
compositio
– Stronger version of aggregation n 1

*
– The parts live and die with the whole Page

– Symbolized by a filled diamond


dependen
• dependency: Depends on Lotter
cy
Rando
y m
– Represented by dotted arrow. Ticket
54
UML Class Class
Relation Generalization
Relationship
dependen
cy
Notation
Summary
Object Object
Aggregation Composition
Object Association Association Association

1..* 1
n n
0..* 0..*

By default and will always be “1”

55
Aggregation
Composition
Faculty SalesOrder

(team- 1..5 1
teaching
is 0..* 1..*
possible)
CourseTeaching SalesOrderLineItem

56

You might also like