W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
外觀模式隱藏了系統(tǒng)的復(fù)雜性。
它為客戶端提供了一個(gè)簡單的接口,客戶端使用接口與系統(tǒng)交互。
外觀模式是結(jié)構(gòu)型模式。
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(); } }
上面的代碼生成以下結(jié)果。
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: