From the course: Design Patterns: Creational

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

How the pattern works

How the pattern works

From the course: Design Patterns: Creational

Start my 1-month free trial

How the pattern works

- [Instructor] To see how Abstract Factory works let's take a look at the class diagram for the pattern from the Gang of Four catalog and then we'll see how the design might map to our example of UserRoles and interface functions. As you can see in this rather complex diagram, the client is composed with an abstract factory, much like in factory method. The choice of concrete factory decides which family of products the client gets. If FactoryOne is used, the client gets ProductA1 and B1. If FactoryTwo is used, the client gets ProductA2 and ProductB2. Notice that the client refers to the product interfaces for Product A and B. So it is not dependent on which family of concrete products is being used. If we decide the client should use a different family of products, all we have to do is switch out which factory the client is using to create the products and the new family of products is created for us. Here's how the…

Contents