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

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 already 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 requestor.

The requestor 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.

主站蜘蛛池模板: 墨脱县| 隆尧县| 泰顺县| 黑龙江省| 康马县| 浪卡子县| 泗水县| 天津市| 汨罗市| 应用必备| 阳信县| 沙雅县| 怀化市| 商南县| 朔州市| 黄石市| 都匀市| 山阳县| 阜平县| 定日县| 观塘区| 五台县| 探索| 辽宁省| 霍林郭勒市| 襄樊市| 大新县| 武定县| 府谷县| 安仁县| 海门市| 富裕县| 镇雄县| 临桂县| 岳池县| 淳安县| 青川县| 北票市| 梁河县| 西华县| 布尔津县|