Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Difference between abstract factory pattern and factory
method pattern in .NET with example.

Answer Posted / guest

Abstract Factory patterns acts a super-factory which creates
other factories. This pattern is also called as Factory of
factories. In Abstract Factory pattern an interface is
responsible for creating a set of related objects, or
dependent objects without specifying their concrete classes.

public interface AbstractFactory
{
AbstractProductA CreateProductA();

AbstractProductB CreateProductB();
}

public class ConcreteFactoryA : AbstractFactory
{
public AbstractProductA CreateProductA()
{
return new ProductA1();
}

public AbstractProductB CreateProductB()
{
return new ProductB1();
}
}

public class ConcreteFactoryB : AbstractFactory
{
public AbstractProductA CreateProductA()
{
return new ProductA2();
}

public AbstractProductB CreateProductB()
{
return new ProductB2();
}
}

public interface AbstractProductA { }

public class ProductA1 : AbstractProductA { }

public class ProductA2 : AbstractProductA { }

public interface AbstractProductB { }

public class ProductB1 : AbstractProductB { }

public class ProductB2 : AbstractProductB { }

public class Client
{
private AbstractProductA _productA;
private AbstractProductB _productB;

public Client(AbstractFactory factory)
{
_productA = factory.CreateProductA();
_productB = factory.CreateProductB();
}
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is a nested masterpage in asp.net 2.0? Can there be a master page inside a masterpage?

845


What is difference between session and application in asp net?

966


What is csrf attack in asp.net?

958


What is the function used for removing an event listener?

970


How can we pass info between 2 asp.net pages?

1009


What is asp net_sessionid?

1044


What is the difference between custom web user control and a custom web server control?

901


Explain login controls.

1055


What are all the various Estimation Techniques available ?

1051


What is session in asp.net?

909


Why is it preferred to not use finalize for clean up?

942


Define machine.config in .net?

932


What are Master Pages in ASP.NET? or What is a Master Page?

1049


Is asp.net is a programming language?

890


Explain different authentication modes in asp.net?

1100