官术网_书友最值得收藏!

Factory

A factory is required when a simple constructor is not enough to create the object. It helps to create complex objects, or an aggregate that involves the creation of other related objects.

A factory is also a part of the life cycle of domain objects, as it is responsible for creating them. Factories and repositories are in some way related to each other, as both refer to domain objects. The factory refers to newly created objects, whereas the repository returns the pre-existing objects either from the memory, or from external storage.

Let's see how control flows, by using a user creation process application. Let's say that a user signs up with a username, user1. This user creation first interacts with the factory, which creates the name user1 and then caches it in the domain using the repository, which also stores it in the storage for persistence.

When the same user logs in again, the call moves to the repository for a reference. This uses the storage to load the reference and pass it to the requester.

The requester may then use this user1 object to book the table in a specified restaurant, and at a specified time. These values are passed as parameters, and a table booking record is created in storage using the repository:

Repository object flow

The factory may use one of the object-oriented programming patterns, such as the factory or abstract factory pattern, for object creation.

主站蜘蛛池模板: 虎林市| 宁河县| 依兰县| 商河县| 山阴县| 来宾市| 江都市| 永川市| 喀喇沁旗| 中山市| 保定市| 汉沽区| 政和县| 龙陵县| 磐安县| 峨眉山市| 古浪县| 蓬莱市| 色达县| 临泽县| 铅山县| 揭阳市| 罗山县| 泰宁县| 岢岚县| 类乌齐县| 扶绥县| 南京市| 故城县| 靖西县| 克东县| 洪雅县| 册亨县| 东平县| 仪征市| 从江县| 五常市| 广汉市| 敖汉旗| 漯河市| 介休市|