Skip to content

Instantly share code, notes, and snippets.

@yemrekeskin
Created January 14, 2015 13:32
Show Gist options
  • Save yemrekeskin/8718c57915aa1a3218e4 to your computer and use it in GitHub Desktop.
Save yemrekeskin/8718c57915aa1a3218e4 to your computer and use it in GitHub Desktop.
/// <summary>
/// Abstract Product
/// </summary>
abstract class Command { }
abstract class Connection { }
abstract class Transaction { }
/// <summary>
/// Concrete Product for Oracle
/// </summary>
class OracleCommand
: Command
{
}
class OracleConnection
: Connection
{
}
class OracleTransaction
: Transaction
{
}
/// <summary>
/// Concrete Product for MySql
/// </summary>
class MySqlCommand
: Command
{
}
class MySqlConnection
: Connection
{
}
class MySqlTransaction
: Transaction
{
}
/// <summary>
/// Abstarct Factory
/// </summary>
abstract class DbFactory
{
public abstract Connection Connection();
public abstract Command Command();
public abstract Transaction Transaction();
}
/// <summary>
/// Concrete Factory for Oracle
/// </summary>
class OracleDbFactory
: DbFactory
{
public override Connection Connection()
{
return new OracleConnection();
}
public override Command Command()
{
return new OracleCommand();
}
public override Transaction Transaction()
{
return new OracleTransaction();
}
}
/// <summary>
/// Concrete Factory for MySql
/// </summary>
class MySqlDbFactory
: DbFactory
{
public override Connection Connection()
{
return new MySqlConnection();
}
public override Command Command()
{
return new MySqlCommand();
}
public override Transaction Transaction()
{
return new MySqlTransaction();
}
}
// kullanımı
DbFactory MySqlFactory = new MySqlDbFactory();
MySqlFactory.Connection();
MySqlFactory.Command();
MySqlFactory.Transaction();
DbFactory oracleFactory = new OracleDbFactory();
oracleFactory.Connection();
oracleFactory.Command();
oracleFactory.Transaction();
// Wrapper sınıf
interface IDataBlock
{
void Open();
void Close();
void Execute(string query);
DataTable GetList(string query);
int GetRecordCout(string query);
}
protected class DataAccessBlock
:IDataBlock
{
private DbFactory Factory;
private Connection Connection;
private Command Command;
private Transaction Transaction;
public DataAccessBlock(DbFactory factory)
{
this.Factory = factory;
this.Connection = Factory.Connection();
this.Command = Factory.Command();
this.Transaction = Factory.Transaction();
}
public void Open()
{
throw new NotImplementedException();
}
public void Close()
{
throw new NotImplementedException();
}
}
//...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment