473,480 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ASP classes, code included multiple times - how to avoid?

I'm writing an ASP application and have a noob question...

I have a class that access an MS SQL database. I have another class also
accesses an MS SQL database and this second class uses objects from the
first class. I have a third class using the DB and objects of the second
class.

Each of these classes contain all the code needed to access the database and
this means much duplicated code. What I'd like to know is if there is a way
to avoid the duplicated code?

I know I could write the code once, then do an #include to include the code
into the class, but that still means multiple occurances of the code.

???
Feb 26 '06 #1
10 2274
Noozer wrote:
I'm writing an ASP application and have a noob question...

I have a class that access an MS SQL database. I have another class
also accesses an MS SQL database and this second class uses objects
from the first class. I have a third class using the DB and objects
of the second class.

Each of these classes contain all the code needed to access the
database and this means much duplicated code. What I'd like to know
is if there is a way to avoid the duplicated code?

I know I could write the code once, then do an #include to include
the code into the class, but that still means multiple occurances of
the code.


What do you mean by "class" ? Are you talking about VBScript Class Objects
created by using the Class Statement
(http://msdn.microsoft.com/library/en...1f669ec5.asp)?
Do you mean custom objects written in JScript? ActiveX objects you
instantiate with Server.CreateObject("prog.id")?
--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Feb 26 '06 #2

"Dave Anderson" <GT**********@spammotel.com> wrote in message
news:12************@corp.supernews.com...
Noozer wrote:
I'm writing an ASP application and have a noob question... <snip> Each of these classes contain all the code needed to access the
database and this means much duplicated code. What I'd like to know
is if there is a way to avoid the duplicated code?
What do you mean by "class" ? Are you talking about VBScript Class Objects
created by using the Class Statement
(http://msdn.microsoft.com/library/en...1f669ec5.asp)?


Yes, exactly.

Feb 26 '06 #3
Noozer wrote:
Are you talking about VBScript Class Objects
created by using the Class Statement?


Yes, exactly.


OK. Could you be a little more specific about what you are doing? Perhaps
you could show an example that illustrates your question.

--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Feb 27 '06 #4

"Noozer" <do*******@me.here> wrote in message
news:VncMf.72667$H%4.28156@pd7tw2no...
I'm writing an ASP application and have a noob question...

I have a class that access an MS SQL database. I have another class also
accesses an MS SQL database and this second class uses objects from the
first class. I have a third class using the DB and objects of the second
class.

Each of these classes contain all the code needed to access the database
and this means much duplicated code. What I'd like to know is if there is
a way to avoid the duplicated code?

I know I could write the code once, then do an #include to include the
code into the class, but that still means multiple occurances of the code.


Have you considered redesigning your set of classes so that none of them
duplicate each other's functionality? Code a common low-level class that
the others can call to do their dirty work. If that's impractical, put the
redundant code in regular functions and call them from the classes.

Also try to avoid any unnecessary depth in your object dependency trees,
e.g., ClassC depends on ClassB which depends on ClassA, etc... I'm not
saying never to do this, just to keep it to the minimum that's needed.

If you want to post the classes you're using (or perhaps abbreviated
versions if possible) we may be able to offer more specific suggestions.
-Mark

Feb 27 '06 #5
"Noozer" <do*******@me.here> wrote in message
news:VncMf.72667$H%4.28156@pd7tw2no...
I'm writing an ASP application and have a noob question...

I have a class that access an MS SQL database. I have another class also
accesses an MS SQL database and this second class uses objects from the
first class. I have a third class using the DB and objects of the second
class.

Each of these classes contain all the code needed to access the database
and this means much duplicated code. What I'd like to know is if there is
a way to avoid the duplicated code?

I know I could write the code once, then do an #include to include the
code into the class, but that still means multiple occurances of the code.

???


Unfortunately, VBScript does not allow for the redefinition of classes. You
could do it in JScript. Your options would be to rewrite the classes in
JScript or create JScript wrapper classes/functions for your existing
VBScript classes.
Feb 27 '06 #6

"Mark J. McGinty" <mm******@spamfromyou.com> wrote in message
news:e8**************@TK2MSFTNGP09.phx.gbl...

"Noozer" <do*******@me.here> wrote in message
news:VncMf.72667$H%4.28156@pd7tw2no...
I'm writing an ASP application and have a noob question...

I have a class that access an MS SQL database. I have another class also
accesses an MS SQL database and this second class uses objects from the
first class. I have a third class using the DB and objects of the second
class.

Each of these classes contain all the code needed to access the database
and this means much duplicated code. What I'd like to know is if there is
a way to avoid the duplicated code?

I know I could write the code once, then do an #include to include the
code into the class, but that still means multiple occurances of the
code.


Have you considered redesigning your set of classes so that none of them
duplicate each other's functionality? Code a common low-level class that
the others can call to do their dirty work. If that's impractical, put
the redundant code in regular functions and call them from the classes.

Also try to avoid any unnecessary depth in your object dependency trees,
e.g., ClassC depends on ClassB which depends on ClassA, etc... I'm not
saying never to do this, just to keep it to the minimum that's needed.

If you want to post the classes you're using (or perhaps abbreviated
versions if possible) we may be able to offer more specific suggestions.


Thanks all!

Basically, I'm trying to design some very generic classes that I will use
often in multple projects. Because of this, I was building each class to be
self sustaining, containing any code needed to converse with databases,
generate output etc. With this, I'd have a lot of duplicated code if I was
using several of the classes at the same time.

Reading the replies here and planning a bit more, it makes much more sense
to build even more basic classes (like a database class) for anything that
I'll be using that often, and being sure to include them in the PROJECT (ie,
ASP) page and NOT within the classes themselves. Such as:

<!-- #include file="dbclass.inc" --> JUST DB handler code
<!-- #include file="pageclass.inc" --> JUST code about pages
<!-- #include file="bookclass.inc" --> JUST code about books

....instead of...

<!-- #include file="bookclass.inc" --> Code about books, DB handler for book
related info, and has an #include to import the "pageclass.inc" file, which
has it's own DB handler for page related info.

Feb 28 '06 #7

Noozer wrote:
"Mark J. McGinty" <mm******@spamfromyou.com> wrote in message
news:e8**************@TK2MSFTNGP09.phx.gbl...

"Noozer" <do*******@me.here> wrote in message
news:VncMf.72667$H%4.28156@pd7tw2no...
I'm writing an ASP application and have a noob question...

I have a class that access an MS SQL database. I have another class also
accesses an MS SQL database and this second class uses objects from the
first class. I have a third class using the DB and objects of the second
class.

Each of these classes contain all the code needed to access the database
and this means much duplicated code. What I'd like to know is if there is
a way to avoid the duplicated code?

I know I could write the code once, then do an #include to include the
code into the class, but that still means multiple occurances of the
code.


Have you considered redesigning your set of classes so that none of them
duplicate each other's functionality? Code a common low-level class that
the others can call to do their dirty work. If that's impractical, put
the redundant code in regular functions and call them from the classes.

Also try to avoid any unnecessary depth in your object dependency trees,
e.g., ClassC depends on ClassB which depends on ClassA, etc... I'm not
saying never to do this, just to keep it to the minimum that's needed.

If you want to post the classes you're using (or perhaps abbreviated
versions if possible) we may be able to offer more specific suggestions.


Thanks all!

Basically, I'm trying to design some very generic classes that I will use
often in multple projects. Because of this, I was building each class to be
self sustaining, containing any code needed to converse with databases,
generate output etc. With this, I'd have a lot of duplicated code if I was
using several of the classes at the same time.

Reading the replies here and planning a bit more, it makes much more sense
to build even more basic classes (like a database class) for anything that
I'll be using that often, and being sure to include them in the PROJECT (ie,
ASP) page and NOT within the classes themselves. Such as:

<!-- #include file="dbclass.inc" --> JUST DB handler code
<!-- #include file="pageclass.inc" --> JUST code about pages
<!-- #include file="bookclass.inc" --> JUST code about books

...instead of...

<!-- #include file="bookclass.inc" --> Code about books, DB handler for book
related info, and has an #include to import the "pageclass.inc" file, which
has it's own DB handler for page related info.


You might want to look at this post wrt include file extensions:

http://groups.google.co.uk/group/mic...c14a5ae7975140

/P.

Feb 28 '06 #8

<!-- #include file="bookclass.inc" --> Code about books, DB handler for
book
related info, and has an #include to import the "pageclass.inc" file,
which
has it's own DB handler for page related info.


You might want to look at this post wrt include file extensions:

http://groups.google.co.uk/group/mic...c14a5ae7975140


I always wondering about which extension to use. I had just recently
switched away from .asp to .inc. Back I go!!!

Thanks!
Mar 1 '06 #9
Noozer wrote:
I always wondering about which extension to use. I had just recently
switched away from .asp to .inc. Back I go!!!


There is no reason to go back. You can simply tell IIS to parse .inc
requests with asp.dll, and there will be no functional difference between
the extensions.


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
Mar 2 '06 #10

Dave Anderson wrote:
Noozer wrote:
I always wondering about which extension to use. I had just recently
switched away from .asp to .inc. Back I go!!!


There is no reason to go back. You can simply tell IIS to parse .inc
requests with asp.dll, and there will be no functional difference between
the extensions.


Assuming Noozer has access to the IIS server, or an obliging web
hosting company....

;-)

--
Mike Brind

Mar 2 '06 #11

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

Similar topics

12
3796
by: David MacQuigg | last post by:
I have what looks like a bug trying to generate new style classes with a factory function. class Animal(object): pass class Mammal(Animal): pass def newAnimal(bases=(Animal,), dict={}):...
3
2022
by: Bryan Parkoff | last post by:
I have C++ Primer Third Edition -- Author Stanley B. Lippman and Josee Lajoie. I have been studying it for couple months however it does not provide a valuable information which it is about...
13
2608
by: Skybuck Flying | last post by:
Hi, I would like to split main.c which contains all code into the following Step 1. Machine.h Step 2. drand.h and drand.c Step 3. nrand.h and nrand.c Main.c then only contains some test...
14
2257
by: teslar91 | last post by:
As a fairly new .NET coder, I would greatly appreciate some comments on any .NET classes that are known to be notoriously slow by comparison to direct API calls. I've already had a bad...
16
2916
by: devicerandom | last post by:
Hi, I am currently using the Cmd module for a mixed cli+gui application. I am starting to refactor my code and it would be highly desirable if many commands could be built as simple plugins. ...
15
28301
by: iKiLL | last post by:
hi all, I would like to be able to create an umbrella class for all my main global sections but I would still like to keep them all in separate file something like the below but I keep getting...
47
3950
by: Larry Smith | last post by:
I just read a blurb in MSDN under the C++ "ref" keyword which states that: "Under the CLR object model, only public single inheritance is supported". Does this mean that no .NET class can ever...
12
11001
by: raylopez99 | last post by:
Keywords: scope resolution, passing classes between parent and child forms, parameter constructor method, normal constructor, default constructor, forward reference, sharing classes between forms....
45
2958
by: =?Utf-8?B?QmV0aA==?= | last post by:
Hello. I'm trying to find another way to share an instance of an object with other classes. I started by passing the instance to the other class's constructor, like this: Friend Class...
0
7037
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
6904
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
5324
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,...
1
4768
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4472
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
2990
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2976
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1294
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
174
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.