intermediateAbstract Factory Pattern

What is the real cost of adding a new product to an existing Abstract Factory family, compared to adding a new family such as a new theme?

Adding a new product, say a Checkbox alongside Button and ScrollBar, means adding a new createCheckbox() method to the shared factory interface, and every existing concrete factory implementing that interface, WindowsFactory and MacFactory and any others, must now implement that new method too, or the code fails to compile. This is a real, non-trivial cost that grows with however many concrete factories already exist. Adding an entirely new family instead, a LinuxFactory say, costs nothing extra to existing factories at all: it is simply one new class implementing the existing interface, with zero changes required anywhere else. Abstract Factory is cheap to extend with new families and comparatively expensive to extend with new products, which is worth knowing before choosing it.

Ready to master this question?

Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.

Sign in to generate a response

Next Step

Continue to Java's standard library included java.util.Observer and java.util.Observable since version 1.0 — why were they deprecated?← Back to all Low-Level Design & Design Patterns questions