public static void Main()
Console.WriteLine("Hello World");
Factory f = new Factory(new MSSQLFactory());
Console.WriteLine("################");
f = new Factory(new OracleFactory());
private readonly DatabaseFactory _dbfac;
private readonly IConnection _connection;
private readonly ICommand _command;
public Factory(DatabaseFactory dbfac)
_connection = dbfac.CreateConnection();
_command = dbfac.CreateCommand();
_connection.Disconnect();
public abstract class DatabaseFactory
public abstract IConnection CreateConnection();
public abstract ICommand CreateCommand();
public class MSSQLFactory : DatabaseFactory
public override IConnection CreateConnection()
return new MSSQLConnection();
public override ICommand CreateCommand()
return new MSSQLCommand();
public class OracleFactory : DatabaseFactory
public override IConnection CreateConnection()
return new OracleConnection();
public override ICommand CreateCommand()
return new OracleCommand();
public interface IConnection
public class MSSQLConnection : IConnection
Console.WriteLine("Connected MSSQL database started..");
Console.WriteLine("Disconnected MSSQL database stopped.");
public class OracleConnection : IConnection
Console.WriteLine("Connected Oracle database started..");
Console.WriteLine("Disconnected Oracle database stopped.");
public interface ICommand
public class MSSQLCommand : ICommand
Console.WriteLine("MSSQL query running...");
public class OracleCommand : ICommand
Console.WriteLine("Oracle query running...");