Chapter 11: Class Diagram Chapter 19 in Applying UML and Patterns Book.
Overview What is Class Diagram? The different between Domain Model and Design Model. How to build UML Class Diagram (Class, Attribute, Relationship).
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.
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
Generalization hierarchy
Generalization hierarchy with added detail
Domain Model (Conceptual Model) vs Domain Model (Conceptual Model) vs. Design Model Classes (Class Diagram) (Conceptual Model) (Class Diagram)
Example Design Class Diagrams (DCD)
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.
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.
Creating NextGen POS DCD Add method names for each class by analyzing the interaction diagrams.
Creating Methods from Sequence Diagrams 12 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)
Creating NextGen POS DCD Add type information to the attributes and methods.
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);
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);
Skeletal definition of Register Class
Collection Classes in Code
Adding Navigability & Dependency Relationships