1 Chapter 11 Class Diagram Chapter 19 in





















- Slides: 21
1 Chapter 11: Class Diagram Chapter 19 in Applying UML and Patterns Book.
2 Overview è What is Class Diagram? è The different between Domain Model and Design Model. è How to build UML Class Diagram (Class, Attribute, Relationship).
3 What is Class Diagram ? è A class diagram shows the existence of classes and their relationships in the logical view of a system. è UML modeling elements in class diagrams: 1. Classes and their structure and behavior. 2. Association, aggregation, dependency, and inheritance relationships. 3. Multiplicity and navigation indicators. 4. Role names.
Dependency • Dependency means “One class uses the other” • A dependency relationship indicates that a change in one class may effect the dependent class, but not necessarily the reverse. • A dependency relationship is often used to show that a method has object of a class as arguments. Dependent Class Depends on Basic Class 4
Composition expresses a relationship among instances of related classes. It is a specific kind of Whole-Part relationship. Class W Automobile Class P 1 Class P 2 Engine Transmission Part Classes 5
Aggregation: Aggregation expresses a relationship among instances of related classes. It is a specific kind of Container-Containee relationship. Container Class C Bag AGGREGATION Class E 1 Class E 2 Apples Milk Containee Classes 6
Aggregation vs. Composition is really a strong form of aggregation • components have only one owner • components cannot exist independent of their owner • components live or die with their owner • e. g. Each car has an engine that can not be shared with other cars. Aggregations may form "part of" the aggregate, but may not be essential to it. They may also exist independent of the aggregate. • e. g. Apples may exist independent of the bag. 7
Generalization hierarchy 8
Generalization hierarchy with added detail 9
10 Domain Model (Conceptual Model) vs. Design Model Classes (Class Diagram) (Conceptual Model) (Class Diagram)
11 Example Design Class Diagrams (DCD)
12 Creating Next. Gen POS DCD è Identify all the classes participating in the software solution. Do this by analyzing the interaction diagrams. Draw them in a class diagram. è Duplicate (i. e. copy) the attributes from the associated concepts in the Domain Model.
Steps: Design to Code Main goal is to define Design Class Diagram with Attributes and Methods 1. Defining Concepts 2. Adding Reference Attributes, attributes. 3. Creating methods from interaction diagrams: Find & Add methods. 4. Add type information to the attributes and methods 5. Add navigability and associations. 6. Collection classes in code. 13
14 Creating Next. Gen POS DCD è Add method names for each class by analyzing the interaction diagrams.
15 Creating Methods from Sequence Diagrams : Register : Product. Catalogue Sale : Sales. Line. Item : Product. Spec Constructor 1. Spec=get. Specification(item. ID) 1. 1 Spec=Find(item. ID) 2. make. Line. Item(spec, quantity) 2. 1 sli= Create(spec, quantity) 2. 1. 1 Sub=get. Sub. Total(item. ID) 2. 2 Add(sli) 15
16 Creating Next. Gen POS DCD è Add type information to the attributes and methods.
Question: Register – add. Line. Item Method è The add. Line. Item sequence diagram will be used to illustrate the Java definition of the add. Line. Item method. è Which class add. Line. Item should belong to? è The add. Line. Item message is sent to a Register instance, therefore the add. Line. Item method is defined in class Register. public void add. Line. Item (item. ID, int quantity); è Message 1. A get. Specification message is sent to the product. Catalog to retrieve a product. Specification spec = catalog. get. Specification (item. ID); è Message 2. The make. Line. Item message is sent to the Sale. sale. make. Line. Item (spec, quantity); 17
Register - add. Line. Item Method Public void addlineitem(itemid, int quantity) { product. Specification spec = catalog. get. Specification(item. ID); sale. make. Line. Item(spec, quantity); } Public product. Specification spec : = find(item. ID); Return spec; } get. Specification(item. ID){ Public void make. Line. Item (product. Specification spec, int quantity){ sli= create(spec, quantity); //new in java add(sli); } 18
Skeletal definition of Register Class 19
Collection Classes in Code 20
21 Adding Navigability & Dependency Relationships





















