Research on design pattern (1)

Source: Internet
Author: User

Written in the front of this series:

In the previous impression, the design pattern seems to be a very tall thing, but, want to go from a yard to an engineer, how can get around it. Helpless, looking for a variety of design patterns of the book, thanks to their own experience in a variety of languages, has learned java,php,javascript design patterns, finally to the design model has a smattering understanding, so, think of their own understanding of things to record a bit, For later use (amnesia required skills).

Why Study Design Patterns

1. Design reusable object-oriented applications; (the card will not be penalized by the routine)
2. Improve programming efficiency and reduce repetitive coding; (not copy and paste)
3. Help programmers to quickly determine the solution of the system; (reuse or slightly modify the previous scenario)
4, help to build a modular system, reduce the coupling between the modules; (Hold the whole body without moving)

About the design pattern itself

    模式名称:能够形象的表示该模式的核心功能或效果    问题:该模式能够解决哪些问题    解决方案:该模式具体的工作原理与方式    效果:使用该模式设计之后较不使用该模式有什么明显的提升效果;

After learning each of the patterns are also targeted at these four points to thoroughly understand it!

More prep Work

1, the model according to the purpose can be divided into:

创建型:与对象的创建有关,基本模式为工厂方法模式;结构型:处理类或对象的组合,基本模式为代理模式;行为型:对类或对象怎样交互和怎样分配职责进行描述,基本模式为注册模式;

2, according to the scope of action, divided into class mode and object mode. Class mode handles the relationship between classes and subclasses, which are determined at compile time, and the object schema handles the relationship between objects, more dynamic

3, customer request is the only way to make an object perform operations, and the object is the only way to change the internal data;

4, strictly reflect the current real-world model does not produce and can reflect the future of the world's system-so we need a higher level of abstract class.

5, the so-called object granularity refers to the size of the object and the number of measurement results.

6, the request sent to the object and its corresponding operation at run time of the connection is called dynamic binding

7. Dynamic binding allows you to replace objects with the same interface at run time, which is called polymorphic

8. The implementation of an object is determined by the class, which specifies the internal data and representations of the object, and also defines the actions that the object can perform. Objects are created by instantiating the class.

9. The new class can be defined by inheriting the existing class (note that the object is created, and the class is defined!!). ), the subclass inherits all the data and operations defined by the parent class when inheriting the parent class. The instance object of the subclass contains all the child classes and the data defined by the parent class, and they can complete all the actions defined by the child class and the parent class.

10. The purpose of an abstract class is to define a public interface for its subclasses. The abstract class takes its// part or all ///(note that here can be a partial, meaning that an abstract class can implement partial operations in itself) by delaying the implementation of the operation into the subclass (these operations are not to be implemented in the abstract class itself, but to write an empty method).

11, abstract class can not be instantiated!!!

12. Operations defined in an abstract class that are not implemented are called abstract operations.

13. Mixed Class (Mixin) is a class that provides alternative interfaces or functions to other classes, which cannot be instantiated and require multiple inheritance.

14, for the interface programming, but not for the implementation of programming.

    不将变量声明为某个特定的具体类的实例对象,而是让它遵从抽象类所定义的接口。

15. The two most common techniques for functional reuse in object-oriented systems are class inheritance and object composition.

16, class inheritance can be more convenient to change the implementation of the reuse, but it is no longer possible to change the implementation of the inherited from the parent class, and to break the encapsulation, because the parent class is missing the details of the class, and the change of the parent class will inevitably cause changes in the subclass, increased coupling.

17. Object composition is dynamically defined at run time by obtaining a reference to another object. Because of the "black-box reuse" nature, objects are referenced through interfaces to each other and do not compromise encapsulation, and it can reduce the size of class inheritance.

18. Prioritize the use of object combinations rather than class inheritance.

理想情况下,你不应为获得复用而去创建新的构件,因为使用对象组合技术可以获得你需要的功能。

19, the delegate is a combination of methods, it makes the combination with the same reuse capacity of inheritance. The object that accepts the request delegates the operation to its agent (similar to the subclass that the child class handles the request to its parent class). Delegate mode in order for the delegate operation to refer to the object that accepts the request, it passes itself to the delegate (equivalent to this reference).

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Research on design pattern (1)

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.