What it is good for?

As with all factories, the details of object creation are hidden. The abstract factory design pattern is particularly useful when we want to expose families of objects (for example, database connectors). The clients then become decoupled from the concrete classes. This pattern is commonly shown as an example in different UI toolkits, where elements differ for different operating systems. It is also quite testable because we can provide mocks instead of an actual factory to the clients.

Even though the incompatibility problem that we mentioned previously is still present here, it is somewhat harder to encounter now. This is mainly because here, the client will actually just pass one single factory as a parameter, and in ...

Get Scala Design Patterns - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.