Thinking in Patterns Chapter 1: introduction

Thinking in Patterns with Java V0.9:  Chapter 1: introduction: TIPatterns.htm#_Toc41169679

1, The sections name of today's learning;

    The Y2K syndrome. 11

    Context and composition. 12

    A word about checked exceptions  13 

2, What is it talk about in these sections?

   Even my english is poor, but in order to learn it, I will write some my viewpoints of the content. After finishing read this book once, and to see a chinese version of this book, maybe I will rewrite some words at here.

   First, I am amused the term GoF is conerned with that well-known four persons in China include JiangQing, WangHongWen, etc..

  The first part tells us, you must have learned some basic OOP and have used Java some time, then you can read this book, it isn't for a beginer of Java or program.

  In section The Y2K syndrome, it tells us, focus on the key that is really the bottleneck of system, usually, only 10% code is this key, don't perform some optimization according to your own thinking without deeply testing. I think Bruce put these words at this location of this book, the meaning maybe is Design Patterns can be used at the key part of system(only 10%), for non-key part, you don't think the Design Patterns should be used everywhere.

  Bruce introduces two terms which is Context and composition, maybe he thought these two terms is very important in the Design Patterns? Because I haven't read some basic knowledge about Design Patterns, so I can't understand these two terms well. But I should remeber these words: "The context object allows you to use the pattern in a composition, and that may be it’s primary value.". Maybe I can understand these after reading this book.

  In fact, I don't think Bruce should put the content about "checked exceptions" at here, to Design Patterns, how important the "checked exceptins" is? In these part, I know Bruce discontented the "checked exceptions" in C++ and Java except Python. This part I can't understand it well, but I can get one is: "I intend to put a lot more RuntimeExceptions into my Java code".

  

3, My comments and feeling for the content?

  no.

4, My questions about the program itself;

  1), What on earth is Context object in the Design Patterns ?

5, My questions about the english language;

  1), Strange words:

  evolve, rudimentary, syndrome, subtitle, pitfall, terms, as far as, predicting doom, as if, premature, virtually, happen, particular, facade, knowledge, silly, past, dominate, landscape, turn around, intrude, go up, vanish, ream, opposite, tongue-in-cheek, widow, demonize, chronicle

  2), Strange sentences:

  Y2K syndrome:

  1>, Also,everyone seems to reserve in their own mind a special case ?except for this thing that I happen to know is a particular problem.?

  2>, these things aren?t so difficult after all, if I can see such an obvious problem.

  3>,  As a result, I know that many

embedded systems have no idea what the date or time is, and even if they do

that data often isn?t used in any important calculations. And yet I was told in

no uncertain terms that all the embedded systems were going to crash on January

1, 2000. As far as I can tell the only memory that was lost on that particular

date was that of the people who were predicting doom ? it?s as if they had

never said any of that stuff.

  4>, ?We should forget about small efficiencies, say about 97% of the time:

Premature optimization is the root of all evil.??Donald Knuth

  5>, My experience with Python exceptions supports this, and unless I get turned around on this issue I intend to put a lot more RuntimeExceptions into my Java code.

                                           incomplete

Outline of Thinking in Patterns with Java

Today, I found it can't sperate chapters in w3m brower in text mode of Linux. So, copy the Contents section at here, and seperate chapters by indenting the character. It hasn't indented After the line consist of "*".

Contents

Preface  8

Introduction  11

    The Y2K syndrome. 11

    Context and composition. 12

    A word about checked exceptions  13

The pattern concept 15

    What is a pattern?. 15

    Pattern taxonomy. 17

    Design principles. 18

    Classifying patterns. 19

    The development challenge. 21

    Unit testing. 21

        Location of test code. 22

Simplifying Idioms  22

    Messenger. 22

    Collecting Parameter. 24

Object quantity  25

    Singleton. 25

        Exercises. 27

    Object pool 27

        Exercises. 30

Object decoupling  30

    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

Factoring commonality  47

    Strategy: choosing the algorithm at run-time  48

    Policy: generalized strategy. 50

    Template method. 50

        Exercises. 52

Encapsulating creation  52

  Simple Factory method. 53

  Polymorphic factories. 55

  Abstract factories. 58

  Exercises. 61

Specialized creation  61

  Prototype. 61

  Builder. 62

  Exercises. 66

Too many  66

  Flyweight: too many objects. 66

  Decorator: too many classes. 69

    Basic decorator structure. 70

    A coffee example. 70

    Class for each combination. 70

    The decorator approach. 73

    Compromise. 78

    Other considerations. 82

    Exercises. 83

Connecting different types  84

  Adapter. 84

  Bridge. 87

  Exercises. 93

Flexible structure  93

  Composite. 93

System decoupling  95

  Observer. 95

    Observing flowers. 97

    A visual example of observers. 101

  Mediator. 103

  Exercises. 104

Reducing interface complexity  104

  Façade. 105

    Package as a variation of Façade  106

Algorithmic partitioning  106

  Command: choosing the operation at run-time  106

    Exercises. 109

  Chain of responsibility. 109

    Exercises. 112

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

Externalizing object state  113

Memento. 113

Complex interactions  114

Multiple dispatching. 114

Visitor, a type of multiple dispatching  117

Exercises. 119

Multiple languages  120

Interpreter motivation. 121

Python overview.. 122

Built-in containers. 123

Functions. 124

Strings. 125

Classes. 127

Creating a language. 130

Controlling the interpreter. 134

Putting data in. 134

Getting data out. 140

Multiple interpreters. 143

Controlling Java from Jython  144

Inner Classes. 148

Using Java libraries. 148

Inheriting from Java library classes  150

Creating Java classes with Jython  151

Building the Java classes from the Python code  156

The Java-Python Extension (JPE)  157

Summary. 157

Exercises. 158

Complex system states  159

StateMachine. 159

Exercises. 169

Table-Driven State Machine. 169

The State class. 171

Conditions for transition. 172

Transition actions. 172

The table. 172

The basic machine. 173

Simple vending machine. 174

Testing the machine. 179

Tools. 180

Table-driven code: configuration flexibility  180

Table-driven code using anonymous inner classes  180

Exercises. 180

Pattern refactoring  181

Simulating the trash recycler. 182

Improving the design. 186

“Make more objects”. 186

A pattern for prototyping creation  189

Trash subclasses. 193

Parsing Trash from an external file  195

Recycling with prototyping. 198

Abstracting usage. 199

Multiple dispatching. 203

Implementing the double dispatch   204

The Visitor pattern. 211

A Reflective Decorator. 214

More coupling?. 219

RTTI considered harmful?. 220

Summary. 223

Exercises. 224

Projects  225

Rats & Mazes. 225

Other maze resources. 230

XML Decorator. 230

A: Tools  230

Ant extensions. 231

Array utilities. 232

Download this book at: http://www.mindviewinc.com/downloads/TIPatterns-0.9.zip

Thinking in Patterns Chapter 2: The pattern concept

Thinking in Patterns with Java V0.9:  Chapter 2: The pattern concept: TIPatterns.htm#_Toc41169683

1, The sections name of today's learning;

    What is a pattern?. 15

    Pattern taxonomy. 17

    Design principles. 18

    Classifying patterns. 19

    The development challenge. 21

    Unit testing. 21

        Location of test code. 22

 

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

  At first, Bruce introduce the famous GoF's Design Patterns which show 23 design patterns, the very good aspect in that book is: it shows a evolution process by a given example, tracking this example's step, we can see how the design patterns be applied in an application.

  1), In the section What is a pattern, Bruce gives us a definition of pattern in a wider area.

  He tells us, Pattern is the general good way for resolving a class of problems, and this way has used by many times.

  Design Patterns isn't only tied with design phase, sometimes it appears in analysis, or implementation phase.

  The concept of Design Patterns is also proper for designing program, the same concept is "separate things that change from things that stay the same".

  Again, Bruce put up with his viewpoint of the little part of a system cost the most resource. He calls this as "the vector of change." My understanding is: from the math's aspect, suppose Y=kX, if "k" is very big, then X plus a little, but Y will plus a lot. So we should use our Design patterns around these most import but with less code's part of the system.

  In the rest part of this section, Bruce tells us the goal of using Design Patterns is "to isolate changes in your code", from this pointview, "inheritance", "compostion", "iterator", these terms in the program which we have used before, all these can be a kind of "Design Pattern".

  2), Section Pattern taxonomy.

  According the degree of using pattern in a system, the ablility of reusing the design, Bruce put up with his categories in this aspect. From the less reusing to the most reusing, it is: Idiom, Specific Design, Standard Design, Design Pattern.

  3), Design principles.

  I think, every principle here can be extend to be a chapter, and this section can be written to a book. Because the less programing experience of mine, I can't understand some principle here, especially like: Principle of least astonishment (don’t be astonishing); Make common things easy, and rare things possible; Law of Demeter; Once and once only.

  I can't write anymore in this section, maybe it need me to add a new goal called: understand Bruce's Design principles:)

  4), Classifying patterns.

  The 23 patterns in Design Patterns written by C++ or smalltalk are classified into three purpose: Creational, Structural, Behavioral. Bruce will revisit these 23 patterns with Java. And put up with his own examples about it. I always like the examples in Thinking in Java. So I think I will get surprised in this book's examples too.

  With Bruce's own mind of classifying all these 23 patterns, he put up with two kinds of classifying methods, and all these two methods are different from GoF's.

  The first method is according to the structure of implementations. At last, Bruce chose the second method:  according to "the problems they solve". So, this will be a practical and very useful book. I like Bruce's choice:) I think if I meet some kind of design problem, I can find a proper patterns in term of the problem's class.

 

  5), The development challenge

  I don't understand what is Bruce talking about in this section, he give some development methods and some internet resource. These terms is concerned with Design Patterns? I don't know.

  6), Unit testing

  In this section, I can know, at first, Bruce use his own testing framework, later, Junit get well, so he simply recommend the defacto standard-Junit. Bruce says he don’t know how much influence he may have had on Junit's change. I think Bruce is proud for his unit testing framework in his early book of Thinking in Patterns 

If I haven't misunderstood this section's words:) He is a frank man, I think.

 

4, My questions about the program itself;

  1), Most of Section Design principles I can't undersand well. I know this is copied from Thinking in Java Edition 2, but I haven't understood these then. Maybe, seeing the translation of HouJie's can help me to understand these?

 

5, My questions about the english language;

  1), Strange words:

ibid, whet, mandatory, vocabulary, adequate, flexible, insightful, work out,

completeness, embody, realm, gradient, put another way, focal, taxonomy,

pollution, synonymous with, succession, perspective, turn out,  proposed,

astonishment, astonishing, pile onto, demeter, Subtraction, dizzying, quest,

quantity, chapter, indent, intent, accidental, Variation, complement, aforementioned,

orientation, illuminating, decent, occur to, other than, in favor of, definitely

maxim, maxim, little-known, recommend, defacto, adequate, not yet, strip out

  2), Strange sentences:

  1>, This should whet your appetite to read Design Patterns by Gamma, et.

al., a source of what has now become an essential, almost mandatory, vocabulary

for OOP programmers.

  2>, Here, ?vector? refers to the maximum gradient and not a container class.

  3>, One of the events that?s occurred with the rise of design patterns is

what could be thought of as the ?pollution? of the term ? people have begun to

use the term to mean just about anything synonymous with ?good.?   

  4>, So, this principle acts as the tie breaker between otherwise equally viable design alternatives.

  5>, I believe this is a subtle but important distinction from the way Metsker organizes the patterns by intent in Design Patterns Java Workshop (Addison-Wesley 2002), because I hope that you will then be able to recognize your problem and search for a solution, if the patterns are organized this way.

  6>, When you download the code for this book, you will find (4/9/2003: Eventually, not yet) unit tests along with the code examples whenever possible.

                                           incomplete

Thinking in Patterns: Preface

Thinking in Patterns with Java V0.9: Preface: TIPatterns.htm#_Toc41169678

 1, The sections name of today's learning:

   Section: Preface

                              

 2, What is it talk about in this section?  

    This section is short, but it isn't no important. It tells us:

    1), this book come from Bruce sir and his friend's many years' experience.

    2), Bruce sir and his friend has a really good paterner relationship, they are really friend with same interesting.

    3), Bruce is focusing on Python now, but this book isn't stop writing.

 3, My comments and feeling for the content?                            

    Although this book written at 2003, and only version 0.9 now. I still want learn it, because I have read Thinking in Java, another book of his.

    I found I like his writing fashion, and all in the book reflect Bruce's wisdom, track the path he give us, I can learn Java with good interesting and well understanding. I haven't to do some more choice in learning books. Because I know I can get many from this book. Bruce has much experience in C++, JAVA, Python, OOP. So I think his Thinking in Patterns is must a good one, in the other words, must not a bad one.

    Bruce and his friend has a good friendship, this make them work happy together. They have good enviriment for their reseach.

 

 4, My questions about the program itself:

   no.                             

 5, My questions about the english language:      

   Too many, like below:

   Strange words:

   given the seminar, urge, pondering, appreciation, superb

   Strange sentence:

   I find this prospect to be much more exciting than the idea of struggling through another language tutorial.

准备用英文版的Thinking in Patterns学习设计模式

今天,正式把这本电子书的快捷方式放在桌面上,另外,下载安装了firefox的划词翻译插件:DictCN 2.2,用来翻译生词。

现在,网上已经有了这本电子书的中文版,但我还是想看英文版,因为想一举两得,既学了设计模式,又学了英语。我会把学习过程中碰到的包括语言在内的问题记下来。

现在,单位的事情不多,可以用这个时间认真学习一下设计模式。不过,单位的机器已经失盗,自己的那台老古董装的是文本模式的redhat linux 9.0,有空的时候在上面看看文章和网页还行,可就是碰到生词没有办法划词翻译。有点不爽。但是也只有将就了。

路还是要走的,不能因为怕走错路就一直呆在原地不动。学设计模式,开始吧。

也许我应该学习设计模式了

接触JAVA也有3年了吧,到现在还没有去看一看J2EE设计模式,别说J2EE设计模式,就是模式也没看,Bruce先生写了一本Thinking in Patterns(他也是经典的Thinking in java的作者),一直想看看,也没有时间去看。

今天早上,醒来睡不着了,在网上浏览看了一篇讲ebay的系统中如何借助了J2EE设计模式的好处,觉得自己真该去掌握一下。有机会,有时间的话,可以把这些设计模式看看。

一天十亿次的访问-eBay架构(原文地,不过其中的构架描述没有图片)

1、http://blog.csdn.net/yzhz/archive/2005/01/10/247116.aspx

2、http://blog.csdn.net/yzhz/archive/2005/01/10/247127.aspx

3、http://blog.csdn.net/yzhz/archive/2005/01/10/247133.aspx

4、http://blog.csdn.net/yzhz/archive/2005/01/10/247140.aspx

转载地(构架描述有图片)

http://www.zahui.com/html/6/41654.htm