Recently used. net encountered some problems when doing web projects, that is, the processing of many pages is the same, the difference is that the stored procedures we write are different, in order to consider the reuse and maintainability and availability of code
Scalability, so I wrote a factory model for the document page, using the interface inheritance technology, because the ASP.net page we wrote is post-code, so when we inherit, we inherit our post-code, that is, XXXX. aspx. cs file. In fact, the inheritance of pages is the same as that of ordinary class inheritance, but the interfaces of ASP.net pages are composed of HTML and post-code, so there are also some differences, now, let's start our journey to inherit from the ASP.net page:
Here I have summarized one in. the UML diagram generated by Rational XDE In the. net environment gives you an intuitive and perceptual understanding. I will first explain the relationships between classes and them in this diagram, the BillFactory class is the document factory that I defined to identify and generate that kind of document. mongourbillcom is a virtual class (or interface) that defines some methods for implementation by inheriting its class, issueBillMng_Frm and IssueBill_Frm are the post-code classes of the page. They are responsible for page operations such as button status and calling business logic, billInstorageMngList and IssueBillMng inherit the VirturBillCom virtual class to implement business processing and call the data storage layer. BillInstorageMngList is responsible for processing warehouse receiving orders, and IssueBillMng is responsible for processing warehouse picking orders. BillEntity and BillItemEntity are Entity classes mapped to databases. BillInstorageMng inherits the page class IssueBillMng_Frm, and BillInstorage inherits the page class IssueBill_Frm. As you can see, BillInstorageMng and BillInstorage inherit the page class, so there is only one empty constructor in their class, and other constructor can be processed by its parent class. Here you may want to ask, can we complete page inheritance ?, This is only one step. To achieve the same effect as the page of the parent class, you must copy the HTML in the parent class to the HTML of the subclass, the display of the interface is the same (if you want to change the interface, you can change the Add button in the HTML of the subclass Interface), but the problem is that in. when HTML is copied to the subclass page in the net designer, the server control on the page is automatically added to the variable declaration when the post code of the Child page is entered. As we can imagine, these controls already exist in the parent class, and the default protection type is protected, so the subclass can also be seen, so the control will be repeated, it will be very wrong, the control variables used by the parent class must be deleted from the Child class. If the child class wants other operations, you can add the control by yourself, but the variables cannot be the same as the parent class. This completes page inheritance. You can try it to reduce a lot of repeated code.
Also, I want to talk about BillInstorageMngList class and IssueBillMng class. They all inherit from mongourbillcom to implement the functions defined by mongourbillcom. They are intermediate layers, therefore, we can directly call mongourbillcom when calling the page. The actual implementation of which instance is implemented by BillFactory may not be clear, specifically, in the IssueBillMng_Frm Constructor (the page constructor does not exist by default, and we add it ourselves), declare an example of javasurbillcom: mgrObr = BillFactory (this ); use the factory to determine the intermediate layer variable of the instance to complete different tasks. This is the simple factory model. If you do not understand it, you can look at the design model. Let's talk about this today. If you have any questions, you can discuss it. Although my expression may not be clear in some places, you can take a good look at this figure, which is a typical factory model diagram, well, it's time to go home from work. Have a good evening.
Author: moshangchen