Introduction to delayed loading in C # (3) -- restore the business rules of the Model

Source: Internet
Author: User

Ah ~~ Recently, I spent my spare time modifying my blog. I found many foreign spam ads on the message board of my website during this time. " IP blacklist " Functions, messages andArticleThe verification code is also added to the comments.CodeI sorted it out. I hope that the newly added verification code will not cause inconvenience to comments and comments!


Today, a friend posted a message in the blog Park saying how to complete the blog. Sorry, I am changing my blog when I am free. 555 ~

The article is still transferred in his blog, the original address: http://www.youguanbumen.net/Article.aspx? Id = 74

[Original content]

In the previous article, we talked about declaring the attribute to implement delayed loading in the object class as virtual, and then inheriting the object class as a subclass to implement this attribute in the subclass, works with delegates to achieve perfect latency loading (the original "model layer" is still kept at the bottom layer for the layer-3 structure, at the same time, you can access the "data access layer" higher than others in the attributes of the object class). At the end of the article, there is still a cup of cake because this attribute may be required by our business before the model attribute is delayed, it is not just used as a storage and read function, but contains this complicated or simple logic code in its get or set accessors.

For example, consider this scenario. We have an entity class called a task list, which has two attributes: "Task Name" and "release time ", there are business rules that the task name can be blank, however, if the task name is blank, We need to read the "release time" to generate a task name to replace this null value (for example, "issue20110120191345"). Of course, this example is somewhat far-fetched, the main reason is that I can't think of a very specific instance, but in actual development, this is certainly the case, and the logic code in it may be complicated to your imagination.

Following the examples in the previous two articles, I simulated this phenomenon and made some modifications to the "article" object class, adding a string attribute named getcategoryrecord, basically, it can be seen from the literal that it is called "The get accessor call record of the category attribute ". Therefore, the "article" Class (base class) is modified as follows:

C # code ?
12345678910111213141516171819202122232425262728293031
Related Article

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.