190 likes | 206 Vues
Explore the fundamentals of UML class diagrams, relationships, and attributes. Learn how to build them to represent system structures and behavior effectively. Dive into designing NextGen POS with detailed steps and sequencing examples.
E N D
Chapter 11: Class Diagram Chapter 19 in Applying UML and Patterns Book.
What is Class Diagram? • The different between Domain Model and Design Model. • How to build UML Class Diagram (Class, Attribute, Relationship). Overview
A classdiagramshows the existence of classes and theirrelationships in the logical view of a system. • UML modeling elements in classdiagrams: • Classes and their structure and behavior. • Association, aggregation, dependency, and inheritance relationships. • Multiplicity and navigation indicators. • Role names. What is Class Diagram ?
Dependency • Dependency means “One class uses the other” • A dependency relationship indicates that a change in oneclass may effect the dependentclass, but not necessarily the reverse. • A dependency relationship is often used to show that a methodhasobject of a class as arguments. Basic Class Dependent Class Depends on
(Conceptual Model) (Class Diagram) Domain Model (Conceptual Model) vs. Design Model Classes (Class Diagram)
Identify all the classes participating in the software solution. Do this byanalyzing the interactiondiagrams. Draw them in a class diagram. • Duplicate (i.e. copy) the attributes from the associated concepts in the Domain Model. Creating NextGen POS DCD
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 typeinformation to the attributes and methods Add navigability and associations. Collection classes in code.
Addmethodnames for each class by analyzing the interaction diagrams. Creating NextGen POS DCD
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)
Add typeinformationto the attributes and methods. Creating NextGen POS DCD
Question: Register – addLineItem Method • The addLineItem sequence diagram will be used to illustrate the Java definition of the addLineItemmethod. • 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 (itemIDitemID, 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(itemiditemid, int quantity) { productSpecification spec = catalog.getSpecification(itemID); sale.makeLineItem(spec, quantity);} Public productSpecificationgetSpecification(itemID){ spec := find(itemID); Return spec; } Public void makeLineItem (productSpecification spec, int quantity){ sli= create(spec, quantity); //new in java add(sli); }