473,320 Members | 1,817 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,320 software developers and data experts.

Inheritanse, insertions and not only that

Hi All,

I post this message in three newsgroups, maybe somebody can say something
helpful.

The ASP.NET C# Web app consists of two parts - the Mobile part (PDA) and the
regular desktop browser (2000/XP) part. The business logic of both parts is
absolutely the same. I don't want to make a full copy of the business logic
in both parts but it seems to me that I don't have any choice. What's done
now. I created an initial page, this page is empty, it just detects the
remote browser version and redirects the program's flow to the required
part - for PDA browser or for 2k/XP browser.

I made both sets of pages almost in the same manner, the controls are
originally different, Mobile and Regular, but these controls are having the
same names and can be managed by the same business logic, thanks to VS for
this flexibility, I made a full copy of a business logic for both sets of
pages and it works.

I hate this solution. If I need to change something I need to change both
codes and keep in mind what code has already been changed and why.

If I could use the inheritance in this case it would be excellent, but I
can't, because VS doesn't support the video inheritance yet, maybe in
future, but nobody promised yet. I use a lot of controls in the logic and
can't make a root class because in this case all these controls will not be
visually inherited, and as I wrote above the origins of these controls are
different - Mobile and Regular.

I can't use #INCLUDE like in C++ to include the same parts of the source
codes. Why? I hate that in VS. Lazy programmers or what? Future versions?..

What I'm having now are almost same class files, excluding the
initialization parts that the Visual Studio generated for the different
controls.

What can I do to cut off the same code from two different places and maybe
to import it from some external file, one for two different class files?
It's terrible but I didn't see that the current version of VS can support
something like #INSERT or #IMPORT except for help files.

Please, help, any ideas will be appreciated.

Dmitri.

Nov 16 '05 #1
2 1638
"Dmitri Shvetsov" <dshvetsov[I really don't like spam @]cox.net> wrote in
message news:vpHcc.35$Wo6.5@fed1read03...
Hi All,

The ASP.NET C# Web app consists of two parts - the Mobile part (PDA) and the regular desktop browser (2000/XP) part. The business logic of both parts is absolutely the same. I don't want to make a full copy of the business logic in both parts but it seems to me that I don't have any choice.


Generally, "business" logic can be shared assuming you structure your app
such that presentation and business logic are kept separate.

My guess is that you need to refactor your code such that as much common
functionality is encapsulated in real "business" classes. These classes will
not know about presentation stuff, but are used by the presentation classes.

Take a login form, for instance. You would probably make a:
desktop/login.aspx and desktop/login.aspx.cs
and also
mobile/login.aspx and mobile/login.aspx.cs

Both of these pages will have text boxes for username, password, and a
button to login. The event handler for that button click event on each page
should probably instantiate and call a method in a third business class:

void button_click (object sender, EventArgs args) {
LoginLogic loginLogic = new LoginLogic();
if (loginLogic.LoginUser(username.text, password.text)) {
Response.Redirect(loggedInPage);
} else {
Response.Redirect(failedPage);
}
}

that third class (LoginLogic) will have all your real business logic. Your
presentation classes, then, can hopefully be kept quite simple.

You can go further and create a common presentation helper class that can
take on even more of the common functionality. For instance:

public class CommonLogin {

private Page currentPage;

public CommonLogin (Page page) {
currentPage = page;
}

public void HandleLoginClick(sender object, EventArgs args) {
LoginLogic loginLogic = new LoginLogic();
if (loginLogic.LoginUser(username.text, password.text)) {
currentPage.Response.Redirect(loggedInPage);
} else {
currentPage.Response.Redirect(failedPage);
}
}
}

then in your two aspx.cs pages, you'd create an instance of CommonLogin, and
add event handlers to it. something like:

button.clicked += new EventHandler (commonLogin.HandleLoginClick);
Please note, all above code was written in the e-mail client, so I'm sure
there are many syntax problems. Hopefully, though, it will help you get
started.

--
Mike Mayer, C# MVP
mi**@mag37.com
http://www.mag37.com/csharp/
Nov 16 '05 #2
"Dmitri Shvetsov" <dshvetsov[I really don't like spam @]cox.net> wrote in
message news:vpHcc.35$Wo6.5@fed1read03...
Hi All,

The ASP.NET C# Web app consists of two parts - the Mobile part (PDA) and the regular desktop browser (2000/XP) part. The business logic of both parts is absolutely the same. I don't want to make a full copy of the business logic in both parts but it seems to me that I don't have any choice.


Generally, "business" logic can be shared assuming you structure your app
such that presentation and business logic are kept separate.

My guess is that you need to refactor your code such that as much common
functionality is encapsulated in real "business" classes. These classes will
not know about presentation stuff, but are used by the presentation classes.

Take a login form, for instance. You would probably make a:
desktop/login.aspx and desktop/login.aspx.cs
and also
mobile/login.aspx and mobile/login.aspx.cs

Both of these pages will have text boxes for username, password, and a
button to login. The event handler for that button click event on each page
should probably instantiate and call a method in a third business class:

void button_click (object sender, EventArgs args) {
LoginLogic loginLogic = new LoginLogic();
if (loginLogic.LoginUser(username.text, password.text)) {
Response.Redirect(loggedInPage);
} else {
Response.Redirect(failedPage);
}
}

that third class (LoginLogic) will have all your real business logic. Your
presentation classes, then, can hopefully be kept quite simple.

You can go further and create a common presentation helper class that can
take on even more of the common functionality. For instance:

public class CommonLogin {

private Page currentPage;

public CommonLogin (Page page) {
currentPage = page;
}

public void HandleLoginClick(sender object, EventArgs args) {
LoginLogic loginLogic = new LoginLogic();
if (loginLogic.LoginUser(username.text, password.text)) {
currentPage.Response.Redirect(loggedInPage);
} else {
currentPage.Response.Redirect(failedPage);
}
}
}

then in your two aspx.cs pages, you'd create an instance of CommonLogin, and
add event handlers to it. something like:

button.clicked += new EventHandler (commonLogin.HandleLoginClick);
Please note, all above code was written in the e-mail client, so I'm sure
there are many syntax problems. Hopefully, though, it will help you get
started.

--
Mike Mayer, C# MVP
mi**@mag37.com
http://www.mag37.com/csharp/
Nov 16 '05 #3

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

Similar topics

3
by: Mark | last post by:
Hi everyone, I just need a bit of advice as to where to start tackling a problem, if thats possible - thanks very much. I need a single stored procedure to make several inserts into my msde...
8
by: Clay Luther | last post by:
I am doing to large dataset performance tests with 7.3.4b2 today and I noticed an interesting phenomenon. My shared memory buffers are set at 128MB. Peak postmaster usage appears to be around 90MB....
1
by: Isaac Blank | last post by:
Hi. We've run into a concurrency issue I do not have a clear solution for. In a DB2 UDB 7.2 database, we have several tables with a chain of foreign key relarionships: Table1 primary key x...
7
by: dam_fool_2003 | last post by:
friends, I wanted to learn the various ways of inserting a single list. so: Method 1: #include<stdlib.h> #include<stdio.h> struct node { unsigned int data; struct node *next;
0
by: Dmitri Shvetsov | last post by:
Hi All, I post this message in three newsgroups, maybe somebody can say something helpful. The ASP.NET C# Web app consists of two parts - the Mobile part (PDA) and the regular desktop browser...
9
by: Paul Steele | last post by:
I am writing a C# app that needs to periodically poll for cdroms and usb storage device insertions. I've looked at the WMI functions but haven't found anything all that useful. The closest is...
5
by: martin-g | last post by:
Hi. I have realized some heavy algorithm which works on ArrayList of strings. It works slow because of a lot of insertions and deletions at arbitrary positions in the list. Now I really need an...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.