Factory Method.
Actually useful design pattern. Let's imagine - you are in development of some B2B application and you need to keep working with two (or more) different databases, which have different APIs. It is the real situation. For example, you have the SQLite RDBMS at the client side and something more heavy at the server. Let it be the PostgreSQL. Frankly speaking, we actually interested in one interface for work with different RDBMS. Factory Method will help us.
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.
Let's try to implement this in C#.
|
|
|