Delphi-Quellcode:
type TDbConnectionFactory =
class
public
class function getConnection(aConStr, aArt:
string): IDbConnection;
end;
...
class function getConnection(aConStr, aArt:
string): IDbCOnnection;
begin
if (aArt = '
MySQL')
then
result := MySqlConnection.Create(aConStr)
else if (aArt = '
Firebird')
then
result := FbConnection.Create(aConStr)
else if (aArt = '
ODBC')
then
result := OdbcConnection.Create(aConStr);
if (result =
nil)
then
Exception.Create('
Ungültige Datenbankart');
end;
Delphi-Quellcode:
myConnection := TDbConnectionFactory.getConnection('
DSN=wall;UID=wwwrun;PWD=', '
ODBC');
...
Das würd ich machen. Entsprechende Factorys eben auch für die anderen Sachen (z.B. Command)