5 Building a crafting system with the Abstract Factory pattern

 

This chapter covers

  • Pros and cons of the Abstract Factory pattern
  • Working with families of related but independent products
  • Working with families of related and dependent products
  • Exploring different Abstract Factory variations

In the last chapter, we built an item production system using the Factory Method design pattern, Unity GameObjects, and reflection. In this chapter, we’ll focus on the Abstract Factory pattern for creating factories OF factories. While the Factory Method helped us hide the creation process of a single product or type of product, Abstract Factory lets us black box the creation process behind families, or related groups, of products. As we noted in the last chapter, choosing between these two patterns largely depends on the scale and depth of your product hierarchies, but also their relationships to one another.

Like the Factory Method, there are a few varieties the Abstract Factory pattern can take depending on what kind of product families you’re creating and what, if any, relationships need to exist between them. Also like the Factory Method pattern in the last chapter, the interfaces or abstract classes give our calling code, or client, the flexibility to not specify the concrete classes of products being created. The added level of abstraction lets the client treat every object factory the same way, regardless of what factory is being used or what family of objects is being instantiated.

5.1 Breaking down the Abstract Factory pattern

 
 
 

5.1.1 Diagramming the pattern

 
 
 

5.2 Creating related but independent products

 
 
 
 

5.2.1 Scripting product interfaces

 
 
 

5.2.2 Adding concrete products

 

5.2.3 Creating abstract and concrete factory classes

 
 

5.2.4 Writing a client class using only interfaces

 
 
 

5.3 Creating related and dependent products

 
 

5.3.1 Writing dependent product abstract classes

 
 
 
 

5.3.2 Creating concrete products

 
 
 
 

5.3.3 Adding abstract and concrete factory classes

 

5.3.4 Updating the client

 
 

5.4 Optional factory variations

 
 
 

5.4.1 Parameterized factories

 
 
 
 

5.4.2 Creating a factory of factories

 
 
 

5.5 Summary

 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest