The implementation of page inheritance in asp.net and the implementation of factory pattern of common page

Source: Internet
Author: User
Tags constructor inheritance
Asp.net| Inheritance | page is most recently used. NET when doing a Web project encountered some problems, that is, many of the page processing the same, is not the same as we write stored procedures are different, in order to consider the reuse of code and maintainability and can

extensibility, so wrote a document page for the factory model, using the interface of the inheritance technology, because we write the ASP.net page is the code, so we inherit the time we inherit the code, that is, we say the XXXX.aspx.cs file. In fact, the inheritance of the page and our ordinary class inheritance, just ASP.net page interface is the HTML and post code together, so there are some different, good advanced start our ASP.net page inheritance tour:

I have summed up here an intuitive understanding of the UML diagrams generated by rational xde in the. NET environment, and I will first explain some of the classes in this diagram and their relationships, the Billfactory class is the document factory that I defined to identify the document that produced it, Virturbillcom is a virtual class (also can be an interface) it defines some methods for inheriting its classes to implement, ISSUEBILLMNG_FRM and issuebill_frm are pages of the back code class, responsible for some of the page operations such as Button state, invoke business logic, etc. Billinstoragemnglist and issuebillmng respectively inherit virturbillcom virtual classes to achieve business processing call data storage layer, billinstoragemnglist responsible for the processing of warehousing orders, ISSUEBILLMNG is responsible for the processing of the library list. Billentity and Billitementity are entity classes for database mapping. BILLINSTORAGEMNG inherits the page class Issuebillmng_frm,billinstorage inheriting class page class Issuebill_frm, you can see, The Billinstoragemng class and the Billinstorage class are inherited by inheriting class page classes, so there is only one empty constructor in their class, others can be handled by its parent class, where you may want to ask, so that you can complete the inheritance of the page? , hehe, this is just one step, in order to achieve the same effect as the page of the parent class, you must copy HTML from the parent class to the HTML of the subclass so that the interface is displayed (if you want to change the interface to change the Add button in the HTML of the subclass interface), the problem is, When you copy HTML to a subclass of a page in the. NET Designer, when you enter the post code for the subpage, the server controls on the page are automatically added to the variable declaration where we can imagine that the controls already exist in the parent class and that the default is the protection type protected so subclasses can also see the So the control repeats, it's very wrong, you have to delete the control variable that the parent class has already used in the subclass, if the subclass itself wants to have other actions to join the control itself, but the variable cannot be duplicated with the parent class. This is very simple to complete the inheritance of the page, you can try, it can reduce a lot of duplicate code.

And what I want to say is the Billinstoragemnglist class and the Issuebillmng class, they all inherit virturbillcom implement the virturbillcom defined functions, they are the middle layer, So we call in the page can be called directly virturbillcom, the actual implementation of which instance by Billfactory to achieve, this may still not understand, specifically said in Issuebillmng_ In the constructor of frm (the page's constructor defaults to No, our own) declares an instance of virturbillcom such as: Mgrobr = Billfactory (this); Use the factory to judge the instance of the middle-tier variable to do different work. This is the simple factory model, you can not understand the design pattern. OK today to say this, what do not understand can be discussed, although my expression may be some places are not very clear, we can take a good look at this picture, is a typical factory model diagram, well it's time to go home. I wish you all a pleasant evening.


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.