C870: Cheng The OO Solution The OO model closely resembles the problem domain Base your model on the objects in the problem domain Iteratively refine the high-level model until you have an implementation Attempt to avoid big conceptual jumps during the development process C870: UML Classes 1 Objects State of Michigan Drivers License J. Q. Public A-123456 03-12-63 VISA J. Q. Public 123 4567 887766 998 C870: UML Classes C870: Advanced Software Engineering (Cheng) 2 1
C870: Cheng objects State of Michigan Drivers License J. Q. Public A-123456 03-12-63 Attributes and Operations Card objects VISA abstracts to J. Q. Public 123 4567 887766 998 class Attributes age height weight Operations move change-job Card class Attributes height width id-number Operations issue change C870: UML Classes 3 Characteristics of Objects Identity Discrete and distinguishable entities Classification Abstract entities with the same structure (attributes) and behavior (operations) into classes Polymorphism The same operation may behave differently on different classes Inheritance Sharing of attributes and operations based on a hierarchical relationship C870: UML Classes 4 C870: Advanced Software Engineering (Cheng) 2
C870: Cheng The Class Diagrams C870: UML Classes 5 Objects Something that makes sense in the application context (application domain) J.Q. Public Joe s Homework Assignment 1 J. Q. Public s drivers license All objects have identity and are distinguishable NOT objects Drivers license C870: UML Classes 6 C870: Advanced Software Engineering (Cheng) 3
C870: Cheng Classes Describes a group of objects with: similar properties (attributes), common behavior (operations), common relationships to other classes, and common semantics J. Q. Public Joe Smith D. Q. Public Card Credit card Drivers license Teller card C870: UML Classes 7 Class Diagrams Class diagram Instance diagram D. Q. Public: J. Q. Public: age: integer age= 32 age= 35 Class with attributes Objects with values Objects have an identity Do not explicitly list object identifiers SSN OK! C870: UML Classes 8 C870: Advanced Software Engineering (Cheng) 4
C870: Cheng Examples C870: UML Classes 9 Operations and Methods Transformation that can be applied to or performed by an object May have arguments C870: UML Classes C870: Advanced Software Engineering (Cheng) 10 5
C870: Cheng Object Notation - Summary C870: UML Classes 11 Associations Conceptual connection between classes A credit card is issued-by a bank A person works-for a company Credit Card Issued-by Works-for J.Q. Public: Age=35 Bank Class diagrams Company Michigan State Univ: Works-for Company C870: UML Classes C870: Advanced Software Engineering (Cheng) Instance diagram 12 6
C870: Cheng Associations are Bi-directional There is no direction implied in an association (Rumbaugh - OMT) Country Has-capital City Is-issued Drivers-license lic.-number: integer C870: UML Classes 13 Associations Can Have Direction Unified adds a direction indicator Inconsistently used Country Has-capital City Is-issued Drivers-license lic.-number: integer C870: UML Classes 14 C870: Advanced Software Engineering (Cheng) 7
C870: Cheng Multiplicity One person holds one credit card Holds Credit-card card-number: integer One object can be related to many objects through the same association One person can hold zero or more credit cards Holds Credit-card card-number: integer C870: UML Classes 15 Multiplicity (Cont.) One person can hold zero or more credit cards () Each card has zero or one holder (0..1) age: integer 0..1 Holds Credit-card card-number: integer :JQPublic: = J. Q. Public age=35 Holds Holds Card789:Credit-Card card-number= 123 456 789 Card123:Credit-Card card-number= 111 222 333 :DQPublic: = D. Q. Public age=32 Card456:Credit-Card card-number= 444 555 666 C870: UML Classes 16 C870: Advanced Software Engineering (Cheng) 8
C870: Cheng Higher order associations Ternary association Project, language, person Seldom needed (and should be avoided) Language 1..* 1..* 1..* Project C++ :Language Compiler: Project Instance of ternary association J. Q. Public: Age=35 LISP:Language TicTacToe:Project C870: UML Classes 18 Link Attributes Associations can have properties the same way objects have properties age: integer SSN: integer Works-for Company How to represent salary and job title? age: integer SSN: integer Works-for Company Use a link attribute! salary: integer job-title: String C870: UML Classes 19 C870: Advanced Software Engineering (Cheng) 9
C870: Cheng Folding Link Attributes Why not this? age: integer SSN: integer salary: integer job-title: String Works-for Company Salary and job title are properties of the job not the person age: integer SSN: integer Works-for salary: integer job-title: String Company In this case, a link attribute is the only solution C870: UML Classes 20 Role Names Attach s to the ends of an association to clarify its meaning boss 0..1 Manages age: integer SSN: integer worker Works-for employee salary: integer job-title: String employer Company C870: UML Classes 21 C870: Advanced Software Engineering (Cheng) 10
C870: Cheng Aggregation A special association, the is-part-of association A sentence is part of a paragraph (a paragraph consists of sentences) A paragraph is part of a document (a document consists of paragraphs) Document Paragraph Sentence Aggregation symbol C870: UML Classes 22 Aggregation (Cont.) Often used in parts explosion Car 4 Wheel Body Gearbox Engine 1..* 1..* Door Hood Trunk Piston Valve Crankshaft C870: UML Classes 23 C870: Advanced Software Engineering (Cheng) 11
C870: Cheng Generalization and Inheritance The is-a association Card Cards have many properties in common Generalize the common properties to a separate class, the base-card Let all cards inherit from this class, all cards is-a base-card (plus possibly something more) Drivers License class: vehicle issued: date expires: date height: integer width: integer thickness: integer id-number: integer issue() revoke() ID Card issued: date expires: date expire() Credit Card credit-limit: integer issued: date validate() expire() C870: UML Classes 24 Example Owns City Based-In Airline Works-for Pilot license Located-In Offers Pilots 1..* Certified-On Airport heat() clean() Departs Arrives Flight date flight # cancel() delay() Used-For Plane model serial # hours flown heat() refuel() clean() 3 Passenger Confirmed-for Seat location reserve() C870: UML Classes 25 C870: Advanced Software Engineering (Cheng) 12
C870: Cheng Aggregation Versus Association Can you use the phrase is-part-of or is-made-of Are operations automatically applied to the parts (for example, move) - aggregation Not clear what it should be Company Division Department Works-for C870: UML Classes 26 Aggregation Versus Inheritance Do not confuse the is-a relation (inheritance) with the is-part-of relation (aggregation) Use inheritance for special cases of a general concept Use aggregation for parts explosion Car Minivan Compact Jeep Roll Bar 4 Wheel Body Gearbox Engine C870: UML Classes 27 C870: Advanced Software Engineering (Cheng) 13
C870: Cheng Recursive Aggregates A recursive aggregate contains (directly or indirectly) an instance of the same kind of aggregate Program Block Compound Statement Simple Statement C870: UML Classes 28 Class diagram Metamodel I Eclipse.org C 435: Software Engineering C870: Advanced Software Engineering (Cheng) 14
C870: Cheng Class diagram Metamodel II Science direct C 435: Software Engineering Use Case Metamodel I uu: use case association relationship _i: includes _e: extends _g: generalization aa: actor relationship Image: Science Direct: ``Visual Modeling for Software Intensive Systems, Kooper et al, 2006. C 435: Software Engineering C870: Advanced Software Engineering (Cheng) 15
C870: Cheng Use Case Metamodel II C 435: Software Engineering Image: Jot.fm Meta Model Architecture M3 M2 M3: language for describing meta-models (MOF: Meta Object Facility) M2: meta model for a given modeling language M1 M1: class diagram M0 M0: instance of class diagram C870: UML Classes 34 C870: Advanced Software Engineering (Cheng) 16
C870: Cheng Interesting/Fun Metamodels Facebook: http://upload.wikimedia.org/wikipedia/co mmons/c/c6/facebook_metamodel_re presented_in_uml_notation_v01.jpg C870: UML Classes 35 C870: UML Classes 36 C870: Advanced Software Engineering (Cheng) 17
C870: Cheng Object Modeling Summary Classes Name Attributes Operations Associations Roles Link attributes Aggregation Inheritance C870: UML Classes 37 C870: Advanced Software Engineering (Cheng) 18