Skip to content

Small exercise to differentiate the concepts of aggregate, entity, and value object in PHP.

Notifications You must be signed in to change notification settings

DeGraciaMathieu/aggregate-entity-valueobject

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

aggregate-entity-valueobject

Small exercise to differentiate the concepts of aggregate, entity, and value object in PHP.

Architecture

qsdsqdqs

Aggregate

An aggregate represents a business concept (ex: budget). It is responsible for containing and ensuring the reliability of the entities it contains (ex: a budget contains transactions). It can also provide entry points to manipulate and interact with its entities (ex: retrieve the amount of transactions).

Entity

An entity represents a business concept, similar to aggregates, but on a smaller and individual scale. The values of an entity are always value objects (ex: Name, Amount ...) to protect against primitive obsession. An entity has methods to manipulate its properties, these intermediary methods are essential to avoid exposing the internal structure of the object and to respect the Law of Demeter.

Value object

A value object is a reusable class that encapsulates non-business logic. Its responsibility is to represent a meaningful characteristic and ensure the correctness and relevance of its value.

Usage

$budget = new App\Aggregators\Budget();

$budget->addTransaction(
    new App\Entities\Transaction(
        new App\ValuesObjects\Uuid('3a535f13-a832-49c1-9156-4dd67744c197'),
        new App\ValuesObjects\Name(''),
        new App\ValuesObjects\Amount(10),
    ),
);

$budget->addTransaction(
    new App\Entities\Transaction(
        new App\ValuesObjects\Uuid('a086e8a5-e016-4f84-b888-c918a70809e6'),
        new App\ValuesObjects\Name(''),
        new App\ValuesObjects\Amount(30),
    ),
);

$budget->amount();

About

Small exercise to differentiate the concepts of aggregate, entity, and value object in PHP.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published