Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 11: Class Diagram

Similar presentations


Presentation on theme: "Chapter 11: Class Diagram"— Presentation transcript:

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: Classes and their structure and behavior. Association, aggregation, dependency, and inheritance relationships. Multiplicity and navigation indicators. Role names.

4 Dependency 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. Basic Class Dependent Class Depends on

5 Composition Composition expresses a relationship among instances of related classes. It is a specific kind of Whole-Part relationship. Class W Class P1 Class P2 Part Classes Automobile Engine Transmission

6 Aggregation Aggregation: expresses a relationship among instances
of related classes. It is a specific kind of Container-Containee relationship. Container Class Class C Bag AGGREGATION Class E1 Class E2 Apples Milk Containee Classes

7 Aggregation vs. Composition
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.

8 Generalization hierarchy

9 Generalization hierarchy with added detail

10 Domain Model (Conceptual Model) vs
Domain Model (Conceptual Model) vs. Design Model Classes (Class Diagram) (Conceptual Model) (Class Diagram)

11 Example Design Class Diagrams (DCD)

12 Creating NextGen 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.

13 Steps: Design to Code Main goal is to define Design Class Diagram with Attributes and Methods Defining Concepts Adding Reference Attributes, attributes. Creating methods from interaction diagrams: Find & Add methods. Add type information to the attributes and methods Add navigability and associations. Collection classes in code.

14 Creating NextGen POS DCD
Add method names for each class by analyzing the interaction diagrams.

15 Creating Methods from Sequence Diagrams
15 Creating Methods from Sequence Diagrams :Register :ProductCatalogue Sale :SalesLineItem :ProductSpec Constructor 1. Spec=getSpecification(itemID) 1.1 Spec=Find(itemID) 2. makeLineItem(spec,quantity) 2.1 sli= Create(spec,quantity) 2.1.1 Sub=getSubTotal(itemID) 2.2 Add(sli)

16 Creating NextGen POS DCD
Add type information to the attributes and methods.

17 Question: Register – addLineItem Method
The addLineItem sequence diagram will be used to illustrate the Java definition of the addLineItem method. Which class addLineItem should belong to? The addLineItem message is sent to a Register instance, therefore the addLineItem method is defined in class Register. public void addLineItem (itemID itemID, int quantity); Message 1. A getSpecification message is sent to the productCatalog to retrieve a productSpecification. productSpecification spec = catalog.getSpecification (itemID); Message 2. The makeLineItem message is sent to the Sale. sale.makeLineItem (spec, quantity);

18 Register - addLineItem Method
Public void addlineitem(itemid itemid, int quantity) { productSpecification spec = catalog.getSpecification(itemID); sale.makeLineItem(spec, quantity); } Public productSpecification getSpecification(itemID){ spec := find(itemID); Return spec; } Public void makeLineItem (productSpecification spec, int quantity){ sli= create(spec, quantity); //new in java add(sli);

19 Skeletal definition of Register Class

20 Collection Classes in Code

21 Adding Navigability & Dependency Relationships


Download ppt "Chapter 11: Class Diagram"

Similar presentations


Ads by Google