460 likes | 1.23k Views
Object Diagrams. Address. Customer. Street: String city: String state: String zipCode: int. firstName: String Lastname: String id: int. Class diagram. getAddress(): Address. getCity(): String. :Customer. :Address. johnSmith :Customer. homeAddr : Address. Object diagram.
E N D
Object Diagrams Address Customer Street: String city: String state: String zipCode: int firstName: String Lastname: String id: int Class diagram getAddress(): Address getCity(): String :Customer :Address johnSmith :Customer homeAddr : Address Object diagram homeAddr :Address JohnSmith :Customer Street: String city: String state: String zipCode: int firstName: String Lastname: String id: int getAddress(): Address getCity(): String
Customer Address firstName: String Lastname: String id: int Street: String city: String state: String zipCode: int 1 Class diagram - homeAddr getAddress(): Address getCity(): String homeAddr : Address johnSmith :Customer Object diagram
Customer Address firstName: String Lastname: String id: int Street: String city: String state: String zipCode: int 1..2 Class diagram - addresses getAddress(): Address [1..2] getCity(): String homeAddr : Address johnSmith :Customer Object diagram officeAddr : Address
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
Video rental • Each customer can rent up to 10 video tapes. • Each video tape has its own ID.
Video rental • Each customer can rent up to 10 video tapes. • Each video tape has its own ID. Customer VideoTape tapesRented: VideoTape[0..10] - id: int - title: String - rented: boolean 1 0..10 isRented(): boolean rent(): void
Customer VideoTape tapesRented: VideoTape[0..10] - id: int - title: String - rented: boolean Class diagram 1 0..10 isRented(): boolean rent(): void : VideoTape a :Customer 00 :id “Spiderman” :title true : rented Object diagram : VideoTape 10 :id “Spiderman2” :title true : rented : VideoTape b :Customer 01 :id “Spiderman” :title true : rented
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.
Customer VideoTape tapesRented: VideoTape[0..10] - id: int - title: String - rented: boolean - rentalCost: double - directorName:String - numRental: int 1 0..10 Class diagram isRented(): boolean rent(): void : VideoTape a :Customer 00 :id “Spiderman” :title true : rented 1.00: rentalCost “…” : directorName 1: numRental Object diagram : VideoTape b :Customer 01 :id “Spiderman” :title true : rented 1.00: rentalCost “…” : directorName 10: numRental
How can we remove the redundancy? • Separate the properties of individual video tapes and video titles.
Title VideoTape - id: int - title: String - rentalCost: double - directorName:String … - tapeId: int - rented: boolean - numRental: int 1 0..* Class diagram isRented(): boolean rent(): void 0..10 Customer 1 : VideoTape a :Customer 00 :id true : rented 1: numRental : Title Object diagram 001 :id “Spiderman” :title 1.00: rentalCost “…” : directorName : VideoTape b :Customer 01 :id true : rented 10: numRental