The domain of our first extension is very simple. The essential
concept of our domain is the “product”. All important properties
of a product and its behavior are defined in the model
MyVendor\StoreInventory\Domain\Model\Product which is stored
in a file with the name Product.php.
The name of the file corresponds to the name of the model.
The file itself is stored in the folder
EXT:store_inventory/Classes/Domain/Model/.

Tip

The class names must reflect the folder structure to ensure that class loading is working.
For example the class MyVendor\MyExtension\FirstFolder\SecondFolder\File should be in the folder
my_extension/Classes/FirstFolder/SecondFolder/File.php.
Pay attention to the corresponding upper casing of the folder names.

Let’s take a deeper look at the model \MyVendor\StoreInventory\Domain\Model\Product.

The model Product in our extension denotes the aggregate root and
represents an entity (as opposed to a ValueObject) and
should extend \TYPO3\CMS\Extbase\DomainObject\AbstractEntity.

The product properties are designed as properties $name,
$description and $quantity and protected (encapsulated)
against direct access from outside by using the keyword protected.
The property values can be set and/or read only by the corresponding getters and setters.

Tip

At a first view, the methods appear to be cumbersome for accessing
the class variables. However, they have several advantages:
The internals of processing can be added or changed at a later time,
without needing to make changes to the calling object.
Additionally, fire-grained access control is possible as for example the reading can be permitted,
without simultaneously allowing writing access.
Most modern IDEs are able to create getters and setters automatically.

The method __construct() serves to guarantee
a well defined state at the beginning of the life cycle of the object.
The properties of the product are set with their respectively default
values.