Skip to Content
Patterns, Principles, and Practices of Domain-Driven Design
book

Patterns, Principles, and Practices of Domain-Driven Design

by Scott Millett, Nick Tune
May 2015
Intermediate to advanced
792 pages
22h 32m
English
Wrox
Content preview from Patterns, Principles, and Practices of Domain-Driven Design

20 Factories

WHAT’S IN THIS CHAPTER?

  • How factories separate use from construction
  • Applying factory methods to aggregates
  • Using a factory method for reconstruction
  • Knowing when to use a factory

Wrox.com Code Downloads for This Chapter

The wrox.com code downloads for this chapter are found at www.wrox.com/go/domaindrivendesign on the Download Code tab. The code is in the Chapter 20 download and individually named according to the names throughout the chapter.

How do you create, persist, and retrieve domain objects while maintaining a domain model that is not distracted by technical concerns? The life cycle of complex domain objects may need coordination to begin and when being persisted. Ensuring invariants are met on creation is achieved through the utilization of the Gang of Four factory pattern.

The Role of a Factory

Aggregates, entities, and value objects can become complex when you’re creating a domain model for large and rich domains. If intimate knowledge is required to ensure valid instances of a dependent object are created, it can cloud the expressiveness of the domain. The knowledge of other objects’ invariants breaks the Single Responsibility Principle (SRP). It is recommended that you separate use from construction and explicitly encapsulate creation logic within a factory object if it is complex or if it can be expressed better. Object creation is not a domain concern, but it does live within the domain layer of an application. You will rarely talk about factories ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Unit Testing Principles, Practices, and Patterns

Unit Testing Principles, Practices, and Patterns

Vladimir Khorikov
Design Patterns: Elements of Reusable Object-Oriented Software

Design Patterns: Elements of Reusable Object-Oriented Software

Erich Gamma, Richard Helm, Ralph Johnson, John Vlissides
Head First Design Patterns, 2nd Edition

Head First Design Patterns, 2nd Edition

Eric Freeman, Elisabeth Robson

Publisher Resources

ISBN: 9781118714706Purchase book