//Creator
public abstract class Creator
{
/**
* looks like a factory
* contains some products and some process methods
*/
protected Product duct;
abstract String processProduct();
abstract String processProductSpecial();
public String Operation()
{
return processProduct(); // FactoryMethod for implemention;
}
}
//ConcreteProduct
public class ConcreteProduct extends Product
{
public ConcreteProduct()
{
System
}
public String makeString(String str)
{
return
}
}
//Product
public abstract class Product
{
public abstract String makeString(String str);
}
//ConcreteCreatorA
public class ConcreteCreatorA extends Creator
{
/**
* You can write some other class like this to override
* the same methods do diffrent thing;
*/
public ConcreteCreatorA()
{
duct=new ConcreteProduct();
System
}
public String processProduct()
{
System
return duct
}
public String processProductSpecial()
{
System
//add another method here
return duct
}
}
//TestFactoryMethod
public class TestFactoryMethod
{
public TestFactoryMethod()
{
}
public static void main(String[] arg)
{
ConcreteCreatorA cc=new ConcreteCreatorA();
System
System
}
}
From:http://tw.wingwit.com/Article/program/Java/gj/201311/27358.html