What does Abstract Factory guarantee that using several independent Factory objects cannot?
It guarantees that every product created from a single factory instance belongs to the same consistent family, which several separate factories, one for buttons and a different one for scroll bars, can never enforce on their own. With independent factories, nothing stops code from asking the button factory for a Windows button and the scroll-bar factory for a Mac scroll bar, producing a visually and logically inconsistent result that compiles and runs without error. Abstract Factory closes this gap by defining one interface with a creation method for every product in the family, so that a single concrete factory, such as WindowsFactory, is the only source for all of that family's related objects, making a mismatched combination structurally impossible rather than merely discouraged.
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