Created
August 20, 2019 15:59
-
-
Save ronnylt/fc8a7264a232b0dd78725139b472acc9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package domain | |
// An Aggregate is a tree of object relations that protect business invariants (business rules). | |
// Concretely, an aggregates handle commands and have a state model encapsulated within it that allows | |
// it to implement the required command validation, thus upholding the invariants (business rules) of the aggregate. | |
// Aggregates are usually composed of several entities and values objects. | |
// The lifetimes of the components of an aggregate are bounded by the lifetime of the entire aggregate. | |
// Aggregate is abstract concept, it's just represented as an empty interface with no specific contract. | |
type Aggregate interface{} | |
// An AggregateRoot is the "top one" entity, which speaks for the whole aggregate and may delegates down to the rest. | |
// It is important because it is the one that the rest of the world communicates with. | |
// AggregateRoot is the common interface for all aggregate roots. | |
type AggregateRoot interface { | |
// It must be uniquely identifiable entity | |
Entity | |
} | |
// EventSourcedAggregateRoot is an aggregate root that records and exposes all the changes to the system as events. | |
type EventSourcedAggregateRoot interface { | |
AggregateRoot | |
// It must return recorded events | |
RecordedEvents() []Event | |
// It must allow to clear events | |
ClearEvents() | |
} | |
// ReconstitutableAggregateRoot is an aggregate root that can be reconstituted from the events. | |
// It has the ability to put the aggregate in any prior state by applying events to it | |
type ReconstitutableAggregateRoot interface { | |
EventSourcedAggregateRoot | |
// It must allow to apply events and reconstitute internal state from applied events | |
Apply(Event) error | |
} | |
// SerializableAggregateRoot is the common interface for aggregates that exposes an Snapshot of their internal encapsulated state. | |
type SerializableAggregateRoot interface { | |
EventSourcedAggregateRoot | |
// Snapshot is called whenever an instance needs to be serialized | |
Snapshot() interface{} | |
// WakeUp is called whenever an instance is reconstituted from a previously saved snapshot | |
WakeUp(interface{}) error | |
} | |
// Identity represents the identity values of entities. It's an interface because it can be any type. | |
type Identity interface{} | |
// Identifiable is the common interface for things that has identity and therefore are identifiable. | |
type Identifiable interface { | |
Identity() Identity | |
} | |
// An Entity is characterized by having an identity that's not tied to their attribute values. All attributes in an | |
// entity can change and it's still "the same" entity. Conversely, two entities might be equivalent in all their | |
// attributes, but will still be distinct. | |
type Entity interface { | |
Identifiable | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment