October 10, 2011 std.database a design suggestion | ||||
---|---|---|---|---|
| ||||
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(); } } |
October 10, 2011 Re: std.database a design suggestion | ||||
---|---|---|---|---|
| ||||
Posted in reply to bls | On Mon, 10 Oct 2011 12:02:13 +0200, bls wrote:
> Hi, what do you people think about using the GoF Factory (design)
> pattern ?
> F.I.
for one, in this case, better to use interface only, and connect method can return instance of Database class, saving one factory and one method.
interface IDatabase {
SqlCommand createCommand ();
}
class MySql : IDatabase {
static MySql connect (..specific args,probably connection string);
}
But yes, using factory classes and methods is good approach to this design problem.
|
Copyright © 1999-2021 by the D Language Foundation