Thinking in Patterns chapter 5: Object decoupling

Thinking in Patterns with Java V0.9: chapter 5: Object decoupling: TIPatterns.htm#_Toc41169699

1, The sections name of today's learning;

    Proxy: fronting for another object 31

        The PoolManager using Proxy. 33

        Dynamic Proxies. 36

    State: changing object behavior  38

    Iterators: decoupling algorithms from containers  44

        Type-safe iterators. 45

    Exercises. 46

 

2, What is it talk about in these sections and my comments and feeling for the content;

  At the begin of this chapter, Bruce put up with his own opinion about

pattern Proxy and State. In his mind, these two patterns are simlar

structurely while GoF's these two patterns are different structurely. They are

all the surrogate "controlling access to implementation". Only Proxy access a

fixed implementation while State access several implementations dynamically.

From his opinion, he point some "mistake" written in GoF's Design Patterns,

you can see these words at the end of State patterns, like this:" Rewrite this:

In Design Patterns, Proxy and State are not seen as related to each other because the two are given (what I consider arbitrarily) different structures." ,and so on.

  I haven't read GoF's Design Patterns, so can't write some my feeling. I only

want to say, speaking with own mind, Bruce, a real master.

  Bruce says: The basic idea is simple: from a base class, the surrogate is derived along with the class or classes that provide the actual implementation:(I think his meaning is the same idea is used for proxy and state pattern)

  1), Proxy: fronting for another object

  I think proxy patterns can decouple objects, the reason is add a middle layer between the client and implementation class. When the implementation class change, the interface class that is proxy which will don't change. From my poor experience, I haven't tasted it's power. From my mind, why does add another layer between them? The changes is always happened on implementation class regardless the existence of proxy class. I think I should read more famous open source project like jive or pet store application.

  Although I understand the basis concept of proxy pattern, and I can see some code of example The PoolManager using Proxy, but spending some minutes on it, I can't understand this complex example yet, I can only put it there, maybe after this overview of book, I can see it entirely when I revisit this example.

  I can't compile the example Dynamic Proxies, and can't under this this section, and, I can't know why Bruce add a comment "// Broken in JDK 1.4.1_01" in the class file "proxy:DynamicProxyDemo.java" that showed in html page but isn't included into code folder of this electronic book. I think maybe I need learn the java.lang.reflect.Proxy class in the JDK.

 

  2), State: changing object behavior

  At last, I understand why this pattern be included into the category "object decoupling". For performing different action according to the certain condition, if no state object involved, it will be added some testing code in some methods.

  State pattern is implemented with the power of "polymorphism", from my understanding, State pattern is just one object hold a state object as a state property, according to the state object's change, that object will change its action. 

  3), Iterators: decoupling algorithms from containers

  In this section, an interesting term named "functional programming" give me strong impression. Walk along with this direction, maybe the programer's work will change huge, because it says: functional programming, whose objective is to describe what a program is doing at every step rather than how it is doing it. That is, you say “sort” rather than describing the sort. In a expand notion: if you want to get an application, you just need only say to computer, do a program that should own the functions below: 1,...; 2, ...;

  Because the templete techniqe has raised in JDK5 (but I have never used this new feature:( ), maybe Bruce need rewrite his Type-safe iterators example.

 

3, My questions about the program itself;

  Too many, include: example PoolManager using Proxy, section Dynamic Proxies, and inner class, the "static" keyword in the inner class, all exercises, etc....

4, My questions about the english language;

  1), Strange words:

  surrogate, notion, tempt, lump, long-standing, front for, speak for, at odds, orthogonal, tale, princess, awkward, aliasing, arbitrarily, specifics, through to, backend, backend Builder object, algorithms, algebraic, STL, candidates, problematic, iteration, establish, Decorator, Unpredictable, mood, copy-on-write, leasing

  2), Strange sentences;

    1>, as long as Proxy is somehow “speaking for” the class that it is referring method calls to then the basic idea is satisfied (note that this statement is at odds with the definition for Proxy in GoF).

    2>, how successful this approach will actually be remains to be seen.

**********************************************************************************************

//: state:StateDemo.java

// Simple demonstration of the State pattern.

 

                                          incomplete