ASP.NET program MASTER

zhaozj2021-02-16  101

Introduction

This article is about detailing processes involved during Framework developments, and as an example, develops a very small framework "Master-Page Framework" using ASP.NET and C #. You will be explained about the object oriented design methodology using UML, Design patterns involved In the frameworks, and a little about the pattern oriented architecture and design (picture), a little bit of everything.

Master Page Framework Developments:

Every Case In Object Oriented Software Engineering. One of the Use Cases While We Develop Web Application Is That "User Needs a Consistent Look and Feel, Through Out, Period".

Now What a deal ??? We See Every Day, Everye, Consistent Web-Sites etc., Etc ... We See Good-Looking "Sexy" Web Sites, But We don't See One Thing See That, How much maintenance cost is required if we need one change for the whole of the web site.

Apart from some CSS style-sheet for consistency, what else we need, a framework, Master-Page Framework, which should be extendible, easy to use, pluggable and modifiable visually! (Sounds great! What a wish :)) There is no Such excitation in ASP.NET (Whidbey, Does Have ONE, But Still Long Way TO GO).

I Started Looking Around The Web and Found Some Interesting Articles:

Master Your Site Design With Visual Inheritance and page Templates by Fritz Onion.

ASP.NET Page Templates - Using Inheritance By Peter Provost.

These articles are very good starting points, so I took the entire valuable advises from them and went further, since, I was looking for something like a reusable / extendible Framework. I took the responsibility of redesigning the whole wheel that never existed, in the first place, how is that;) The approach I took, what I devised is, Pattern Oriented Architecture and Design (POAD), not design patterns, they are different I call it POAD because my application has a peculiar look and feel that.. it follows a pattern. POAD means you have entire prototypic pattern, your application will follow, but will be overridden later for concrete structure of it (the concept needs a whole article and I would write later, with some examples, hopefully next month). So the master-page has header, footer, navigator, menus / submenus, and content place-holders that would be filled in later as needed for concrete pages, How's that, sounds good. Let's move further! Here are the steps involved in designing THE Poad based software.

Draw the Whole Abstract Pattern your framework wouldoe.

Find Objects Responsible for doing the job.

Find Relationships Between.

Find design patterns needed.

ElaBorate Objects While Designing Them, And Find Functionality for Them.

Write Test Cases.

Steps Involved:

Draw the Whole Abstract Pattern your framework wouldoe.

Here is The PrototyPic Pattern of Our Framework:

Figure 1 (Master-Page Layout / Pattern)

Master Web User-Control

If we decompose this pattern into objects, it's being clear that we should have something like skeleton or template for the place holders, ie, there should be something like a master-page that is composed of the placeholders, like header, footer, logo, menus, navigator, and contents etc.Since our plan is to change these place holders visually, we could safely put these place holders in a user control (PageUserControlBase) that in turn contains all the place holders. Call it a Master user-control, . where you define your layout for these contents Now, our model would have a Master Page that in turn is composed of Master User-Control (PageUserControlBase) that in turn is composed of placeholders, like this:

Getting closer, great! :) Now the visual part is decided that we provide using user-control or so. We want this user-control to be pluggable at run time, so we'll dynamically load it at run time using web.config LIKE THIS:

Our Framework encapsulates all the functionality of the Master User-Control (PageUserControlBase) class in an assembly as a base / abstract class, so that we can extend it in future, if we need it Here is how it would look like.:

With this approach, IF in Future, WE DECIDE with SOME OTHER LOOK AND FeEL Of The Master User Control, All We need is to extend pageuserControlBase Class and use IT:

<% @ Control inherits = "Shams.web.ui.masterpages.pageuserControl"%>

Or use it like this:

<% @ Control inherits = "Shams.web.ui.masterpages.pageuserControllextra"%>%>

PageUserControl or PageUserControlExtra, will provide us access to the WebControls.PlaceHolder (s) Here is how the PageUserControlBase.ascx should look like:.?. This was straightforward, right Yes, it is Now the visual component can easily be extended, and further , is pluggable through the web.config, and is ready. So while designing the Framework, we are right on target, extendible and pluggable Framework, great :). What else would be needed, well lot of work still there? All we have Done So Far IS WAY PROUGH PLUGGABLE MASTER USER Control-Base. We Have A Long Way To Go. Let's first analyze how the html / aspx page looks like:

You can see the page itself Has Four Parts, Let's Examine Them Closely:

Part A: - HTML Header, Describing Code-Behind Language, Page Title, Meta Info, And HTML Body ETC.

Part-b: - form isa.

Part-C: - Master User-Control Area, [OR Any Controls].

Part-d: - HTML Footer Area.

Master Custom-Control:

Every page can have one and only one HTML Form. We put all the server-controls in this form (part-C). So, what we need is another object that would encapsulate all these HTML-Rendering stuff shown above, like Part- A, Part-B, Part-C, And Part-D in It. If You Look at the Control Class, IT Has All The Functionality We Are Looking For. The Control IS A Composite That Means We can Put Other Controls IN. So, it would be a good starting point to start with a Custom control by extending the Control Object. This extended Custom Control, we named it PageControlBase, will provide HTML rendering capability as well as it would have a System.Web.UI.HtmlControls .HtmlForm object. This Form object would be used to add our famous master-user-control or Part-C in it. Now, our master page would be composed of some master custom control, and master-user-control. Here is the UML Diagram That Demonstrates All That: Now That We Have A Pluggable Master-User-Control, a Custom Control That Will Create All of The Html Parts is Necessary.

What WE NEED IS An Integrator Class That Will Insert Master User-Control INTO CUSTOM CONTROL FORM AND ATTACH IT TO The master-page. And That's the masterpagebase class, derived from ui.page class: -

Design Patterns Used in Master-Page Framework

When you are planning for any framework That Is Based, The Most Effective Pattern is The Template Design Pattern. Here Is The Code That Demonstrates THIS THIS The code

Public Interface ipageControl

{

System.Web.ui.Control ParentControl ();

Void htmlrenderstarts ();

Void prehtmlrender ();

Void htmlrender ();

Void PostHtmlrender ();

Void htmlrenderends ();

///

/// The title page can be set with this property

/// String PageTitle

{

Get;

SET;

}

///

///

String metainfo

{

Get;

SET;

}

}

We defined the sequence / pattern of execution That Would Later Be Overridden by the derived classes.

Template Design Pattern Is Used in Two Occasions:

Defined Template In The Custom Control: -

And Here Is The Other Place Where The Same Design Pattern is buy:

Other patterns that are used are Factory and Composite Design Patterns The Factory pattern is used to create classes, and should provide one place;. If we have plan to put some business logic around their creation, we can do it, without breaking the existing code .

Composite Pattern is built in with the .NET Framework, like Control Class is itself based on composite pattern. Composite Pattern in its simple form is a list of list of objects. Instead of reinventing my own containers for objects, I used the Control class as My Starting Point.

So that's it, we are done with the Framework All you need is to derive your page from the MasterPage class, and override the stuff you want to change in your concrete classes How we do it is shown using UML Diagram here..:

Let's Discuss Some Typical Scenarios We'll Come Across While Doing Implementation:

1. Creation of Master Page Skeleton: -

AS Discussed Earlier, All We need is to derive from masterpagebase. Here is the code snippet as an example:

Here is the output we'll get; it's a master-page skeleton.

The Visual Settings Are from Web.config, I.,

If you have some other-layout in your mind for your MasterPage, you can create your own user control and change the signature in the web.config.Here is the not so detailed objects sequence diagram, for the above scenario: -

2. Creation of masterpage from masterpage skeleton: -

WE WOULD CREATE A MASTERPAGE CLASS from masterpageBase and Override The Placeholders with our owRe is The example code snippet for this:

Here Is A Master-Page I created for My Sample Website:

3. Creation of Your Own Pages from masterpage you just have created.

All you need to do is make this masterpage class a base class for all of your pages, and override the functionality That You might want to be different, and make things consistent: -

Here is The proposed UML Diagram for the rest of the basis for the web site: -

4. If you have more Than One Master Pages (MDI SCENARIO)

In this particular scenario, you would override the function LoadPageUserControl (), where the framework is dynamically loading the user specified master control Here is the code snippet for this scenario:. -

And Here Is The Uml Diagram for Rendering this Scenario: -

Here is The UML Reperesent of The Generic Case, MDI (Multiple Document Interface Or Multiple Master Interface (MMI) In Case Of Web-Applications: -

So that's it for now, I hope you have enjoyed this MMI journey with me, although the flight was a little bit bumpy, but we are happy that we are safely landed back to home (page). Now enjoy the framework, all you need is to include assembly Shams.Web.UI.MasterPages.dll and start using it. I have also included an example that will help you in designing your applications. Please send me your feedbacks for further improvement of the framework, thanks.Conclusion

Software architecture revolves around structure, and framework provides the structure to it. The framework is the foundation for any application being developed. Poor foundation leads to poor applications that require more maintenance cost and would be very inefficient by nature. So whenever you decide for a framework development, look for some one who is a domain expert for the particular business and have lots of design experience as well, in that way, you would be able to develop something that is reusable and extensible in nature.

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

New Post(0)