Summary of the creation pattern:
The Earth (customer) needs a nature (product), the nature needs to have a lot of animals (product features), many plants (product features). Nature uses a combination of singleton mode and abstract Factory mode. Animals and plants are created using a simple factory method pattern. To create an animal, for example: In a simple factory encounter the same "person", Directly using the prototype pattern cloning, the law is created by the builder mode.
Public Animal
{
Private String mtype = null;
Public Animal Clone ()
{
...
}
Public String GetType ()
{
return mtype;
}
}
Public Humananimal extends Animal
{
public static Builder ()
{
Public Build Add (String part)
{
}
Public Humananimal Build ()
{
}
}
}
Public animalfactory
{
Private Animal mlastanimal = null;
Public Animal Create (String type)
{
if (Type.equals (Mlastanimal.gettype))
{
return Mlastanimal.clone ();
}
Else
{
Animal Temp=null;
if (type.eaual ("person"))
{
temp = new Humananimal.builder (). Add ("Hand"). Add ("header"). Add ("Foot"). Add ("torso"). Build ();
}
...//other animals slightly
Mlastanimal = temp;
return temp;
}
}
}
Private Class Nature
{
Private list<animal> manimals= new arraylist<animal> ();
Private list<plant> mplants = new arraylist<plant> ();
private static Nature minstance = null;
Private Nature ()
{
Manimals.add (animalfactory.create ("person"));
Manimals.add (animalfactory.create ("person"));
Manimals.add (Animalfactory.create ("Dog"));
Manimals.add (Animalfactory.create ("Grass carp"));
...
Mplants.add (Plantfactory.create ("Horn Flower"));
Mplants.add (Plantfactory.create ("Peach Tree"));
...
}
public static Nature getinstance ()
{
if (minstance = = null)
{
Minstance = new Nature ();
}
return minstance;
}
Public list<animal> getanimals ()
{
return manimals;
}
Public list<plant> getplants ()
{
return mplants;
}
}
The creation pattern of design pattern perception