Design Patterns: A summary of reusable object-oriented Software basics (top)

Source: Internet
Author: User

Chapter I. INTRODUCTION
1. What is design mode?
Design patterns are the core solutions that people use to solve similar problems and solve such problems. Design patterns are used to implement design reuse.
2. Four elements of design pattern
Name: Describes the problem, solution, and effect of the pattern. Names help people communicate design ideas and design results.
Issue: Describes when to use the pattern. It describes design problems and the causes and consequences of problems.
Solution: Describes the components of the design, their interrelationships, their responsibilities, and how they collaborate.
Effect: Describes the effect of the pattern application and the problem that the usage pattern should weigh.
3. How does this book describe a design pattern?
Describe the pattern name and classification, intent, alias, motivation, applicability, structure, actor, collaboration, effect, implementation, code example, known app, and related patterns.
4, design mode How to solve the problem
1) Find the right object. Objects include data and operations on the data. Design patterns help you determine the abstractions that are not obvious and describe these abstractions.
2) determines the granularity of the object.
3) Specify the object interface. An interface is a collection of all the operations that an object provides.
4) Describes the implementation of the object. Programming the interface, not the implementation.
5) Use the reuse mechanism. The combination of objects is preferred instead of class inheritance.
6) The structure of the associated run time and compile time.
7) design should support change. A common cause of redesign is the creation of objects by displaying a class, dependencies on a particular environment, reliance on hardware and software platforms, reliance on object representations or implementations, algorithmic dependencies, tight coupling, expansion of functionality by generating subclasses, and the inability to easily modify classes.
5, how to choose the design mode
Here are a few different ways to do this:
1) Consider how the design pattern solves the design problem.
2) The intent portion of the browse mode.
3) How the research model relates to each other.
4) Study the pattern of similar purposes.
5) Check the reason for the redesign.
6) Consider what is mutable in your design.

Chapter Two case study
This chapter mainly combined with a text editor Lexi instance, in terms of the use of several design patterns, why these design patterns have been chosen.
If there is no contact with the design mode, I see this chapter is difficult to understand. You can read the following chapters first, and then look back at the chapter, perhaps with a new understanding.

Chapter III Creating Patterns
1. The two main themes in these patterns: they all encapsulate information about which specific classes the system uses, and they hide how instances of these classes are created and put together.
2. Abstract Factory Abstraction Factory
2.1 Intent: Provide an interface that creates a series of related or interdependent objects without specifying their specific classes. The factory class creates the interface, and the subclass implements the interface.
2.2 The abstract Factory mode can be used in the following cases:
1) A system is independent of the creation, composition, and presentation of its products.
2) When a system is to be configured by one of multiple product families.
3) When you want to emphasize the design of a series of related product objects for joint use.
4) When you provide a Product class library and just want to display their interfaces instead of implementing them.
3. Builder Builder
3.1 Intent: To separate the construction of a complex object from its representation so that the same build process can create different representations.
3.2 Use this mode in the following situations:
1) When creating complex objects, the algorithm should be independent of the parts of the object and how they are assembled.
2) When the construction process must allow the constructed object to have different representations.
3.3 The difference from the abstract factory: The build pattern focuses on constructing a complex object in one step, returning the product in the last part; Abstract factory focuses on multiple series of product objects (simple or complex), and the product returns immediately.
4, Factory Method factory methods
4.1 Intent: Define an interface for creating objects, and let subclasses decide which class to instantiate. This pattern defers the implementation of one class to other subclasses.
4.2 This mode can be used in the following cases:
1) When a class does not know the class of the object it must create.
2) When a class wants to specify the object it creates by its subclasses.
3) When the class delegates the responsibility of creating an object to one of several helper subclasses, and you want to use which helper subclass is the proxy for this information when it is localized.
5. Prototype prototype
5.1 Intent: Use the prototype instance to specify the kind of object to create and create a new object by copying the prototypes.
5.2 When a system should be independent of its product creation, composition, and representation, use this pattern, as well:
1) When the class to be instantiated is specified at run time, for example, by dynamic loading, or
2) in order to avoid creating a factory class hierarchy that is parallel to the product class level;
3) When an instance of a class can have only one of several different state combinations. Building the corresponding number of prototypes and cloning them may be more convenient than manually instantiating the class each time you use the appropriate state.
6. Singleton single Piece
6.1 Intent: Ensure that a class has only one instance and provides a global access point to access it.
6.2 The pattern can be used in the following cases:
1) When a class can have only one instance and the customer can access it from a well-known access point.
2) When this unique instance should be extensible by subclasses, and the customer should be able to use an extended instance without changing the code.

Design Patterns: A summary of reusable object-oriented Software basics (top)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.