Class: Hanami::Entity
- Inherits:
-
Object
- Object
- Hanami::Entity
- Defined in:
- gems/gems/hanami-model-1.3.2/lib/hanami/entity.rb,
gems/gems/hanami-model-1.3.2/lib/hanami/entity/schema.rb
Overview
An object that is defined by its identity. See “Domain Driven Design” by Eric Evans.
An entity is the core of an application, where the part of the domain logic is implemented. It’s a small, cohesive object that expresses coherent and meaningful behaviors.
It deals with one and only one responsibility that is pertinent to the domain of the application, without caring about details such as persistence or validations.
This simplicity of design allows developers to focus on behaviors, or message passing if you will, which is the quintessence of Object Oriented Programming.
If we expand the code above in pure Ruby, it would be:
Hanami::Model ships Hanami::Entity
for developers’ convenience.
Hanami::Model depends on a narrow and well-defined interface for an Entity - #id
, #id=
, #initialize(attributes={})
.If your object implements that interface then that object can be used as an Entity in the Hanami::Model framework.
However, we suggest to implement this interface by including Hanami::Entity
, in case that future versions of the framework will expand it.
See Dependency Inversion Principle for more on interfaces.