CONCEPTUAL DESIGN UML CLASS DIAGRAM RELATIONSHIPS 214 A



































- Slides: 35

CONCEPTUAL DESIGN: UML CLASS DIAGRAM RELATIONSHIPS 214

A Simplified Object-Oriented Systems Analysis & Conceptual Design Methodology Activities 1. Identify the information system’s purpose 2. Identify the information system’s actors and features 3. Identify Use Cases and create a Use Case Diagram 4. Identify Objects and their Classes and create a Class Diagram 5. Create Interaction/Scenario Diagrams 6. Create Detail Logic for Operations 7. Repeat activities 1 -6 as required to refine the “blueprints” 215

Objects • Objects have three responsibilities: 4 What they know about themselves – (e. g. , Attributes) 4 What they do – (e. g. , Operations) 4 What they know about other objects – (e. g. , Relationships) 216

Defining Class A CLASS is a template (specification, blueprint) for a collection of objects that share a common set of attributes and operations. Class Health. Club. Member attributes operations Objects 217

• Relationships A RELATIONSHIP is what a class or an object knows about another class or object. Four Types 4 Generalization (Class-to-Class) (Superclass/Subclass) • Inheritance • Ex: Person - Faculty. Person, Student. Person, Staff. . . • Ex: Modes. Of. Travel - Airplane, Train, Auto, Cycle, Boat. . . 4 [Object] Associations • Faculty. Information - Course. Information • Student. Information - Course. Information 4 [Object] Aggregations & Composition (Whole-Part) • Assembly - Parts • Group - Members • Container - Contents 218

• Relationships Exist to: 1) show relationships 2) enforce integrity 3) help produce results In this example: University. Course 1 Student. Information 0, m 1 Student. In. Course 0, m • Removal of a University Course should also remove Students that are in the Course but not Student Information. • Removal of a Student should also remove the Courses that the Student is in but not the University Course. • Removal of a Student in a Course should not affect either University Course or Student Information. 219

UML Class Diagram Notation 1 of 2 Class attributes { operations { Member member. Number first. Name last. Name telephone address city etc. . . check. Out. Video check. In. Video buy. Item etc. . . Expanded view of a Class into its three sections: Top: Class Name Middle: attributes Bottom: operations 220

UML Class Diagram Notation 2 of 2 Class Generalization Relationship Object Aggregation Association Object Association n n Object Composition Association 1 1. . * 0. . * Will always be “ 1” 221

Class Diagram Relationships n Class • Generalization n Object • Association • Aggregation • Composition 222

Generalization (Class-to-Class) (superclass – subclass; supertype – subtype) n A Generalization follows a “is a” or “is a kind of” heuristic from a specialization class to the generalization class. (e. g. , student “is a” person, video “is a kind of” inventory). n Common attributes, operations and relationships are located in the generalization class and are inherited by the specialization classes n Unique attributes, operations and relationships are located in the specialization classes. n Inherited attributes and operations may be overridden or enhanced in the specialization class depending on programming language support. n Inherited operations in the specialization classes may be polymorphic. n Only use when objects do NOT “transmute” (add, copy, delete) n Multiple inheritance is allowed in the UML but can complicate the class model’s understanding and implementation (e. g. , C++ supports but Java and Smalltalk do not). 223

Generalization Example <<abstract>> Role attributes operations Others: • Transactions • Things • Places • Etc. . . Staff Faculty Student Visitor attributes operations Note: <<abstract>> = no objects 224

Poor Generalization Example (violates the “is a” or “is a kind of” heuristic) Person attributes operations Leg Head attributes operations Arm 225

Generalization Inheritance Generalization Common a 1 a 2 a 3 o 1 o 2 o 3 One-Way Inheritance from the Generalization to the Specialization Unique a 4 a 5 a 6 o 4 o 5 o 6 (a = attribute; o = operation) Generalization a 1 a 2 a 3 o 1 o 2 o 3 Specialization a 1 a 2 a 3 a 4 a 5 a 6 o 1 o 2 o 3 o 4 o 5 o 6 226

Generalization - Multiple Inheritance Generalization 2 Generalization 1 a 2 a 3 a 2 a 4 a 5 o 3 o 4 o 5 o 1 o 2 o 3 Specialization a 6 a 7 a 8 inherited attributes o 1 o 2 (which one? ) o 3 o 4 o 5 o 6 o 7 o 8 a 1 a 2 (which one? ) a 3 a 4 a 5 inherited operations 227

UML Generalization Note Useful text Supertype discriminator Subtype 1 Subtype 2 Note: Supertype = Superclass; Subtype = Subclass 228

Generalization - Multiple Classification Discriminator Female Doctor role <<abstract>> Person Male Gender {complete} Nurse patient Physicaltherapist #1 Patient #2 #3 229

Rational Rose Class Diagram Example 230

Associations n n Relationships between instances (objects) of classes Conceptual: • associations can have two roles (bi-directional): – source --> target – target --> source • roles have multiplicity (e. g. , cardinality, constraints) • To restrict navigation to one direction only, an arrowhead is used to indicate the navigation direction n No inheritance as in generalizations 231

Object Association Relationship Patterns b) Object Aggregation Associations Class A attributes operations x x x Class B attributes operations a) Object Associations c) Object Composition Associations (y may not be “ 1”) y Part 1 attributes operations x x Part 2 attributes operations Part 1 attributes operations x Class B attributes operations Class A attributes operations Whole attributes operations Part. N attributes operations Whole attributes operations 1 1 y Part 2 attributes operations 1 y Part. N attributes operations 232

Associations role B Class A Class B role A Example: Company Employee Employer Person 233

Multiplicities 1 0. . * 0. . 1 m. . n Class exactly one Class many (zero or more) Class optional (zero or one) Class numerically specified Example: Course 0. . * 1 Course. Offering 234

Aggregation & Composition • Aggregation (shared aggregation): • is a specialized form of ASSOCIATION in which a whole is related to its part(s). • is known as a “part of” or containment relationship and follows the “has a” heuristic • three ways to think about aggregations: • whole-parts • container-contents • group-members • Composition (composite aggregation): • is a stronger version of AGGREGATION • the “part(s)” may belong to only ONE whole • the part(s) are usually expected to “live” and “die” with the whole (“cascading delete”) • Aggregation vs. Composition vs. Association? ? ? 235

Aggregation Faculty (team-teaching is possible) 1. . * Composition Sales. Order 1 0. . * 1. . * Course. Teaching Sales. Order. Line. Item (another: assembly --> part) (another: hand --> finger) 236

Composition 4 Composition is often used in place of Generalization (inheritance) to avoid “transmuting” (adding, copying, and deleting of objects) Person {abstract} Person 1 0. . 1 Faculty Student Faculty. Role 1 0. . 1 Student. Role Faculty. Student Note: Attributes may need to be considered to more-fully understand 237

Association, Aggregation and Composition Template/Pattern Whole Example Whole w 1 w 2 w w 3 4 0. . * Part p p 4 p 3 p 2 1 p 5 p 6 (association, aggregation & composition look the same) 238

Multiplicity Example #1 Whole 1 5 2 Part 1 • One Whole is associated with 5 Part 1 • One Part 1 is associated with 1 Whole W P P P 3 Part. N • One Whole is associated with 2 Part. N • One Part. N is associated with 3 Whole P P W W W P W W 239

Multiplicity Example #2 Class 1 min. max. 1 1. . n 2. . 5 0. . * Class 2 1. . n C 1 C 2 C 2 C 2 etc. . . 1 C 2 C 1 Class 3 * C 1 C 3 C 3 C 3 2. . 5 C 3 C 1 C 1 C 1 etc. . . 240

Multiplicity Example #3 Faculty. Information 1 0. . * 1 Student. Information 1 1 0. . * 1. . * 0. . * Committee. Assign Degree. Held 0. . * Course. Teach Course. Completed 0. . * Club. Member 241

“many-to-many” multiplicity Student. Information attributes operations Course. Information 0. . * attributes operations 0. . * Becomes either Student. Information Course. Information Student. Information attributes operations 0. . * Course. Information 0. . * attributes operations 1 1 0. . * Student. Course. Information Semester. Taken Grade. Earned operations Attributes that represent the “union” of the two classes are located in this “association” class. Student. Course. Information Semester. Taken Grade. Earned operations 242

Reflexive Association Relationships Objects within the same class have a relationship with each other. Course 0. . * is pre-requisite for 0. . * has pre-requisite of 243

Video Store – UML Class Diagram 1 1 Inventory Rental. Item Sale. Item Video Concession. Item Game Transaction 0. . * 1 Employee Sale. Transaction 1 0. . * Rental. Transaction 0. . * 1 0. . 1 1 Member 1. . * Sale. Rental. Line. Item 0. . * 1 VCR Store. Location Suplier 1 0. . * Purchase. Order 1 1. . * Purchase. Order. Line. Item 0. . * 244

245

246

247

QUITTING TIME 248