- Mastering Microservices with Java
- Sourabh Sharma
- 241字
- 2021-07-02 13:03:37
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:

The factory may use one of the object-oriented programming patterns, such as the factory or abstract factory pattern, for object creation.
- Java語言程序設計
- Java從入門到精通(第4版)
- Wireshark Network Security
- 數據結構習題精解(C語言實現+微課視頻)
- 深入理解Java7:核心技術與最佳實踐
- Visual Basic程序設計實驗指導(第4版)
- Unity 5.x By Example
- Vue.js 2 Web Development Projects
- Django實戰:Python Web典型模塊與項目開發
- Hands-On JavaScript for Python Developers
- Clojure for Java Developers
- SpringBoot從零開始學(視頻教學版)
- NGUI for Unity
- Python機器學習開發實戰
- MATLAB計算機視覺實戰