Objects Jan date of birth: 1955/02/02 address 9 9 UML St position: Manager Savings Account 1287 Greg: date of birth: 1970/01/01 opened:199703/03 ddress: 75 Object Di Margaret: date of birth: 1980/03/03 Mortgage Account 29865 address: 150 C++ Rd position: Teller opened:200008/12 property: 75 Object Dr. Transaction 487. amount: 200.00 time:200109/0114:30 Instant Teller 876 location: Java valley cafe www.lloseng.com O Lethbridge/Laganiere 2001 Chapter 2: Review of object Orientation
© Lethbridge/Laganière 2001 Chapter 2: Review of Object Orientation 6 Objects Margaret: date of birth: 1980/03/03 position: Teller Transaction 487: amount: 200.00 time: 2001/09/01 14:30 Greg: date of birth: 1970/01/01 address: 75 Object Dr. Mortgage Account 29865: balance: 198760.00 opened: 2000/08/12 property: 75 Object Dr. Instant Teller 876: location: Java Valley Cafe Savings Account 12876: balance: 1976.32 opened: 1997/03/03 Jane: date of birth: 1955/02/02 position: Manager address: 99 UML St. address: 150 C++ Rd
Classes A class Is a unit of abstraction in an object oriented(Oo) rogram Represents similar objects -Its instances Is a kind of software module -Describes its instances'structure(properties) -Contains methods to implement their behaviour www.lloseng.com O Lethbridge/Laganiere 2001 Chapter 2: Review of object Orientation
© Lethbridge/Laganière 2001 Chapter 2: Review of Object Orientation 7 Classes A class: • Is a unit of abstraction in an object oriented (OO) program • Represents similar objects —Its instances • Is a kind of software module —Describes its instances’ structure (properties) —Contains methods to implement their behaviour
Is Something a class or an Instance? Something should be a class if it could have instances Something should be an instance if it is clearly a single member of the set defined by a class Film Class: instances are individual films Reel of film: Class: instances are physical reels Film reel with serial number sw19876 Instance of reeloffilm Science fiction Instance of the class Genre Science fiction film · Class: instances include‘ Star Wars Showing of Star Wars'in the phoenix cinema at 7p.m Instance of ShowingofFilm www.lloseng.com O Lethbridge/Laganiere 2001 Chapter 2: Review of object Orientation 8
© Lethbridge/Laganière 2001 Chapter 2: Review of Object Orientation 8 Is Something a Class or an Instance? • Something should be a classif it could have instances • Something should be an instance if it is clearly a singlemember of the set defined by a class Film • Class; instances are individual films. Reel of Film: • Class; instances are physical reels Film reel with serialnumber SW19876 • Instance of ReelOfFilm Science Fiction • Instance of the class Genre. Science FictionFilm • Class; instancesinclude ‘Star Wars’ Showing of ‘Star Wars’in the Phoenix Cinema at 7 p.m.: • Instance of ShowingOfFilm
Naming classes Use capital letters e.g. BankAccount not bankAccount Singular nouns Use the right level of generality E. g Municipality, not city Make sure the name has only one meaning - E.g. bus' has several meanings www.lloseng.com O Lethbridge/Laganiere 2001 Chapter 2: Review of object Orientation
© Lethbridge/Laganière 2001 Chapter 2: Review of Object Orientation 9 Naming classes • Use capital letters —E.g. BankAccount not bankAccount • Use singular nouns • Use the right level of generality —E.g. Municipality, not City • Make sure the name has only one meaning —E.g. ‘bus’ has several meanings
2.3 Instance variables Variables defined inside a class corresponding to data present in each instance · Attributes Simple data - E.g. name, dateOfBirth · Associations -Relationships to other important classes -E.g. supervisor, coursesTaken More on these in Chapter 5 www.lloseng.com O Lethbridge/Laganiere 2001 Chapter 2: Review of object Orientation
© Lethbridge/Laganière 2001 Chapter 2: Review of Object Orientation 10 2.3 Instance Variables Variables defined inside a class corresponding to data present in each instance • Attributes —Simple data —E.g. name, dateOfBirth • Associations —Relationships to other important classes —E.g. supervisor, coursesTaken —More on these in Chapter 5