单例
Public class Singleton(){
Private static Singleton singleton= new Singleton();
Private Singleton(){}
Public static Singleton getSingleton(){
Return singleton;
}
}
工厂
Public interface IProduct{
void produce();
}
Public class product implements IProduct{
Public void produce(){
System.out.println("produce");
}
}
Public class Factory{
Public static IProductProduct(String productName){
IProduct product=null;
try{
product=(product)Class.forName("product").newInstance();
}catch(Exception e){
e.printStackTrace();
}
Return product;
}
}