<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    junhong

    Design pattern with java (part four)

    1. Flyweight: too many objects
      it is very simple, you externalize some of the data in an object, so that you can pretend that you have more objects than you really do. However, this adds complexity to the interface for using such objects, because you must pass in additional information to method calls in order to tell the method how to find the externalized information.
    2. Decorator: too many classes
      The use of layered objects to dynamically and transparently add responsibilities to individual objects is referred to as the decorator pattern.
      Used when subclassing creates too many (& inflexible) classes
      All decorators that wrap around the original object must have the same basic interface
      Dynamic proxy/surrogate?
      This accounts for the odd inheritance structure
      Tradeoff: coding is more complicated when using decorators
      Basic decorator structure

    thinking in patterns with Java2.bmp

    Connecting different types

    1.Adapter

    Adapter takes one type and produces an interface to some other type. When you’ve got this,
    and you need that, Adapter solves the problem. The only requirement is to produce a that,
    and there are a number of ways you can accomplish this adaptation.
    //: adapter:SimpleAdapter.java
    // "Object Adapter" from GoF diagram
    package adapter;
    import junit.framework.*;
    class Target {
    public void request() {}
    }
    class Adaptee {
    public void specificRequest() {
    System.out.println("Adaptee: SpecificRequest");
    }
    }
    class Adapter extends Target {
    private Adaptee adaptee;
    public Adapter(Adaptee a) {
    adaptee = a;
    }
    public void request() {
    adaptee.specificRequest();
    }
    }public class SimpleAdapter extends TestCase {
    Adaptee a = new Adaptee();
    Target t = new Adapter(a);
    public void test() {
    t.request();
    }
    public static void main(String args[]) {
    junit.textui.TestRunner.run(SimpleAdapter.class);
    }
    } ///:~
    2. Bridge
    but the goal of Bridge is to allow you to structure your code so that you can easily add new kinds of front-end objects which are implemented with functionality in new kinds of back-end objects. Thus, both front-end and back-end can vary independently of each other.

    The front-end classes can have completely different interfaces from each other, and typically do. What they have in common is that they can implement their functionality using facilities from any number of different back-end objects. The back-end objects also don’t have the same interface. The only thing the back-end objects must have in common is that they implement the same kind of functionality – for example, a group of different ways to implement a graphics library or a set of different data-storage solutions.

    Bridge is really a code-organization tool that allows you to add in any number of new frontend services that implement their operations by delegating to any number of back-end options. Using Bridge, you can accomplish this without the normal combinatorial explosion of possibilities that would otherwise occur. But keep in mind that the vector of change with Bridge is typically happening at coding time: it keeps your code organized when you are dealing with an increasing number of options for implementing functionality.

    ?

    posted on 2006-04-12 16:07 junhong 閱讀(249) 評論(0)  編輯  收藏


    只有注冊用戶登錄后才能發表評論。


    網站導航:
     
    主站蜘蛛池模板: 日韩高清免费在线观看| 国产成人免费AV在线播放| 青青在线久青草免费观看| 亚洲福利视频导航| 久久久久久国产精品免费免费男同| vvvv99日韩精品亚洲| 日韩大片在线永久免费观看网站| 久久久久国色AV免费观看性色| 亚洲youjizz| 日本一道综合久久aⅴ免费| 国产成人不卡亚洲精品91| 国产精品免费视频播放器| 日本永久免费a∨在线视频| 亚洲精品老司机在线观看| 亚洲国产成人久久精品app| 无码免费午夜福利片在线| 亚洲人成色4444在线观看| 国产一区二区三区在线观看免费| 一级做a爱过程免费视| 亚洲精品无码久久久久| 37pao成人国产永久免费视频| 亚洲高清成人一区二区三区| 国产免费AV片在线观看播放| 久久亚洲精品AB无码播放| 999在线视频精品免费播放观看| 亚洲一区二区三区高清在线观看| 日本中文一区二区三区亚洲| 波霸在线精品视频免费观看| 亚洲黄色片免费看| 成人免费无码大片a毛片| 九九九国产精品成人免费视频| 亚洲欧洲日韩国产综合在线二区| 无人在线观看免费高清视频| 免费一级特黄特色大片| 亚洲卡一卡2卡三卡4卡无卡三| 女人被弄到高潮的免费视频| 狠狠躁狠狠爱免费视频无码| 亚洲国产精品人久久电影| 免费一级黄色毛片| 最近中文字幕免费2019| 色妞www精品视频免费看|