Domain Models are used to visually represent important domain concepts and relationships between them.
Domain Models help clarify and communicate important domain specific concepts and are used during the requirements gathering and designing phase.
Domain modeling is the activity of expressing related domain concepts into a domain model.
UML
UnifiedModellingLanguage
Requirements analysis determines
external behaviour
Domain modelling determines
internal behaviour
Domain
A sphere of knowledge particular to the problem being solved
Domain expert
A person expert in the domain
Dependency
The loosest form of relationship. A class in some way depends on another
Association
A class "uses" another class in some way. When undirected, it is not yet clear in what direction dependency occurs.
Directed Association
Refines association by indicating which class has knowledge of the other
Aggregation
A class contains another class. Note that the diamond it at the end with the containing class
Composition
Like aggregation, but the contained class is integral to the containing class. The contained class cannot exist outside of the container
What kind of relationship does Aggregation use?
It uses a "has-a" relationship where the part can exist without container
What kind of relationship does Composition use?
It uses a "is-composed-of" relationship where part cannot live without container
What kind of relationship does Inheritance use?
It uses a "is-a-kind-of" relationship
should it be an attribute or a class?
If a concept is not representable by a number or a string, most likely it is a class.
Example of an attribute
a lab mark can be represented by a number
Example of a class
a student cannot be represented by a number or a string
Defensive programming
Tries to address unforeseen circumstances, in order to ensure the continuing functionality of the software element.
It makes the software behave in a predictable manner despite unexpected inputs or user actions
Defensive programming example
Design by Contract
At the design time, responsibilities are clearly assigned to different software elements, clearly documented and enforced during the development using unit testing and/or language support
Pros of Design by Contract
clear demarcation of responsibilities helps prevent redundant checks, resulting in simpler code and easier maintenance
Every software element should define a specification (or a contract) that governs its interaction with the rest of the software components.
Pre-condition
A pre-condition is a condition or predicate that must always be true just prior to the execution of some section of code
Post-condition
A post-condition is a condition or predicate that must always be true just after the execution of some section of code
Invariant
what does the contract maintain? Some values must satisfy constraints, before and after the execution (say of the method). For example: a value of mark remains between zero and 100
Benefits of Design by Contract (DbC)
Do not need to do error checking for conditions that not satisfy the preconditions!
Benefits of Design by Contract (DbC)
Prevents redundant validation tasks.
Benefits of Design by Contract (DbC)
Given the preconditions are satisfied, clients can expect the specified post-conditions.
Benefits of Design by Contract
Responsibilities are clearly assigned, this helps in locating errors and resulting in easier code maintenance
Benefits of Design by Contract
Helps in cleaner and faster development.
Post-conditions are sometimes tested using guards or assertions within the code itself, and some languages have specific syntactic constructions for testing .
In Design by Contract, the properties declared by the post-condition(s) are assured, provided the software element is called in a state in which its pre-condition(s) were true.
An implementation or redefinition (method overriding) of an inherited method must comply with the inherited contract for the method
v Preconditions may be weakened (relaxed) in a subclass, but it must comply with the inherited contract
Post-conditions may be strengthened (more restricted) in a subclass, but it must comply with the inherited contract.
An implementation or redefinition (overridden method) may increase the benefits it provides to the client, but not decrease it.
Class Invariant
The class invariant constrains the state (i.e. values of certain variables) stored in the object.
Class invariants are inherited, that means, "the invariants of all the parents of a class apply to the class itself.”