<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 閱讀(254) 評論(0)  編輯  收藏


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


    網站導航:
     
    主站蜘蛛池模板: 91免费福利视频| 亚洲AV无码一区二区三区牲色 | jizz中国免费| 免费一看一级毛片| 国产精品亚洲精品日韩电影| 国产色在线|亚洲| 国产免费看JIZZ视频| 亚洲av日韩av综合| 无码人妻久久一区二区三区免费丨| 亚洲日韩中文字幕| 黄网站色成年片大免费高清| 国产人妖ts在线观看免费视频| 国产亚洲精品91| 红杏亚洲影院一区二区三区| 国产精品免费久久久久久久久| 国产亚洲自拍一区| 久久aa毛片免费播放嗯啊| 日本高清免费网站| 亚洲国产美女在线观看| 男女超爽刺激视频免费播放 | MM1313亚洲国产精品| 久久午夜伦鲁片免费无码| 亚洲电影唐人社一区二区| 日本黄色动图免费在线观看| 日韩精品一区二区亚洲AV观看| 波多野结衣免费在线观看| 亚洲av无码兔费综合| 亚洲无人区一区二区三区| 最近中文字幕大全中文字幕免费 | 亚洲精品制服丝袜四区| 日本免费网站视频www区| 亚洲综合成人网在线观看| 日韩不卡免费视频| 一级做a爰性色毛片免费| 国产高清视频在线免费观看| 亚洲AV无码专区国产乱码电影| 又粗又长又爽又长黄免费视频| 人人狠狠综合久久亚洲婷婷| 毛片a级毛片免费播放下载| 激情综合亚洲色婷婷五月| 成人免费视频国产|