- Mastering Microservices with Java 9(Second Edition)
- Sourabh Sharma
- 241字
- 2021-07-02 21:54:50
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.
- 構(gòu)建移動(dòng)網(wǎng)站與APP:HTML 5移動(dòng)開發(fā)入門與實(shí)戰(zhàn)(跨平臺移動(dòng)開發(fā)叢書)
- React Native Cookbook
- SQL for Data Analytics
- Dependency Injection in .NET Core 2.0
- PHP網(wǎng)絡(luò)編程學(xué)習(xí)筆記
- 利用Python進(jìn)行數(shù)據(jù)分析(原書第3版)
- Getting Started with Hazelcast(Second Edition)
- Terraform:多云、混合云環(huán)境下實(shí)現(xiàn)基礎(chǔ)設(shè)施即代碼(第2版)
- SSM開發(fā)實(shí)戰(zhàn)教程(Spring+Spring MVC+MyBatis)
- Python3.5從零開始學(xué)
- Julia 1.0 Programming Complete Reference Guide
- Raspberry Pi Robotic Blueprints
- Laravel Application Development Blueprints
- 監(jiān)控的藝術(shù):云原生時(shí)代的監(jiān)控框架
- Node.js實(shí)戰(zhàn):分布式系統(tǒng)中的后端服務(wù)開發(fā)