Professional Documents
Culture Documents
Head
1
Body
Back
Chair
2 1 4
Arm Seat Leg
Example I
Example II
05.5. Aggregation
Example – Aggregation
Bed
1
1
Cupboard
Example – Aggregation
Garden Plant
*
Example I
Furniture is not an intrinsic part of room
Furniture can be shifted to another room, and so can exist independent of a
particular room
Example II
A plant is not an intrinsic part of a garden
It can be planted in some other garden, and so can exist independent of a particular
garden
http://www.codeproject.com/KB/cpp/oopuml.aspx
Lecture No.06
Examples
Child class also includes characteristics of its base class.
Shape
color
vertices
move
setColor
draw
Circle Triangle
Line
radius angle
length
draw
draw draw
computeArea
getLength computeArea
All the three derived class are behaviourally compatible with base class.
File
size
…
open
print
…
Wherever the file class is it can be replaced by any of its child classes.
06.2. Polymorphism
It is also essential component of object oriented modeling (paradigm).
In general, polymorphism refers to existence of different forms of a single entity. For
example, both Diamond and Coal are different forms of Carbon.
Example – Polymorphism
draw
View Shape
draw
Shape class hierarchy shape is base class and there are three child classes line circle ,
triangle. View send draw method to shape class and draw is called according to the
nature of actual object present.
print
Editor File
Editor sends message print to file class and print is called based on the actual child
object of file class message is same and appropriate execution will be done.
draw Shape
View
draw
Problem Statement
Develop a graphic editor that can draw different geometric shapes such as line, circle
and triangle. User can select, move or rotate a shape. To do so, editor provides user
with a menu listing different commands. Individual shapes can be grouped together
and can behave as a single shape.
Identify Classes
Extract nouns in the problem statement
Develop a graphic editor that can draw different geometric shapes such as line,
circle and triangle. User can select, move or rotate a shape. To do so, editor provides
user with a menu listing different commands. Individual shapes can be grouped
together and can behave as a single shape.
“Individual shapes can be grouped together and can behave as a single shape”
View – graphic editor must have a display area to show the shapes. We made this
object using domain knowledge.
• Shape
• Line
• Circle
• Triangle
• Menu
• Group
• View
Shape G roup
Line Menu
Circle
View
Triangle
Finding Associations:
Identify Associations
• Line
i. Color
ii. Vertices
iii. Length
• Circle
i. Color
ii. Vertices
iii. Radius
• Triangle