how does Abstract Factory design pattern is useful ? doesn't it just a polymorphism and nothing else ? [closed]
how does Abstract Factory is useful ? doesn't it just a polymorphism and nothing else ?
I have read all the design patterns and everywhere things looks similar. most of them are开发者_StackOverflow社区 type of polymorphism's different flavors.
Abstract Factory uses polymorphism, yes, but so do many other patterns - polymorphism is a fundamental part of object oriented languages, so it is also part of how you express concepts in individual patterns.
The core of this design pattern is to be able to switch out a family of related class hierarchies (as opposed to individual types) by introducing an abstract factory to encapsulate object creation for all types within the family.
Once you provide a concrete implementation of the abstract factory for a particular "family" (or "theme"), this factory then in turn is used to create instances of classes within the family - the prime example being platform dependent widgets.
精彩评论