Abstract Factory design pattern


It is a super factory which creates other factories. This factory is also called as Factory of factories.
Example:
Abstractfactory

abstract class Animal
{
 abstract String speak();
}

class Cat
{
 string speak()
 {
  return "Meow";
 }
}

class Dog
{
 string speak()
 {
  return "Bark bark";
 }
}

class Lion
{
 string speak()
 {
  return "Roar roar";
 }
}

class Octopus
{
 string speak()
 {
  return "Squak squak";
 }
}

class Shark
{
 string speak()
 {
  return "cant speak";
 }
}

class SeeAnimalFactory 
{
 public Animal getAnimal(string animalType)
 {
   Animal animal = null;
   If("octopus".equals(animalType))
      animal = new Octopus();
   If("shark".equals(animalType))
      animal = new Shark();
 }
}

class LandAnimalFactory 
{
  public Animal getAnimal(string animalType)
  {
    Animal animal = null;
    if("dog".equals(animalType))
        animal = new Dog();
    if("cat".equals(animalType))
        animal = new Cat();
    if("lion".equals(animalType))
        animal = new Lion();
 }
}

class AnimalFactory
{
 public abstract Animal getAnimal(string anumalType)
  {
    If("see".equals(anumalType))
        return new SeeAnimalFactory();
    else
      return new LandAnimalFactory();
  }
}

class SpeakAnimals 
{
 AnimalFactory animalFactory = new AnimalFactory();
 Animal animal = animalFactory.getAnimal("Dog");
 animal.speak();
}