設計模式(八)預設介面卡
阿新 • • 發佈:2018-12-04
1、目標
//目標
public interface IDesigner {
public void drawPicture();
public void findIdea();
public void thinkUE();
public void showPicture();
}
2、預設介面卡
//預設介面卡 public abstract class Designer implements IDesigner{ public void drawPicture(){ System.out.println("畫畫!"); } public void findIdea(){ System.out.println("尋找靈感!"); } }
3、介面卡
//介面卡1
public class CarDesigner extends Designer{
@Override
public void thinkUE() {
System.out.println("思考汽車的使用者體驗!");
}
@Override
public void showPicture() {
System.out.println("辦汽車設計展!");
}
}
//介面卡2 public class HouseDesigner extends Designer{ @Override public void thinkUE() { System.out.println("思考房屋的使用者體驗!"); } @Override public void showPicture() { System.out.println("辦房屋設計展!"); } }
4、消費者
public class Customer { public static void main(String[] args) { CarDesigner carDesigner=new CarDesigner(); carDesigner.drawPicture(); carDesigner.findIdea(); carDesigner.thinkUE(); carDesigner.showPicture(); System.out.println("----------------------"); HouseDesigner houseDesigner=new HouseDesigner(); houseDesigner.drawPicture(); houseDesigner.findIdea(); houseDesigner.thinkUE(); houseDesigner.showPicture(); } }