What can we learn from Microsoft's dbml files (it tells us what is the top priority of Microsoft )~ Does the three branch categories undermine a single responsibility?

Source: Internet
Author: User

A dbcontext constructor, method Overloading

In the binary dbcontext instance, how is a table object added?

Does the three branch categories undermine a single responsibility?

The four-segment method defines the type operation specifications from the other hand.

5. assign values to attributes in the LINQ object class. Before and after the changes, sendpropertychanging and sendpropertychanged

Six linqtosql triggers sendpropertychanging and sendpropertychanged for us. What is its true intention?

7. The dbcontext object should be used as the base class of other object operation types and provide unified submission actions for it.

 

 

Let's take a look at the definition of a single responsibility in "Baidu Encyclopedia": There is only one reason for its change in a class. There should be only one responsibility. Every responsibility is a changing axis. If a class has more than one responsibility, these responsibilities are coupled. This leads to a fragile design. When a responsibility changes, other responsibilities may be affected. In addition, coupling of multiple responsibilities will affect reusability. For example, you need to separate the logic from the interface.

The partition class (partial) is also a new thing of. net. It should have appeared at 2.0 correctly. The definition on msdn is as follows:

You can split the definition of classes, structures, interfaces, or methods into two or more source files. Each source file contains a part of the type or method definition to compile the application.ProgramAll parts are combined.

In my understanding, when a class cannot complete or is not sure about all the functions of the class during a period of time, you can first define this class as partial, it allows you to supplement the same class in another place. This technology is widely used by Microsoft on the LINQ to SQL. Of course, for various reasons, in my opinion, this kind of use has damaged the single responsibility principle of the class. In fact, it is only a supplement to the class with the same responsibility, the class still needs to complete those things, but it is not sure what to do or how to do it. When it knows how to implement it, it can define a partial to improve it. TheCodeIt is automatically generated by IDE, so some things are not enough for developers, and Microsoft certainly knows all of this, so it is designed as partial, so that programmers can supplement the class as needed, rather than expand.

 1 [ Global : System. Data. LINQ. Mapping. tableattribute (name = "  DBO. web_exceptionlog  "  )]  2       Public   Partial  Class  Web_exceptionlog: inotifypropertychanging, inotifypropertychanged  3   {  4   5           Private   Static Propertychangingeventargs emptychangingeventargs = New  Propertychangingeventargs (string. Empty );  6   7           Private   String _ Exceptionid;  8   9           Private   String  _ Fullinfo;  10   11           Private   String  _ Senders;  12   13           Private   String  _ Httpmethod;  14  15           Private  System. datetime _ occurtime;  16   17 // ......

 

This is an entity object of the IDE's automatically generated LINQ to SQL. We hope to supplement this class. The subsequent code is as follows:

 
 
 1   Public   Partial   Class  Web_exceptionlog: entity. entitybase  2   {  3          Protected  Override   Object  [] Primarykey  4   {  5              Get { Return   New   Object [] { This  . Exceptionid };}  6   }  7   8         Public   Override Ienumerable <ruleviolation> Getruleviolations ()  9   {  10              Throw   New  Notimplementedexception ();  11   }  12 }
 
 

 

 
 

Therefore, it is inaccurate for the Division class to destroy the single responsibility of the type. Just like a good thing, the Power Shown in different people is also different. The truth is the same. Haha.

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.