C
Christer
Hi all!
We're creating an administration for a web application. This includes
severeal aspx pages.
Our key entity in the web application is "Profile", which can have a
certain type.
Based on the profile type, the administration pages will have some
small changes, such as displaying a few extra tabs, or maybe change
the available choices in a dropdown.
At my former company they implemented this sort of behavior by using a
LOT of switch (c#) statements everywhere code flow was based on
certain internal environment variables, which, over time got pretty
messy to expand (emagine the implementation of a new profile type - we
had to check every statement, which was a tedious task and made us
develop a certain paranoira
Now, not wanting to repeat history, we're trying to find the right
development pattern for our aspx pages. This is our current idea:
1. We use a aspx page with code behind .cs file (lets call it
EditSomething.aspx).
2. The aspx page has several web controls, including tabs and buttons.
3. Instead of putting profile type oriented switch statements in the
code behind, we're think of introducing an abstract factory with set
of classes corresponding to the amount of profile types. The abstract
class defines the interface the subclasses will need to implement.
3. On page load (or other places where needed) we will ask a static
method on the abstract class to return the proper class based on
profile type (and other information).
4. On button clicks the actions and values are proxied to and
processed by the same class.
The pattern above is repeated on every apsx file in the
administration. This ensures, that we know exactly where to expand our
code, when expanding profile types (and more testable with NUnit, we
suspect). And, when "forgetting" to implement a function, the compiler
will tell us.
The classes from the factory in return uses core classes, which is the
business logic.
Now, does anyone have comments on this sort of development pattern? We
call the factory classes controllers, because they in fact, control
the code behind (and partially inspired by the sound of
Model-View-Controller design pattern .
I'd like to know whether others have found better, structured ways of
reusing layout but still enabling certain changes - making the
application behave in a certain way in every page, without making
spaghetti code...
Kind regards
Christer
We're creating an administration for a web application. This includes
severeal aspx pages.
Our key entity in the web application is "Profile", which can have a
certain type.
Based on the profile type, the administration pages will have some
small changes, such as displaying a few extra tabs, or maybe change
the available choices in a dropdown.
At my former company they implemented this sort of behavior by using a
LOT of switch (c#) statements everywhere code flow was based on
certain internal environment variables, which, over time got pretty
messy to expand (emagine the implementation of a new profile type - we
had to check every statement, which was a tedious task and made us
develop a certain paranoira
Now, not wanting to repeat history, we're trying to find the right
development pattern for our aspx pages. This is our current idea:
1. We use a aspx page with code behind .cs file (lets call it
EditSomething.aspx).
2. The aspx page has several web controls, including tabs and buttons.
3. Instead of putting profile type oriented switch statements in the
code behind, we're think of introducing an abstract factory with set
of classes corresponding to the amount of profile types. The abstract
class defines the interface the subclasses will need to implement.
3. On page load (or other places where needed) we will ask a static
method on the abstract class to return the proper class based on
profile type (and other information).
4. On button clicks the actions and values are proxied to and
processed by the same class.
The pattern above is repeated on every apsx file in the
administration. This ensures, that we know exactly where to expand our
code, when expanding profile types (and more testable with NUnit, we
suspect). And, when "forgetting" to implement a function, the compiler
will tell us.
The classes from the factory in return uses core classes, which is the
business logic.
Now, does anyone have comments on this sort of development pattern? We
call the factory classes controllers, because they in fact, control
the code behind (and partially inspired by the sound of
Model-View-Controller design pattern .
I'd like to know whether others have found better, structured ways of
reusing layout but still enabling certain changes - making the
application behave in a certain way in every page, without making
spaghetti code...
Kind regards
Christer