Sunday, May 30, 2010

Abstract Factory Pattern

Provides an interface for creating families of related or dependent objects without specifying their concrete classes.



1. It relies on object composition, object creation is in methods exposed in the factory interface.

2. Example from .NET

a. DbProviderFactory is an abstract factory.
b. It is implemented by SqlClientFactory, OdbcFactory
c. SqlClientFactory returns SqlCommand, OdbcFactory returns OdbcCommand
 namespace System.Data.Common { 
public abstract class DbProviderFactory {
protected DbProviderFactory();
public virtual bool CanCreateDataSourceEnumerator { get; }
public virtual DbCommand CreateCommand();
public virtual DbCommandBuilder CreateCommandBuilder();
public virtual DbConnection CreateConnection();
public virtual DbConnectionStringBuilder CreateConnectionStringBuilder();
public virtual DbDataAdapter CreateDataAdapter();
public virtual DbDataSourceEnumerator CreateDataSourceEnumerator();
public virtual DbParameter CreateParameter();
public virtual CodeAccessPermission CreatePermission(PermissionState state);
}
}

No comments:

Post a Comment