473,396 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Code behind with use of Abstract Factory?

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
Nov 17 '05 #1
3 1799
Just speaking to the design pattern part, this sounds like a good candidate. Instead of having if-then's and switch/case's all over the place, you could base your entire app off of one interface - like ISiteLayout. And you have as many designs as you want, that all implement the ISiteLayout interface..

So, once you figure out which class to instantiate (and it won't matter to the app, which class that is) - you can just use the interface at will. So if you have Admin, and General as classes that implement ISiteLayout, you could do either of these:

ISiteLayout objMyLayout = new Admin();
-or-
ISiteLayout objMyLayout = new General();

and then continue to use objMyLayout like normal..
Back to the issue at hand, we've always done this by having a bitmask of what you are allowed to see (by section, for an application) - and a function to check. So we'd check if you are authorized to see a page, or whether to show nav - based on a setting for that section of the app. It's not as bad as what you described, you basically need to handle security at one place in the nav, and one place at the top of the page.
"Christer" <wi******@hotmail.com> wrote in message news:7b**************************@posting.google.c om...
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
Nov 17 '05 #2
Thank you for your answer, Frank... how's life in the police squad? ;)

"Frank Drebin" <no*****@imsickofspam.com> wrote in message news:<rD**********************@newssvr28.news.prod igy.com>...
Just speaking to the design pattern part, this sounds like a good
candidate. Instead of having if-then's and switch/case's all over the
place, you could base your entire app off of one interface - like
ISiteLayout. And you have as many designs as you want, that all
implement the ISiteLayout interface..
We do expect the forementioned "controller" factories to be different
for each aspx page in the system. That is: A factory for
editsomething.aspx and another factory for contentoverview.aspx. I see
your point about it's "basically" what to show and what not, and that
there are overlapping security checks that needs to be done on all
pages - AND the security checks could be put in a more general place.
So, once you figure out which class to instantiate (and it won't matter
to the app, which class that is) - you can just use the interface at
will. So if you have Admin, and General as classes that implement
ISiteLayout, you could do either of these:

ISiteLayout objMyLayout = new Admin();
-or-
ISiteLayout objMyLayout = new General();

and then continue to use objMyLayout like normal..
Im not sure of what your point precisely is there. That the interface
defines common functions, such as security checks? Or? I do agree that
it wont matter to the app, however I think we intend to base our
factories on inheritance instead of interfaces. Should be the same
result, though.

Back to the issue at hand, we've always done this by having a bitmask of
what you are allowed to see (by section, for an application) - and a
function to check. So we'd check if you are authorized to see a page, or
whether to show nav - based on a setting for that section of the app.
It's not as bad as what you described, you basically need to handle
security at one place in the nav, and one place at the top of the page.


With "It's not as bad as what you described" are you referring to my
future design, or to the design that was used at my former comany? In
other words... what do you think is bad? ;)

Kind regards
Christer (and that's my real name :)
Nov 17 '05 #3
I was talking more generally to the concept of having a class factory... in
real life, I'm in the process of adapting a navigation approach I found on
gotdotnet.com where pages are based off of a base class/page.. and you can
then, on page load - do something like a VerifySec(curuser,cursecreq) - and
if they are no good, show an Access Denied... and using this same type setup
for how to show navigation.. because no matter what you do, you need to
check privs for what navigation elements you need to show.. and you also
need to make sure they can't manually navigate to the page...

When I was saying "bad as it seems".. I was talking about our current
implementation (which is somewhat like your old implementation) - where
there is security checks for each navigation element (and that is done in on
place) - and we also, at the top of each page call a method to make sure you
have access to the page..

So in short, that seems to be the way to do, regardless of the language..

"Christer" <wi******@hotmail.com> wrote in message
news:7b**************************@posting.google.c om...
Thank you for your answer, Frank... how's life in the police squad? ;)

"Frank Drebin" <no*****@imsickofspam.com> wrote in message

news:<rD**********************@newssvr28.news.prod igy.com>...
Just speaking to the design pattern part, this sounds like a good
candidate. Instead of having if-then's and switch/case's all over the
place, you could base your entire app off of one interface - like
ISiteLayout. And you have as many designs as you want, that all
implement the ISiteLayout interface..


We do expect the forementioned "controller" factories to be different
for each aspx page in the system. That is: A factory for
editsomething.aspx and another factory for contentoverview.aspx. I see
your point about it's "basically" what to show and what not, and that
there are overlapping security checks that needs to be done on all
pages - AND the security checks could be put in a more general place.
So, once you figure out which class to instantiate (and it won't matter
to the app, which class that is) - you can just use the interface at
will. So if you have Admin, and General as classes that implement
ISiteLayout, you could do either of these:

ISiteLayout objMyLayout = new Admin();
-or-
ISiteLayout objMyLayout = new General();

and then continue to use objMyLayout like normal..


Im not sure of what your point precisely is there. That the interface
defines common functions, such as security checks? Or? I do agree that
it wont matter to the app, however I think we intend to base our
factories on inheritance instead of interfaces. Should be the same
result, though.

Back to the issue at hand, we've always done this by having a bitmask of
what you are allowed to see (by section, for an application) - and a
function to check. So we'd check if you are authorized to see a page, or
whether to show nav - based on a setting for that section of the app.
It's not as bad as what you described, you basically need to handle
security at one place in the nav, and one place at the top of the page.


With "It's not as bad as what you described" are you referring to my
future design, or to the design that was used at my former comany? In
other words... what do you think is bad? ;)

Kind regards
Christer (and that's my real name :)

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Medi Montaseri | last post by:
Hi, Given a collection of similar but not exact entities (or products) Toyota, Ford, Buick, etc; I am contemplating using the Abstraction pattern to provide a common interface to these products....
3
by: Sebastian Faust | last post by:
Hi, I am currently reading the chapter about abstract factorys from "Modern C++ Design" and wondering how it would be possible to create an object which has a constructor with parameters. At the...
33
by: Chris Capel | last post by:
What is the rationale behind the decision not to allow abstract static class members? It doesn't seem like it's a logically contradictory concept, or that the implementation would be difficult or...
2
by: Julia | last post by:
Hi, I have an application composed from layers like the following A --B ---C A is the top layer C uses an Abstract Factory to Create Concrete classes
4
by: Rachel Devons | last post by:
All, I'm struggling with an OOP concept. Let me try to define what I'm wanting by using some classic examples. Let's say that I have classes called Square & Circle that derive from class...
2
by: emaileric | last post by:
Hi all, I am looking for a way to create two different forms, with different look and feel. However, they would both have the same set of controls, and reference the same code behind page. I...
6
by: Nindi | last post by:
5 Files Singleton.h The Singleton Factory.h The factory creating new objects. The Base class of the hierachy stores a typelist identifying the signature of the constructors to be called...
16
by: RSH | last post by:
Hi, I am a fairly seasoned developer and have recently started looking at software design patterns. I am starting with the Abstract Factory Pattern and was wondering if someone could help me...
4
by: C# | last post by:
http://www.questpond.com/FreeDesign1.htm I was going through the above videos. Can i conclude Abstract factory patterns are extensions of factory patterns. I have made the conclusion after...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.