For example, there is a program to make out animals world in different continents.
Different continent has its owner different carnivores and Herbivores. So we can use abstract factory to create the different animals.
participants
In
Asia
tigers eat other animals and in Africa Lions eat other animals.
// Abstract Factory pattern -- Real World example
using System;
namespace DoFactory.GangOfFour.Abstract.RealWorld { // MainApp test application
class MainApp { publicstaticvoid
Main
() { // Create and run the Africa animal world ContinentFactory
africa
= new AfricaFactory(); AnimalWorld world = new AnimalWorld(
africa
); world.RunFoodChain();
// Create and run the
America
animal world ContinentFactory
america
= new AmericaFactory(); world = new AnimalWorld(
america
); world.RunFoodChain();