Designing was one of the core reasons that I took part in system modelling and pursed that career. It a joie de vivre to create the visual blocks of components and them implement them. Nothing gives you as much satisfaction when a creation that was put on paper finally sees the light of the day :).
Design patterns is not a way of modelling just provides ways of implementing of building blocks of component [I always think those are classes put purists might disagree :(.... ] and provide flexibity of the system in case of any major changes !!!
We will start with the design for the factory pattern and will update this column soon. cheers !!!
Design patterns is not a way of modelling just provides ways of implementing of building blocks of component [I always think those are classes put purists might disagree :(.... ] and provide flexibity of the system in case of any major changes !!!
We will start with the design for the factory pattern and will update this column soon. cheers !!!
As we can see from the design, following are the components that are taking part :
1) Creator : As i had mentioned that this can be an abstract class or an interface. In our case this is represented by IAirFactory.This defines an factory method called CreateProduct which accepts a parameter of type ProductSprecification .(This factory method is a an example of paremeterized factory method where on the basis of the i/p parameter it decides which product is to be instantiated. The benefit of haveing a parameterized factory is that it eliminates the need to subclass a Creator in order to facilicate the use of a new Product as and when it comes.)
2) Concrete Creator: In the given sample, the classes that have been sub-classed from the Creator i.e FactoryJet,FactoryBoeing,FactoryEastWest,FactoryGulf.
3) Product : In our case the product is represented by the interface IProduct. Under real life senarios this can be an abstract class as well.
Note: Now there can be many variations of the factory method
a) Either the creator can be a abstrcat class providing default implemenation of the factory method or no implemenation . e.g The IAirFactory if it was an abstract class and if the airfactory has to return a default product of Seats then CreateProduct method would not have been an abstract class. Then the ConcreteCreator have to override the base method to provide its own implementation of the CreateProduct()
b) We can use the parameterized factory method to reduce the number of sub-classes formed by the creators for concrete products. e.g In our example we are using the paramertized factory method i.e the CreateProduct() uses the ProductSpecification as a parameter.The IAirFactory if it was an abstract class CreateProduct could have had some default implemetaion to return the appropriate Product (Tyre,Seat)instead of having all the sub-classed concrete products.

No comments:
Post a Comment