Download presentation
Presentation is loading. Please wait.
1
1 Object Diagrams Customer firstName: String Lastname: String id: int getAddress(): Address :Customer johnSmith :Customer JohnSmith :Customer firstName: String Lastname: String id: int getAddress(): Address Address Street: String city: String state: String zipCode: int getCity(): String Class diagram Object diagram :Address homeAddr : Address Street: String city: String state: String zipCode: int getCity(): String
2
2 Customer firstName: String Lastname: String id: int getAddress(): Address Address Street: String city: String state: String zipCode: int getCity(): String 1 - homeAddr Class diagram Object diagram johnSmith :Customer homeAddr : Address
3
3 Customer firstName: String Lastname: String id: int getAddress(): Address [1..2] Address Street: String city: String state: String zipCode: int getCity(): String 1..2 - addresses Class diagram Object diagram johnSmith :Customer homeAddr : Address officeAddr : Address
4
4 What can be classes? Traditionally… –Nouns in a specification Each class’s instances/objects should have its own identity, behavior and state. Physical/logical objects Identifier for each physical/logical object People, organizations Person’s and organization’s roles Places and locations Transactions made among classes Events
5
5 Video rental –Each customer can rent up to 10 video tapes. –Each video tape has its own ID.
6
6 Video rental –Each customer can rent up to 10 video tapes. –Each video tape has its own ID. Customer tapesRented: VideoTape[0..10] VideoTape - id: int - title: String - rented: boolean isRented(): boolean rent(): void 0..101
7
7 Customer tapesRented: VideoTape[0..10] VideoTape - id: int - title: String - rented: boolean isRented(): boolean rent(): void 0..101 Object diagram a :Customer : VideoTape 00 :id “Spiderman” :title true : rented 10 :id “Spiderman2” :title true : rented Class diagram b :Customer : VideoTape 01 :id “Spiderman” :title true : rented
8
8 What if… –you need to maintain individual video’s properties? Rental cost, # of rentals, production company, distribution company, distribution year, director’s name, rating (R-rated, PG13, etc.), etc.
9
9 Customer tapesRented: VideoTape[0..10] VideoTape - id: int - title: String - rented: boolean - rentalCost: double - directorName:String - numRental: int isRented(): boolean rent(): void 0..101 a :Customer : VideoTape 00 :id “Spiderman” :title true : rented 1.00: rentalCost “…” : directorName 1: numRental b :Customer : VideoTape 01 :id “Spiderman” :title true : rented 1.00: rentalCost “…” : directorName 10: numRental Object diagram Class diagram
10
10 How can we remove the redundancy?
11
11 How can we remove the redundancy? Separate the properties of individual video tapes and video titles.
12
12 Customer VideoTape - tapeId: int - rented: boolean - numRental: int isRented(): boolean rent(): void 0..*1 Title - id: int - title: String - rentalCost: double - directorName:String … 1 0..10 a :Customer : VideoTape 00 :id true : rented 1: numRental b :Customer : VideoTape 01 :id true : rented 10: numRental Object diagram Class diagram : Title 001 :id “Spiderman” :title 1.00: rentalCost “…” : directorName
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.