Chapter Intro to design Patterns
Chapter No. 01 Introduction to Design Patterns
1. Design principle identify the aspects of your application that vary and separate them to what the stays. (P9)
Design principles: Find out where applications may need to change, separate them, and don't mix with code that doesn't need to change.
2. Design principle-an interface and not a implementation. (P11)
Design principles: Programming for interfaces, not for implementation.
3. Design principle favor composition over inheritance. (P23)
Design principle: Multi-use combination, less inheritance.
4. The strategy pattern defines a family of algorithms, encapsulates each one, and makes them. Strategy lets the algorithm vary independently from clients this use it. (P24)
Policy pattern: Defines the algorithm family, encapsulates each other, so that they can replace each other, this mode makes the change of the algorithm independent of the client using the algorithm.
Chapter The Observer pattern
NO. 02 Chapter Observer mode
1. The Observer pattern defines a one-to-many dependency between objects so, one object change state,all of its depend Ents are notified and updated automatically. (P51)
Observer mode: Defines a one-to-many dependency between objects, so that when an object changes state, all its dependents are notified and automatically updated.
2. Design principle strive for loosely coupled designs between objects. (P53)
Design principles: For the interaction between the loosely coupled design efforts.
3. Loosely coupled designs allow use to build flexible OO systems This can handle change because they minimize the Interde Pendency between objects. (P53)
Loosely coupled design allows us to build resilient OO systems that can cope with change because the interdependence between objects is minimized.
Chapter the decorator pattern
No. 03 Chapter Decorator Mode
1. Design principle Classes should is open for extension, but closed for modification. (P86)
Design principles: Classes should be open to extensions and closed for modifications.
2. Be careful when choosing the areas of code this need to be extended; Applying the open-closed principle everywhere is wasteful, unnecessary, and can leads to complex, hard to understand code. (P87)
Be careful when selecting the part of the code that needs to be expanded. It is wasteful and unnecessary to use the open-close principle everywhere, and the code becomes complex and difficult to understand.
3. The decorator pattern attaches additional responsibilities to an object dynamically. Decorators provide a flexible alternative to subclassing for extending functionality. (P91)
Decorator mode: Dynamically attaching responsibility to an object. To extend functionality, adorners provide a more flexible alternative than inheritance.
4. But Java I/O also points out of the downsides of the decorator A large number of small classes that can is overwhelming to the developer API. (P101)
But Java I/O also leads to a "disadvantage" of the decorator pattern: the use of decorator patterns often results in a large number of small classes in the design that are too numerous to be bothered by programmers using this API.
Chapter The factory pattern
No. 04 Chapter Factory mode
1. The Factory method pattern defines a interface for creating a object,but lets subclasses decide which class to Instan Tiate. Factory method lets a class defer instantiation to subclasses. (P134)
Factory method Pattern: Defines an interface to create an object, but the subclass determines which is to be instantiated. The factory method lets classes defer instantiation to subclasses.
2. Design principle Depend upon abstractions. Do not depend upon concrete classes. (P139)
Design principles: To rely on abstractions, do not rely on specific classes.
3. The Abstract Factory pattern provides a interface for creating families related or dependent objects without Specifyin G their concrete classes. (P156)
Abstract Factory Pattern: Provides an interface for creating a family of related or dependent objects without explicitly specifying a specific class.
4. The intent of Factory method are to allow a class to defer instantiation to its subclasses. (P162)
The factory method allows the class to defer instantiation to a subclass.
5. The intent of Abstract Factory is to create families of related objects without have to depend on their concrete clas Ses. (P162)
Abstract factories create related object families without having to rely on their specific classes.
Chapter the singleton pattern
No. 05 Chapter Single Case mode
1. The Singleton pattern ensures a class has only one instance, and provides a global point of access to it. (P177)
Singleton mode: Ensures that a class has only one instance and provides a global access point.
Chapter the command pattern
No. 06 Chapter Command mode
1. The Command pattern encapsulates a to request as an object, thereby letting for you parameterize other objects with different Requests, queue or log requests, and support undoable operations. (P206)
Command mode: Encapsulates a request into an object to parameterize other objects with unused requests, queues, or logs. The command mode also supports revocable operations.
2. The Command pattern decouples an object making a request from one this knows how to perform it. (P230)
The command mode decoupled the object that made the request and the object that executed the request.
Chapter the Adapter and Facade Patterns
No. 07 Chapter Adapter mode and Appearance mode
1. Here's how the client uses the Adapter (P241)
1.1 The client makes a request to the adapter by calling a method on it using the target interface.
1.2 The adapter translates that request to one or more calls on the adaptee using the Adaptee interface.
1.3 The client receives the result of the ' call and never ' knows there is a adapter doing the translation.
The client uses the adapter in the following process:
1.1 The client makes a request to the adapter through the method of calling the adapter through the target interface.
The 1.2 adapter converts the request into one or more calling interfaces of the adaptor using the adaptor interface.
1.3 The client received the result of the call, but was unaware that all this was the adapter in the act of converting
2. The Adapter pattern converts the interface's a class into another interface the clients expect. Adapter lets classes work together that couldn ' t otherwise because of incompatible interfaces. (P243)
Adapter Mode: Converts the interface of a class into another interface that the client expects, and the adapter makes the classes incompatible with the original interface work seamlessly.
3. A façade not only simplifies a interface, it decouples A-client from a subsystem of components. (P260)
The appearance pattern not only simplifies the interface, but also decoupling the customer from the subsystem of the component.
4. Facades and adapters may wrap multiple classes, but a façade ' s intent is-to-simplify, while a adapter ' s are to convert The interface to something different. (P260)
Skins and Adapters can wrap many classes, but the intent of the appearance is to simplify the interface, and the intent of the adapter is to transform the interface into different interfaces.
5. The façade pattern provides a unified interface to a set of Interfaces Inn a subsystem. The façade defines a higher-level interface that makes the subsystem. (P264)
Appearance mode: Provides a unified interface for accessing a group of interfaces in a subsystem. The appearance defines a high-level interface that makes the subsystem easier to use.
6. Design principle principle of least knowledge-talk a to your immediate. (P265)
Design principles: Minimum knowledge principles, only talk to your close friends.
7. The principle tells us that we are should only invoke methods which belong to: (P266)
The object itself
Objects passed in as a parameter to the method
Any object the method creates or instantiates
Any components of the object
This principle tells us that we should call the following methods:
Object itself
An object that is passed in as a parameter to a method
Any object created or instantiated by this method
All components of an object
Chapter the template method pattern
No. 08 Chapter Template Method mode
1. The Template method defines the steps of a algorithm and allows to subclasses the provide for one or MO Re steps. (P286)
The template method defines the steps of an algorithm and allows subclasses to provide implementations for one or more steps.
2. The Template method is defines the skeleton of the algorithm in a, and deferring some to STEPSS. Template method lets subclasses redefine certain steps of the algorithm without ' changing. (P289)
Template method Pattern: Defines the skeleton of an algorithm in a method, and delays some steps into subclasses. The template method allows subclasses to redefine some of the steps in the algorithm without changing the structure of the algorithm.
3. The Hollywood principle Don ' t call us, we'll call you. (P296)
Hollywood rule: Don't call us, we'll call you.
Chapter the iterator and composite pattern
No. 09 Chapter iterator and combination mode
1. The iterator patternprovides a way to access the eleemnts of ' a aggregate object sequentially without exposing its unde Rlying respresentation. (P336)
The iterator pattern provides a way to sequentially access individual elements of an aggregation object without exposing its internal representation.
2. Design Principle:a class should have only one reason to change. (P339)
Design principle: A class should have only one reason to cause change.
3. The composite pattern allows your to compose objects into tree structures to represent part-whole. Composite lets clients treat individual objects and compositions of objects uniformly. (P356)
Combination mode: Allows you to combine objects into a tree structure to represent the "whole/part" hierarchy. A combination enables customers to work with individual objects and groups of objects in a consistent way.
4. The composite pattern allows us up structures of objects in the form of trees that contain both compositions of O Bjects and individual objects as nodes. (P357)
The combination mode allows us to create the structure of the object in a tree form, which contains a combination and an individual object.
5. Using A composite structure, we can apply the same operations over both composites and individual. In other words, in most cases we can ignore the differences between compositions of objects and individual. (P357)
Using the composite structure, we can apply the same operation to the combination and individual objects. In other words, in most cases, we can ignore the difference between the combination of objects and the individual objects.
--------------------------------------------------
Author:cs_cjl
Website:http://blog.csdn.net/cs_cjl
--------------------------------------------------
Chapter
10th Chapter State Mode
1. The state pattern allows a object to alter its behavior as its internal state changes. The object would appear to change its class. (P410)
State mode: Allows an object to change its behavior as the internal state changes, and the object appears to modify its class.
Chapter the proxy pattern
11th Chapter Agent Mode
1. By invoking methods in the proxy, a remote call are made across the wire and a String, an integers and a state object are Returned. Because we are using a proxy, the gumballmonitor doesn ' t know, or care, that calls are remote (other than has to worry a Bout remote exceptions). (P457)
By invoking the proxy method, a remote call can cross the network, returning strings, integers, and state objects. Because we are using proxies, the invoked method is executed remotely, and Gumallmonitor does not know/or is not at all (the only thing to worry about is to handle remote exceptions).
2. The Proxy pattern provides a surrogate or placeholder for another object to control access to it. (P460)
Agent mode: Provides an alias or placeholder for another object to control access to the object.
3. Use "Proxy pattern" to "Create a representative object" Controls access to another object, which may is remote, ex Pensive to create or in need of securing. (P460)
Using proxy mode to create a representative object that controls the access of an object on behalf of an object, the object being represented can be a remote object, create an expensive object, or an object that requires security control.
Chapter Compound Patterns
12th Chapter Compound Mode
1. Patterns are often used together and combined within the same design solution. (P500)
Patterns are commonly used together and are grouped together in the same design solution.
2. A compound pattern combines two or the patterns into a solution that solves a recurring or general problem. (P500)
Conforming mode combines two or more patterns in one solution to solve a common or recurring problem.