Tuesday, September 7, 2010

Factory Design Pattern

The Factory Design Pattern is maybe the most used pattern in modern languages like Java and C#. Most probably if you are searching for factory design pattern on the internet most of the results are about Factory Method and Abstract Factory.

We use it when we want to:
  • creates objects without exposing the instantiation logic to the client.
  • refers to the newly created object through a common interface





class DBConnector : public QObject

{
Q_OBJECT
public:
DBConnector(QObject* parent=0);

~DBConnector();

virtual bool OpenConnection(QString aDatabaseName) = 0;

QSqlQuery GetData(QString aSqlQuery);

bool WriteData(QString aSqlQuery);

void commit();

void cleanUp();

protected:

QSqlDatabase* m_pDatabase;

QSqlQuery* m_pQuery;

signals:

void ConnectionErrorSignal(QString);

void QueryErrorSignal(QString);

};


class SqliteDBConnector : public DBConnector

{

public:

SqliteDBConnector();

bool OpenConnection(QString aDatabaseName);

};


bool DBManager::CreateDBConnectors()
{
DBConnector m_pMainDBConnector = new SqliteDBConnector();

return true;
}

No comments: