std.database a design suggestion

bls bizprac at orange.fr
Mon Oct 10 03:02:13 PDT 2011


Hi, what do you people think about using the GoF
Factory (design) pattern ?
F.I.

abstract class Database {

	//common database stuff
	public abstract void connect(string user, string pw);
	// execSql(); prepare() etc...
}

abstract class DatabaseFactory {

    public abstract Database GetDatabase();
}

class PostgreSQL:Database {

	// common
    public override void connect(string user, string pw) {

    }
    //PostgreSQL specific
    public void funkyPGstuff() {}
}

class PostreSQLFactory:DatabaseFactory {

    public override Database GetDatabase() {

       return new PostgreSQL();

    }
}

class MySQL:Database {

	// common
    public override void connect(string user, string pw) {

    }
    //MySQL specific
    public void funkyMySQLstuff() {}
}

class MySQLFactory:DatabaseFactory {

    public override Database GetDatabase() {

       return new MySQL();

    }
}


More information about the Digitalmars-d-announce mailing list