Template Method (Behavioral Design Patterns) in cooperation with Factory Method (Creational Patterns).
At one of the previous articles we were talking about Factory Method design pattern implementation.
" Implementation is simple. In general, we will have one interface ( DB), which will declare the union API for any database processing. Of course, we will have one fabric class ( FabricDB ), which will be responsible for instantiating of concrete database class. And, finally, we will have the realization of each concrete database classes ( PostgreDB and SQLiteDB ) which are derived from the DB interface." - it was the short description of the Factory Method Design Pattern implementation.
Let's imagine : we have an algorithm, which needs, between others, to process the different databases. The main skeleton of the algorithm is constant, but we have the database - dependent parts. In our example the TemplateMethodAbstractClass.ProcessDatabaseTemplateMethod() represent the skeleton of the algorithm, but the Open() and Close() part of them are implemented at the concrete database classes and different for SQLite database and PostgeSQL database.
Let's try to implement this in C#.
|