<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)  編輯  收藏


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


    網站導航:
     
    主站蜘蛛池模板: 毛片免费全部免费观看| 久久久亚洲欧洲日产国码农村| 日本三级2019在线观看免费| 国产免费AV片在线播放唯爱网| 四虎影视在线永久免费观看| 亚洲一区无码精品色| 亚洲第一永久在线观看| 亚洲精华国产精华精华液好用 | 99在线免费观看| 日本免费xxxx色视频| 亚洲精品成人片在线观看| 亚洲精品mv在线观看 | 女人18毛片水真多免费播放 | 亚洲av无码av制服另类专区| 亚洲欧美国产精品专区久久| 男的把j放进女人下面视频免费| 毛片免费vip会员在线看| 国产亚洲欧美日韩亚洲中文色| 好紧我太爽了视频免费国产| 免费人成在线观看播放国产| 亚洲综合久久一本伊伊区| a毛看片免费观看视频| 亚洲高清视频在线观看| 国产乱子精品免费视观看片| 亚洲国产日韩一区高清在线| 久久久久久毛片免费看 | 亚洲中文字幕不卡无码| 久久精品国产亚洲AV电影网| 亚洲片国产一区一级在线观看 | 亚洲 综合 国产 欧洲 丝袜 | 国产免费一级高清淫曰本片| 亚洲国产一区二区三区青草影视| 成人AV免费网址在线观看| 亚洲avav天堂av在线网毛片| 精品免费人成视频app| 亚洲AV性色在线观看| 久久青青成人亚洲精品| 女人张开腿给人桶免费视频| 免费萌白酱国产一区二区三区| 区三区激情福利综合中文字幕在线一区亚洲视频1 | 国产片免费福利片永久|