std.database design suggestion

Daniel Gibson metalcaedes at gmail.com
Tue Oct 11 18:10:46 PDT 2011


Am 10.10.2011 12:04, schrieb bls:
> -- Sorry for posting on D.announce --
>
> 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();
>
> }
> }

I think this would make sense and JDBC does something similar, if I 
recall correctly.

Cheers,
- Daniel


More information about the Digitalmars-d mailing list