Chapter 9 Applying UML and Patterns -Craig Larman Domain Models Chapter 9 Applying UML and Patterns -Craig Larman
Introduction Remember: Use cases are not object-oriented requirement analysis , but they emphasize an activity view. A domain model is the most important and classic-model in Object Oriented Analysis
Domain model ? A domain model is a visual representation of conceptual classes (idea, thing or object) or real-situation objects in a domain. Make it easier to understand the key concepts and the stakeholders view. A UP domain model is a visualization of things in a real-situation domain of interests, not of software objects such as Java or C# classes. It is part of the Business Model artifact
Domain Model Relationships Business Model Domain Model Classes, attributes, associations Elaboration on some terms Use Case Model Domain Objects = conceptual classes Glossary Requirements Interaction Diagrams Design
Fig. 9.1 Example
Domain Model -UML Notation Illustrated using a set of class diagrams for which no operations are defined. It may contain: Domain Objects or Conceptual Classes Associations between conceptual classes Attributes of conceptual classes
A Domain Model is not a Software Artifact A Conceptual class: Sale Date Time
A Domain Model is not a Software Artifact Software Artifacts: Sale Date Time Print() Object responsibilities is not part of the domain model. (But to consider during Design) Avoid
Think of Conceptual Classes in terms of: Symbols – words or images Intensions – its definition (what does it represent) Extensions – the set of examples to which it applies. Note ; during each iteration, only objects in current scenarios are considered for addition to the domain model.
Symbol, intension and extension. All the examples of sales Fig 9.5
Question : Why create Domain model Question : Why create Domain model ? Answer : To take inspiration of real world domain to create software classes
Question : Why create Domain model Question : Why create Domain model ? Answer : To take inspiration of real world domain to create software classes
How to find these conceptual classes ?
Method1 : Identify Conceptual Classes by Category List: p 140-141 Common Candidates for classes include: Descriptions Roles Places Transactions Containers
Abstract nouns Rules Organizations Events Processes
Written Materials Catalogs Records Financial Instruments Services Systems
Method2: Conceptual Classes with Noun Phrase Identification Identify Nouns and Noun Phrases in textual descriptions of the domain. Fully dressed Use Cases, problem definition are good for this type of linguistic analysis. It’s not strictly a mechanical process: Words may be ambiguous Different phrases may represent the same concepts.
2. Cashier starts a new sale. 3. Cashier enters item identifier. Main Success Scenario (or Basic Flow): 1. Customer arrives at POS checkout with goods and/or services to purchase. 2. Cashier starts a new sale. 3. Cashier enters item identifier. 4. System records sale line item and presents item description, price, and running total. Price calculated from a set of price rules. Cashier repeats steps 3-4 until indicates done. 5. System presents total with taxes calculated. 6. Cashier tells Customer the total, and asks for payment. 7. Customer pays and System handles payment.
9. System presents receipt. 8. System logs completed sale and sends sale and payment information to the external accounting system (for accounting and commissions) and Inventory system (to update inventory). 9. System presents receipt. 10. Customer leaves with receipt and goods (if any). Extensions (or alternative Flows) 7a. Paying by cash: 1. Cashier enters the cash amount tendered. 2. System presents the balance due, and releases the cash drawer. 3. Cashier deposits cash tendered and returns balance in cash to Customer. 4. System records the cash payment.
Fig. 9.7 Remember : There is no such things as a correct list. Brainstorm what you consider noteworthy to be a candidate. But in general , different modelers will find similar lists.
When to model Specification/Description Conceptual Classes? Suppose all the items (ObjectBurgers) are sold out and then deleted. Someone ask you “”How much do ObjectBurgers cost ?
Example1: Fig. 9.9
When to model Specification/Description Conceptual Classes? A Class that records information about an item. Even if all Instances of the item are sold out, the description remains. It avoids duplication of recording the descriptive information with each instance of the item.
Example2 : Fig. 9.10
Association: Relationship between classes (more precisely, between instances of those classes). Fig. 9.11
Association: Relationship between classes (more precisely, between instances of those classes). Fig. 9.12
“many” ( 0 or more ) Multiplicity indicates how many instances can be validly associated with another instance, at a particular moment, rather than over a span of time. Example : monogamy Fig. 9.13
Fig. 9.14 : multiplicity values
Multiplicity communicates a domain constraint that will be reflected in software. How ? Fig. 9.15
Multiple Associations between two classes
Attributes A logical data value of an object. Imply a need to remember information. Sale needs a dateTime attributte Store needs a name and address Cashier needs an ID
Fig. 9.19
Fig. 9.20
Fig. 9.21 : Derived Attributes The quantity entered by the cashier may be recorded as an attribute “quantity” of the SaleLineItem class. However the quantity can be calculated from the actual multiplicity value of the association
Fig. 9.22 : Association or attribute Most attribute type should be “primitive” data type, such as: numbers and booleans. Attribute should not be a complex domain concept(Sale , Airport) CurrentRegister is of type “Register”, so expressed with an association
Fig. 9.23 A destination airport is not a string, it is a complex thing that occupies many square kilometers of space. So “Airport” should be related to “Flight” via an association , not with attribute
Should the “ItemID” class be shown as a separate class Should the “ItemID” class be shown as a separate class ? It depends on how the domain model is being used. ItemID is a new type with its own attributes Fig. 9.24 ItemID are primitive types(number, boolean, character, string…etc)
Fig. 9.26 : Modeling quantities and Units Price is a quantity with associated units. How should we model them?
A Common Mistake when modeling the domain- Classes or Attributes? Rule: If we do not think of a thing as a number or text in the real world, then it is probably a conceptual class. If it takes up space, then it is likely a conceptual class. Examples: Is a store an attribute of a Sale ? Is a destination an attribute of a flight ?
Assignment 1: Mobile phone system Problem definition Consider a system for a simple mobile phone. The phone can receive calls and call other phone numbers. It offers its owner a personal phone book to store namse and phone numbers. The phone book can be dynamically updated. The phone also manages a complete log of all incoming and outgoing calls and helps its owner to remember unanswered calls.
assignment Find classes and attributes for the mobile phone system.
assignment Find classes and attributes for the library system. For help see the videos from requirements to classes.
How to create a domain model Find the conceptual classes Draw them as classes in a UML class diagram Add associations and attributes
But remember There is no such thing as a single correct domainmodel. All models are approximations of the domain we are attempting to understand. We incrementally evolve a domain model over several iterations on attempts to capture all possible conceptual classes and relationsships.