Domain Model Class Diagram N Snchez 1 Outline


























- Slides: 26

Domain Model Class Diagram N. Sánchez 1

Outline Overview of Class Diagrams Domain Model Class Diagram § Compare to ERDs § Instantiation of Objects § Associations • Association Classes • Generalization Hierarchy o • N. Sánchez How the Class Diagram would be used in Applications Dev. § Who will use our Class Diagram? § How will our Class Diagram be used? Inheritance Whole-Part Hierarchy o Aggregation o Composition 2

Overview of Class Diagrams are used to model classes and their associations with other classes. • UML Diagram • Object Oriented (OO) Diagram - used for OOAD, OOP/OOPL, OODB Domain Model Class Diagram Design Class Diagram § In Analysis Phase § In Design Phase § Model objects in the problem domain § Model software classes • “things” that need to be remembered Student id. Num {key} last. Name first. Name major birth. Date N. Sánchez Student -id. Num: int {key} -last. Name: string -first. Name: string -major: string -birth. Date: date +Student() +Student(id, ln, fn) +get. Last. Name(): string +set. Last. Name() +calc. Age(): int 3

ERD vs Domain Model Class Diagram ERD Domain Model Class Diagram Terminology N. Sánchez Terminology § Entity § Domain Class § Attribute § Relationship § Association § Cardinality § Multiplicity § Instance § Object (or instance) 4

Domain Classes § § Student Contain attributes id. Num {key} last. Name first. Name major hometown Used to Instantiate Objects • A term used in OO which means to create an object (i. e. instance) of a class. • “Cookie-cutter” analogy stu 1 stu 2 111 222 Smith Sue FIN Houston Doe MIS N. Sánchez John Dallas 5

Primary Keys Hey, where’s the Primary Key? § In OOP/OOPL: • § § Primary keys are not required because objects can be accessed by reference However, in Relational Databases • Primary keys are required! UML Notation: {key} • N. Sánchez Example from the textbook Thus, for your class project: § Add a primary key to all domain classes except: • subclasses • association classes sale. Id {key} 6

Association Types Regular Associations § N. Sánchez Class Diagrams have associations (i. e. relationships) similar to ERDs Learn to Model these: § Association Class § Generalization Hierarchy is-a § Whole-Part Association has-a 7

Association Class N. Sánchez 8

Association Class N. Sánchez Association Class § Same as the ERD’s associative entity § Resides only on a many-to-many § In UML, the notation is different: • Use a dashed line • Keep the M: M • Do not add a primary key. 9

Generalization Hierarchy an “is-a” association N. Sánchez 10

Generalization Hierarchy § § § N. Sánchez aka: Generalization/Specialization Hierarchy • Generalize – as we move • Specialize – as we move Superclass • Known as a: generalization, base, parent class • A class that is being inherited by another class (i. e. subclass) • e. g. _________________ Subclass • Known as a: specialization, derived, child class • A class that inherits from another class • A class that extends the superclass • e. g. _________________ It is an “is-a” association: § Read it from the _______. 11

Generalization Hierarchy In a Generalization Hierarchy Inheritance is in effect! § Inheritance - a feature of OO in which the objects of a __________ inherit the attributes from its __________ Recall that objects contain their attributes stu 1 111 Doe MIS N. Sánchez John Dallas How many attributes does: • an Online. Sale object have? ____ • an In. Store. Sale object have? ____ • a Telephone. Sale object have? ____ 12

Generalization Hierarchy • Attribute • How many superclasses are there? ____ • Car is a ________ to Sports. Car but a ________ of Motor. Vehicle. • Attribute • Attribute • How many attributes does a Sports. Car have? ____ • Attribute N. Sánchez • Attribute 13

Generalization Hierarchy: Abstract vs Concrete Abstract class § Notation: italicized § Designed to not be instantiated. • Concrete class § Notation: plain text § Designed to be instantiated. • N. Sánchez That is, we will not be creating objects of this type. That is, we will be creating objects of this type. • Which classes are Abstract? ________ • Which classes are Concrete? ________ • Are there any other types of Sales classes? Y / N • If this design is implemented: • Will the programmer be able to instantiate a Sale object? Y / N 14

Generalization Hierarchy: Abstract vs Concrete Approach 1 Approach 2 Which approach is better and why? ______ • Will we lose any information with this approach? Y / N N. Sánchez • If so, how can we fix this? _________________ 15

Generalization Hierarchy: Abstract vs Concrete • When would we design this model? N. Sánchez • When would we design this model? 16

Generalization Hierarchy: Abstract vs Concrete • Are there any mistakes in the identification of abstract and concrete classes? Y / N • If yes, what is the mistake? _____________ N. Sánchez 17

Generalization Hierarchy What are these IDs? N. Sánchez 18

Generalization Hierarchy You can create a generalization anywhere but you shouldn’t! Only do this under 1 of 2 situations: 1. _____________ 2. _____________ Is this diagram showing that: • An In. Store. Sale is-a Sale? Y / N • A Store is-a In. Store. Sale? Y / N N. Sánchez 19

Whole-Part Hierarchy a “has-a” association N. Sánchez 20

Whole-Part Hierarchy Whole part hierarchies § used to represent a “has-a” association § 2 Types: • Aggregation • Composition Aggregation § removable parts § “has-a” but parts can exist separately • N. Sánchez Aggregation e. g. computer & its parts 21

Whole-Part Hierarchy Composition § N. Sánchez Composition “has-a” but parts cannot exist separately • Parts are non-removable • Stronger! 22

Summary N. Sánchez 23

Summary • How many superclasses are there? ____ • How many subclasses are there? ____ Account Class • Superclass, subclass, or neither? _______ • Abstract or Concrete? ______ Savings & Checking Account • Superclass, subclass, or neither? _______ • Abstract or Concrete? ______ • # of attributes of a Checking Account object? ____ Transaction class • Superclass, subclass, or neither? _______ • Abstract or Concrete? ______ N. Sánchez 24

Summary • How many superclasses are there? ____ • How many subclasses are there? ____ • Is there an Association Class? Y / N • What does 0. . 2 mean? N. Sánchez 25

The role of Modeling in Applications Development Who will be using what we as Analysts have designed? Domain Model Class Diagram Student Class (C#) public class Student { //Fields public int Id. Num {get; set; } public string Last. Name {get; set; } public string First. Name {get; set; } public string Major {get; set; } public string Hometown {get; set; } Course course. ID {key} name desc credit. Hours Form Class (C#) } public class Form 1 { //Instantiate Student stu 1 = new Student(); //Methods. . . } //Populate stu 1. Id. Num = 111 stu 1. Last. Name = "Doe"; stu 1. First. Name = "John"; stu 1. Major = "MIS"; stu 1. Hometown = "Dallas"; stu 1 111 Doe John MIS Dallas Database 1. . 1 0. . * id. Num {key} last. Name first. Name major hometown Student Table Course. Sect Student 0. . * Course Table crn {key} sect. Num location time status Section Table Student Table Id. Num N. Sánchez Last. Name First. Name Major Hometown 111 Doe John MIS Dallas 222 Smith Sue FIN Houston 26