1 / 29

The OO Solution

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. Objects. State of Michigan.

tybalt
Télécharger la présentation

The OO Solution

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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 CSE870: UML Classes

  2. Objects State of Michigan Drivers License VISA J. Q. Public A-123456 03-12-63 J. Q. Public 123 4567 887766 998 CSE870: UML Classes

  3. Attributes and Operations Person objects Attributes name age height weight Operations move change-job abstracts to Card objects Card class Attributes height width id-number Operations issue change State of Michigan Drivers License VISA J. Q. Public A-123456 03-12-63 J. Q. Public 123 4567 887766 998 Person class

  4. 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 CSE870: UML Classes

  5. The Class Diagrams CSE870: UML Classes

  6. 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 • Person • Drivers license CSE870: UML Classes

  7. Classes • Describes a group of objects with similar properties (attributes), common behavior (operations), common relationships to other classes, and common semantics • Person • J. Q. Public • Joe Smith • D. Q. Public • Card • Credit card • Drivers license • Teller card CSE870: UML Classes

  8. Class Diagrams D. Q. Public: Person J. Q. Public: Person age= 32 age= 35 Class diagram Instance diagram Person age: integer Class with attributes Objects with values Objects have an identity Do not explicitly list object identifiers SSN OK! CSE870: UML Classes

  9. Examples CSE870: UML Classes

  10. Transformation that can be applied to or performed by an object May have arguments Operations and Methods CSE870: UML Classes

  11. Object Notation - Summary CSE870: UML Classes

  12. Associations • Conceptual connection between classes • A credit card is issued-by a bank • A person works-for a company Issued-by Credit Card Bank Class diagrams Works-for Person Company J.Q. Public: Person Michigan State Univ: Company Instance diagram Works-for Age=35 CSE870: UML Classes

  13. Associations are Bi-directional • There is no direction implied in an association (Rumbaugh - OMT) Country name City name Has-capital Person name Drivers-license lic.-number: integer Is-issued CSE870: UML Classes

  14. Associations Have Direction • Unified adds a direction indicator • Inconsistently used Country name City name Has-capital Person name Drivers-license lic.-number: integer Is-issued CSE870: UML Classes

  15. Multiplicity Person Credit-card Holds card-number: integer name: String Holds Person Credit-card 0..* card-number: integer name: String • One object can be related to many objects through the same association One person holds one credit card One person can hold zero or more credit cards (* stands for many) CSE870: UML Classes

  16. Multiplicity (Cont.) Card456:Credit-Card Card123:Credit-Card Card789:Credit-Card card-number= 111 222 333 card-number= 123 456 789 card-number= 444 555 666 :JQPublic:Person :DQPublic:Person name= D. Q. Public age=32 name= J. Q. Public age=35 One person can hold zero or more credit cards (0..*) Each card has zero or one holder (0..1) Person Credit-card 8 Holds 0..1 0..* card-number: integer name: String age: integer Holds Holds CSE870: UML Classes

  17. Multiplicity (Cont.) Credit-Card 3 Authorized 123 456 789 Person 8 Holds J. Q. Public 35 8 Holds 3 Authorized Credit-Card 111 222 333 3 Authorized Person D. Q. Public 8 Holds 32 Credit-Card 3 Authorized 111 222 333 • One person can hold zero or more credit cards (0..*) • Each card has one holder (no indication or 1) • Each card has one or more authorized users (1..*) • One person can be authorized to use zero or more cards Explicit enumeration is also possible (2, 3, 2..5, etc.) 8 Holds 1 0..* Credit-card Person 3 Authorized card-number: integer name: String 1..* 0..* Note: hexagons should be rectangles to represent instances CSE870: UML Classes

  18. Higher order associations Language Project C++ Compiler Person J. Q. Public 35 Language Project LISP TicTacToe • Ternary association • Project, language, person • Seldom needed (and should be avoided) Note: hexagons should be rectangles to represent instances CSE870: UML Classes

  19. Link Attributes How to represent salary and job title? Use a link attribute! • Associations can have properties the same way objects have properties CSE870: UML Classes

  20. Folding Link Attributes Why not this? Salary and job title are properties of the job not the person Person name: String Company age: integer 0..* Works-for SSN: integer name: String address: String address: String salary: integer job-title: String Person Company name: String 0..* Works-for 0..* age: integer name: String In this case, a link attribute is the only solution SSN: integer address: String address: String salary: integer job-title: String CSE870: UML Classes

  21. Role Names Person Company name: String 0..* 0..* Works-for boss age: integer name: String employee employer 0..1 SSN: integer address: String address: String 0..* worker Manages salary: integer job-title: String • Attach names to the ends of an association to clarify its meaning CSE870: UML Classes

  22. Aggregation Aggregation symbol • 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) CSE870: UML Classes

  23. Aggregation (Cont.) • Often used in parts explosion CSE870: UML Classes

  24. The is-a association 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) Generalization and Inheritance Card height: integer width: integer thickness: integer id-number: integer issue() revoke() Drivers License ID Card Credit Card issued: date credit-limit: integer class: vehicle expires: date issued: date issued: date expires: date expire() validate() expire() CSE870: UML Classes

  25. Example Owns Pilot Works-for City Airline Based-In 0..* name name name 0..* license Located-In Offers 1..* Certified-On Pilots 0..* 0..* Airport 0..* Plane 0..* Departs Flight name 0..* model serial # date Used-For Arrives heat() hours flown flight # clean() 0..* cancel() heat() delay() refuel() clean() 30..* Seat 0..* Passenger location name Confirmed-for reserve()

  26. 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…… 0..* 0..* Company Division Department Works-for 0..* Person CSE870: UML Classes

  27. 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 Aggregation Versus Inheritance 4 Wheel Body Car Gearbox Engine Minivan Compact Jeep Roll Bar CSE870: UML Classes

  28. Recursive Aggregates Program 0..* Block Compound Simple Statement Statement • A recursive aggregate contains (directly or indirectly) an instance of the same kind of aggregate CSE870: UML Classes

  29. Classes Name Attributes Operations Associations Roles Link attributes Aggregation Inheritance Object Modeling Summary CSE870: UML Classes

More Related