代码:
package com.by;
interface logger {
public String show();
}
interface factory{
public String makeLogger();
}
class filelogger implements logger{
@Override
public String show() {
// TODO Auto-generated method stub
return "文件日志记录";
}
}
class filefactorty implements factory{
@Override
public String makeLogger() {
// TODO Auto-generated method stub
return new filelogger().show();
}
}
class databaselogger implements logger{
@Override
public String show() {
// TODO Auto-generated method stub
return "数据库记录";
}
}
class databasefactory implements factory{
@Override
public String makeLogger() {
// TODO Auto-generated method stub
return new databaselogger().show();
}
}
public class Text1 {
public static void main(String[] args) {
System.out.println(new filefactorty().makeLogger());
System.out.println(new databasefactory().makeLogger());
}
}
实验结果:
标签:String,show,class,工厂,Override,makeLogger,设计模式,方法,public From: https://www.cnblogs.com/123-456-789/p/16814531.html