"Dahua design mode" notes three

Source: Internet
Author: User


Do not know how to do the information of the peers, whether there is such a feeling, an enterprise's informatization success or failure to a large extent depends on the company's leadership of the knowledge level and the understanding of information, I now have the feeling of cutting, people are very frustrated, often a software implementation to the leadership of this class will not go on, and some leaders even computers will not be used. So this time to say a few words, looking for work to the company's managers to investigate, lest to regret.


1. Template method Mode (Templatemethod):

A template method pattern is defined as trying to extract the same code into the parent class, leaving different code in the subclass. This pattern I often use, for example, to initiate a workflow in a workflow, except for the services of different templates that are invoked, the code is the same. So you can extract the code into a parent class, inheriting the parent class through subclasses, and you can also complete the subclass's own actions.

1/**////Parent Class
2public Class Parent
4 public virtual void OP1 ()
5 {
6 Console.WriteLine ("Parent OP1");
8 Public virtual void OP2 ()
9 {
Console.WriteLine ("Parent OP2");
13/**////sub-Class A
14public class Sona:parent
15 {
public override void OP1 ()
17 {
Base. OP1 ();
Console.WriteLine ("SonA OP1");
public override void OP2 ()
22 {
Base. OP2 ();
Console.WriteLine ("SonA OP2");
27/**////Sub Class B
28public class Sonb:parent
29 {
public override void OP1 ()
31 {
Base. OP1 ();
Console.WriteLine ("Sonb OP1");
public override void OP2 ()
36 {
Panax Notoginseng Base. OP2 ();
Console.WriteLine ("Sonb OP2");
41/**////Call method
The static void Main (string[] args)
43 {
SonA a = new SonA ();
A.OP1 ();
A.OP2 ();
SONB b=new sonb ();
B.OP1 ();
B.OP2 ();

Give me the feeling a bit like decorating mode.

2. Dimitri Law (LOD):

My understanding is to improve the cohesion of classes and reduce the coupling between classes and classes. Try not to expose the design details of the class, only provide the interface to the point of the three-party call.

Implementation should be the interface or Factory mode bar.

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.