https://github.com/degraciamathieu/aggregate-entity-valueobject
Small exercise to differentiate the concepts of aggregate, entity, and value object in PHP.
https://github.com/degraciamathieu/aggregate-entity-valueobject
aggregate clean-architecture entity php value-object
Last synced: 11 months ago
JSON representation
Small exercise to differentiate the concepts of aggregate, entity, and value object in PHP.
- Host: GitHub
- URL: https://github.com/degraciamathieu/aggregate-entity-valueobject
- Owner: DeGraciaMathieu
- Created: 2024-04-04T14:33:23.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2024-04-05T06:33:29.000Z (almost 2 years ago)
- Last Synced: 2025-03-27T04:41:37.010Z (11 months ago)
- Topics: aggregate, clean-architecture, entity, php, value-object
- Language: PHP
- Homepage:
- Size: 22.5 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# aggregate-entity-valueobject
Small exercise to differentiate the concepts of aggregate, entity, and value object in PHP.
## Architecture

### 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
```php
$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();
```
