digitalmars.D.announce - std.database a design suggestion
- bls (35/35) Oct 10 2011 Hi, what do you people think about using the GoF
- Michal Minich (11/14) Oct 10 2011 for one, in this case, better to use interface only, and connect method
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(); } }
Oct 10 2011
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.
Oct 10 2011