interface Logger{ public void WriteLog(); } public class FileLog implements Logger{ public void WriteLog(){ system.out.print("file wirte"); } } public class DBFileLog implements Logger{ public void WriteLog(){ system.out.print("db wirte"); } } interface Factory{ public Logger createLogger(); } public class FileFactory implements Factory{ public Logger createLogger(){ Logger fileLogger=new FileLog(); return fileLogger; } } public class DBFactory implements Factory{ public Logger createLogger(){ Logger dbLogger=new DBFileLog(); return dbLogger; } } public class App{ public void Main(string args){ Logger logger; Factory factory; factory=new FileFactory(); logger=factory.createLogger(); logger.wirte("测试"); } }