Home  /  Questions  /  Question



50   50
Jul 16, 2011


Abstract Factory pattern -- Structural example with interface

Hi,

Can someone show me how to do the sample example of abstract factory:  "Abstract Factory Pattern - Structural Example" as outlined in this site, but with using an Interface?

Regards,
Amees




80   96.4
Aug 01, 2011
You could replace the AbstractFactory class with this:

public interface AbstractFactory
{
    AbstractProductA CreateProductA();
    AbstractProductB CreateProductB();
}

You could also replace the abstract Product base classes (AbstractProductA and AbstractProductB) with this:

public interface AbstractProductA
{
}

public interface AbstractProductB
{
    void Interact(AbstractProductA a);
}
You'll then have to remove all "override" keywords, because now your classes implement the interface instead of overriding the base class.

Hope this helps.