Page inheritance in ASP.NET implementation and general page factory implementation

xiaoxiao2021-03-06  108

I have encountered some problems when I use .NET to do a web project, it is the same as a lot of pages. Different is that the stored procedures we write are different, in order to consider the reuse and maintainability of the code.

Scalability, so I wrote a factory mode of the document page, using the interface inheritance technology, because we write the ASP.NET page is the postage of the code, so we inherit our post-posted code when we inherit. It is the xxxx.aspx.cs file we say. In fact, the inheritance of the page is the same as our ordinary class, just the interface of the ASP.NET page is integrated with HTML and the rear code, so there are some different, good advanced starting our ASP.NET page inheritance journey:

I have summarized a UML map generated by the Rational XDE in the .NET environment, I will first let the classes in this pair and their relationships, the BillFactory class is the documents I defined. It is a virtual class (or interface) that it defines some ways to implement it, IssueBillmng_FRM and ISSUEBILL_FRM are the rear code class of the page, such as some operations for the page, for example , Button status, call business logic, etc., BillInStorageMnglist and IssueBillmng separately inherit the VirturbillCom virtual class to implement business processing calling data storage layer, etc., BillInStorageMNGLIST is responsible for the processing of the library, IssueBillmng is responsible for the processing of the library. Billentity and Billitementity are the physical classes of the database map. BillInStorageMng inherits the page class issuebillmng_frm, billInstorage inherited page class issuebill_frm, you can see that the BillInStorageMng class and the BillInstorage class are only an empty constructor in their classes, and the other can be Class processing, here everyone may ask, this can you complete the inheritance of the page? , Huh, this is just one of the steps. In order to achieve the same effect to achieve the parent class, you must copy the HTML in the parent class to the html of the subclass, which is the same as the display (if you want to change the interface) Change the add button in the html of the subclass interface, but there is a problem that when you copy the HTML to the subclass in the .NET Designer, you will automatically add the page when you enter the back code of the sub-page. Server controls are placed in variable declarations, we can imagine that these controls already exist in the parent class and the default is that the protected type is protected, so the subclass can also be seen, so the control will repeat, it is wrong, must be in the child Delete the control variable used by the parent class in the class. If the subclass you want to have other operations to join the control, but the variable cannot be repeated with the parent class. This is very simple to complete the inheritance of the page. You can try it, it can reduce a lot of repetitive code.

There is also what I want to say is the BillInStoragemnglist class and the Issuebillmng class. They all inherit the VirturbIllcom to implement the function of the Virturbillcom defined. They are the middle layer, so we can call VirturbIllcom directly when they call, which instance of the specific real implementation BillFactory is implemented, this may not understand, specifically, in the constructor of Issuebillmng_FRM (the page constructor is not available by default, our own plus) declares an instance of a Virturbillcom such as: mgrobr = BillFactory (this); Use the factory to determine the intermediate layer variable of the instance to complete different work. This is the simple factory model, you don't understand the design model. I said this today, I don't understand anything, can be discussed, although my expression may be less clear, everyone can take a look at this pair, is a typical factory model, ok, the next get off work go home . I wish you all a happy evening. Author: moshangchen

转载请注明原文地址:https://www.9cbs.com/read-102651.html

New Post(0)