首页 > 其他分享 >设计模式抽象工厂方法

设计模式抽象工厂方法

时间:2022-10-21 19:24:43浏览次数:41  
标签:String show class 工厂 Override 抽象 makeLogger 设计模式 public

代码:

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/16814547.html

相关文章