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.
HealthPointis a value in this domain to respond to health statusActoris an entity in this domain to respond to an object which can take actionPlayerandMonsteris 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.
Attackercan apply damage toDefenderin the contextDefendercan receive damage and update its data (HealthPoint) in the context
In the
Attackerrole the damage is applied toDefenderonly 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.
NewbitTrainingcontext describes a#attack_byaction that can leadAttackerto apply damage toDefender
It is similar to
Domain Serviceto describe one or more entities to co-work together.