Under Domain-Driven Design, we are trying to "Model" the real world to the virtual world. However, it cannot clearly describe the context/interaction with the domain.
The raw data is a "number" or "string" and cannot explain the meaning in specifying the domain. Therefore we have to create a "value object" to assign the domain meaning and use "entity" to compose mapping a real-world object.
HealthPoint
is a value in this domain to respond to health statusActor
is an entity in this domain to respond to an object which can take actionPlayer
andMonster
is an entities but have different "roles" in the "NewbieTraining" context
The role means can take specify an action in the context. The Ruby mixin the module and include specify the action to the class.
Attacker
can apply damage toDefender
in the contextDefender
can receive damage and update its data (HealthPoint
) in the context
In the
Attacker
role the damage is applied toDefender
only which means we only check it isDefender
(or duck-typing to userespond_to(:damage)
)
The context is a set of actions about roles in this context.
NewbitTraining
context describes a#attack_by
action that can leadAttacker
to apply damage toDefender
It is similar to
Domain Service
to describe one or more entities to co-work together.