C # design patterns-Overview

Source: Internet
Author: User
The design pattern seems very fashionable, but it is very practical because it makes the solution elegant, simple, and reusable. the design pattern seems very mysterious. In fact, the design pattern is just a simple method to reuse object-oriented code between projects and programs. the idea behind it is very simple. It records and cataloguing the interaction between common objects. for martial arts, this is like a routine. Of course it is a classic or MVC framework. The framework is designed to describe how objects communicate so that mutual data models and methods are not involved, in fact, it is the same as the goal of High Cohesion and low coupling in software engineering. This is also the goal pursued by the model and also the target pursued by the object-oriented model.

As mentioned earlier, low coupling refers to separation classes, including encapsulation and inheritance. For inheritance, a subclass can inherit all methods of the parent class and all non-private variables, therefore, a base class is not written too detailed. This is a principle of the design pattern.

"For interface programming,Instead of programming"

 

In fact, if you have done winform and used inheritance, sometimes you may feel a headache, because C # only supports class single inheritance. If you inherit a form, it is too much trouble, if the base class has any problems, your child forms cannot be re-painted for display.

The second principle of the design pattern is:

Object combination is preferred,Instead of Inheritance

How to understand this sentence is very simple. We still achieve the goal of low coupling. We made this mistake in a project message system last year. I didn't read this book at the time.

Because a message system includes the underlying socket, command interpreter, Delegate, transmitter, middle layer, and GUI. if the relationship is not well handled, the system structure is quite poor.

If you look at the example of the design pattern, especially the Observer Pattern and intermediary pattern, you will find that it embodies the principles of the above two design patterns everywhere, please remember them again

 

1.For interface programming,Instead of Programming

2.Object combination is preferred,Instead of Inheritance

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.