Any widget that supports multiple look and multiple feel has to deal with multiple Model, View and Controller objects. To maintain flexibility it is important to make these objects not depend on how other objects are created.
Creational design patterns solve these issues. These patterns reduce design complexity and increases flexibility. Here's the sentence from a famous design patterns book about creational design patterns:
"Creational design patterns give a lot of flexibility in What gets created, Who creates it, How it gets created, and when"
Factory Method Pattern:
This pattern encapsulates Controller creation and moves this knowledge out of View framework classes. View framework let's View subclasses to decide which controller class to instantiate because it only knows when to create a controller, not what kind of controller to create.
The main purpose of the Factory method is to create objects.
Controller Base: Controller's abstract class
Controller 1 and Controller 2: Controller's Concrete class
View Base: View's abstract class
View 1 and View 2: View's Concrete class
Controller Creator: This class has a factory method that creates Controller 1 or Controller 2 and returns a pointer to Controller Base. View Base uses this class and lets the derived class View 1 and View 2 to decide which Controller to instantiate.
Creational pattern, for more information about other Creational design patterns.
No comments:
Post a Comment