Professional Documents
Culture Documents
Ecture 2: Class Modelling: - Class Representation in UML - Relationship - Class Diagram
Ecture 2: Class Modelling: - Class Representation in UML - Relationship - Class Diagram
Community
chest card
Property Deeds
Banker
Hotel
Monopoly
Board
Supply Money
Dices
Chance card Tokens
Class
Association
TitleDeed
Token 1 1 Player
+selectedTokenpicks +player +player 1
1
+titleDeed Role
has
Generalization buy
+ownProperty +property
PropertyOwner 1
0..*
Composition
Aggregation Property
develop
+buildings 1..*
builds on
Building Street Utility RailwayStation
1..*
Player
-name: String
-selectedToken: Token
-totalSupplyMoney: Float = 0
+setName(playerName: String): void
+getName(): String
+setSelectedToken(Token: token): void
+getToken(): Token
+setSupplyMoney(money: Float): void
+getSupplyMoney(): Float
+updateSupplyMoney(amount: Float): void
- totalSupplyMoney : float = 0
Private
Player
-name: String
-selectedToken: Token
-totalSupplyMoney: Float = 0
+setName(playerName: String): void
+getName(): String
+setSelectedToken(Token: token): void
+getToken(): Token
+setSupplyMoney(money: Float): void
+getSupplyMoney(): Float
1
DITP 3113 OBJECT ORIENTED PROGRAMMING SEM I 13/14 7
ASSOCIATION
• Association represents conceptual relationships between classes.
associations
Interpreted as :-
owning
Player Token
Interpreted as :-
1 1
Interpreted as :-
One player object can picks only one token object.
Player buy
Property
1 0..*
Interpreted as :-
One player object buys no property or more property.
role role
1 1
Player
Token
-name: String
-name: String
-selectedToken: Token
-currentSpace: Integer
-totalSupplyMoney: Float = 0
object
Player
-name: String
-selectedToken: Token
-totalSupplyMoney: Float = 0
-ownProperty: Property[0..*]
2
DITP 3113 OBJECT ORIENTED PROGRAMMING SEM I 13/14 7
GENERALIZATION
• A relationship between general object to more specialized object.
• Realization of inheritance
• General object -> super class, base class
• Specialized object -> sub class, derived class
• is-a relationship
– is-kind-of relationship
Player
Super class
is-a relationship
Interpreted as :-
•PropertyOwner is a kind of Player.
•PropertyOwner can develop property.
•PropertyOwner inherits all public (package and protected)
attributes and methods from Player.
•Every PropertyOwner is a Player.
Player
-name: String
-selectedToken: Token
-totalSupplyMoney: Float = 0 Interpreted as :-
+setName(playerName: String): void
+getName(): String
+setSelectedToken(Token: token): void •Player can buy property.
+getToken(): Token
+setSupplyMoney(money: Float): void •When Player buy property, he
+getSupplyMoney(): Float
+updateSupplyMoney(amount: Float): void is a PropertyOwner.
•Only PropertyOwner can
develop House or Hotel on the
street.
•Only PropertyOwner can
PropertyOwner
mortgage house, hotel, utilities
-house: House[1..*]
-hotel: Integer[0..1] and/railroad.
-utilities: Utility[0..*]
-railroad: Railroad[0..*] •PropertyOwner is-a Player.
+developHouse(noOfHouses: Integer): void
+developHotel(): void
+mortgageHouse(street: Street): Float
+mortgageHotel(street: Street): Float
+mortgageUtilities(): Float
+mortgageRailroad(): Float
3
DITP 3113 OBJECT ORIENTED PROGRAMMING SEM I 13/14 1
Variants of Relationships
• Relationships is not limited to directional association and
generalization.
3
2
DITP 3113 OBJECT ORIENTED PROGRAMMING SEM I 13/14
Advanced Relationship
• Therefore, a richer relationship is needed to describe the
model precisely.
3
3
DITP 3113 OBJECT ORIENTED PROGRAMMING SEM I 13/14
Part and Whole
• Some object is made up from many objects.
• In this case there are part-of object and whole-object.
• For example, a Car is made of Window, Door, Tire, Engine
etc.
3
4
DITP 3113 OBJECT ORIENTED PROGRAMMING SEM I 13/14
AGGREGATION
• is-part-of relationship (or is-made-of)
• Represent by solid line and hollow diamond-end
• Part-object and whole-object relationship
Owner Station
-name: String 1..* -location: String
-capital: float
-stationOwned: Station[1..*] -stationOwned +setLocation(String location): void
+getLocation(): String
+setName(String name): void owns
+getName(): String
+setCapital(float capital): boolean
+getCapital(): float
Whole-object Aggregation
Part-object
Property
-Name: String
-Price: Float Interpreted as :-
-Group: String
+DisplayProperty() Player buy a Property and the
+property
TitleDeed is given to the player.
1
When PropertyOwner mortgage the Property
has to the bank, the TitleDeed is given to the
Bank.
+titleDeed 1
Queue
-player: Player[0..*] Player
Interpreted as :-
The Player is visible to push() method. Thus, this is
some kind of dependency.
3
9
DITP 3113 OBJECT ORIENTED PROGRAMMING SEM I 13/14
END OF LECTURE 2