domain models illustrates meaningful conceptual classes in problem domain, and used during analysis.
represents real world problems, not software components
software-oriented class diagrams are represented later, during the design.
features of domain models:
domain classes: represent a real-world object (customer, agent), business objects (Contact, Invoice), business events (Sale, Hire, Charge, Payment). usually a noun in the requirements.
attributes: represent property in the domain class.
associations: represent relationship between domain classes, the association has a role indicating the details of the relationship.
additional rules: complex rules can be attached to domain classes.
concept name is always a noun phrase, eg. KeyChecker.
we start from the periphery of the system by assigning concepts that handle the interactions between the system and outer world aka. between actors and the system.
each actor has at least one boundary object (concept) that converts data to internal objects when receiving data from the actor, or converting internal objects to data accepted by the actor when sending data to the actor.
organizations has persons-of-contact (POC) to handle communications with other organizations. => Controller object (concept)
during analysis: objects only used to represent possible system state, no effort to describe the system’s behavior.
during design: the behavior of the objects can be discussed.
UML does not have designated symbols for domain concepts, so it is usual to adopt the symbols that are used for software classes.
associations describe who (concepts) needs to work together and why (not how they work together).
usually, associations belongs to the same package
attributes: refers to the concept attributes, where each concepts may need an internal state, params ..etc. eg. Lock model needs internal state indicating open, locked
when an attribute may go into multiple different concepts, put it in the controller.
2.5.4 Contracts: Preconditions and Postconditions¶
contracts:
express important conditions about the attributes in the domain model.
include facts about forming or breaking relations between concepts.
define time-points of where objects should should be created, then destroyed.
is assigning responsibilities to the software objects acquired in domain analysis.
concepts are converted to classes (one concept can be converted to one or more classes).
Dynamic object interactions can be represented using UML sequence diagrams.
Controller participates in every interaction with the actor.
good software designs are characterized by:
short communication chains between objects.
balanced workload across objects
low degree of connectivity (associations) among objects
design heuristics:
used to achieve optimal design.
bottom-up (inductive): applying design principles and design patterns locally at the level of objects (micro-level design).
top-down (deductive): applying architectural styles globally at the system level, then decomposing system into sub-systems (macro-level design)
2.6.1 Design Principles for Assigning Responsibilities¶
A popular approach to micro-level design is known as responsibility-driven design (RDD).
types of responsibility objects can have:
knowing: memorizing data or references (properties of objects/classes).
doing: performing computation (methods).
communicating: communicate with other objects (invoking methods of other objects).
Important design principles at the local, objects level include:
Expert Doer principle
High Cohesion principle
Low coupling principle
As seen, design principles are not always in agreement with each other. Enforcing any particular design principle to the extreme would lead to absurd designs.
it is left out to the developer judgment to mix the design principles in a way that serves the optimal design.
it is essential to document the the judgment process and the reasoning behind favouring one design principle over the others, and document the alternative solutions considered even if they haven’t been used.
each module should have only limited knowledge about other modules
in other words: do not talk to strangers
a.getB().getC().foo();// violates the law of Demetera.getB().invokeFoo();// better, a knows about b only.// the logic of getting c, and calling c.foo() extracted to a method in B.
class diagram notation is standardized by UML, while domain models are not.
The number of operations in a class correlates with the amount of responsibility handled by the class
The number of methods in each class should be similar (balanced), if you find classes with strange number of methods (eg. all classes have 3-5 methods, but one have 20) then there may be undiscovered classes or responsibility miss-assignments
all classes must be traceable back to domain concepts.
a domain concept can be represented by one (or more) software classes.
all domain concepts must be traceable back to class(es), if one domain concept has no corresponding class, then:
the requirement has low priority, no need to think about it now.