Factory design Pattern and Abstract Factory design pattern - sharmasadhna/mylearnings GitHub Wiki
Factory design Pattern
AIM:
when client wants to create an object of certain type (to call methods on that) it need not be bothered with so many details like what parameters the object will accept etc...
need not know the details of implementation , it only have to know minimal interface method needed to call.
below ex: only getdatabaseobject() is known, and then only connect is known
ex:
indiviadual database types inherits from interface IDatabase --> and implements their own connect() method;
SQl, Oracle,MySQl database classes implements interface method connect
DataBaseFactory.cpp --> public IDataBase getdatabaseobject(string databaseType) { if (dataBaseType == SQL) new SQL and return;}
In client code --> call IDataBase obj = DataBaseFactory.getdatabaseobject(sql/oracle/mysql ...). oj.connect() //connect to respective database.
Abstract Factory design Pattern
Factory of factories--> example of Shape 2d and 3d shapes