How does Abstract Factory promote loose coupling between components?
Abstract Factory promotes loose coupling between components because it fully isolates client code from the concrete classes it works with.
1. Separating the client from concrete implementations
The client knows only the abstract factory interface (GUIFactory), not the concrete classes (WinFactory, MacFactory).
It accesses the factory through a common interface:
GUIFactory factory = new MacFactory();
Button button = factory.createButton();The client does not know or care which exact object will be created: a WindowsButton or a MacButton. This reduces the dependency between components.
2. Depending on abstractions, not implementations
The code interacts with product interfaces (Button, Checkbox), not their concrete implementations.
If you replace MacFactory with WinFactory, the system keeps working without changes.
3. Flexible swapping of product families
You can swap one product family for another simply by passing a new factory, without rewriting the logic. This is achieved through the Dependency Inversion Principle: high-level code depends on abstractions, not on details.
4. Localizing changes
If you need to change the implementation of a product (for example, how a button is drawn), that affects only the specific factory and product. The client code stays unchanged - its coupling to the factories is minimal.
Conclusion: Abstract Factory creates a layer of abstractions between the client and the implementations, which makes the code independent, easy to extend, and less prone to cascading changes.
Short Answer
Interview readyA concise answer to help you respond confidently on this topic during an interview.