W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
外觀模式隱藏了系統(tǒng)的復雜性。
它為客戶端提供了一個簡單的接口,客戶端使用接口與系統(tǒng)交互。
外觀模式是結構型模式。
class ShapeFacade { interface Shape { void draw(); } class Rectangle implements Shape { @Override public void draw() { System.out.println("Rectangle::draw()"); } } class Square implements Shape { @Override public void draw() { System.out.println("Square::draw()"); } } class Circle implements Shape { @Override public void draw() { System.out.println("Circle::draw()"); } } private Shape circle = new Circle(); private Shape rectangle = new Rectangle(); private Shape square = new Square(); public ShapeFacade() { } public void drawCircle() { circle.draw(); } public void drawRectangle() { rectangle.draw(); } public void drawSquare() { square.draw(); } } public class Main { public static void main(String[] args) { ShapeFacade shapeFacade = new ShapeFacade(); shapeFacade.drawCircle(); shapeFacade.drawRectangle(); shapeFacade.drawSquare(); } }
上面的代碼生成以下結果。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: