Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old February 26th, 2006, 07:15 AM
Noozer
Guest
 
Posts: n/a
Default 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.

???


  #2  
Old February 26th, 2006, 07:25 AM
Dave Anderson
Guest
 
Posts: n/a
Default Re: ASP classes, code included multiple times - how to avoid?

Noozer wrote:[color=blue]
> 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.[/color]

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.


  #3  
Old February 26th, 2006, 09:05 AM
Noozer
Guest
 
Posts: n/a
Default Re: ASP classes, code included multiple times - how to avoid?


"Dave Anderson" <GTSPXOESSGOQ@spammotel.com> wrote in message
news:1202l6u84jjad8@corp.supernews.com...[color=blue]
> Noozer wrote:[color=green]
>> I'm writing an ASP application and have a noob question...[/color][/color]
<snip>[color=blue][color=green]
>> 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?[/color][/color]
[color=blue]
> 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)?[/color]

Yes, exactly.



  #4  
Old February 27th, 2006, 07:35 AM
Dave Anderson
Guest
 
Posts: n/a
Default Re: ASP classes, code included multiple times - how to avoid?

Noozer wrote:[color=blue][color=green]
>> Are you talking about VBScript Class Objects
>> created by using the Class Statement?[/color]
>
> Yes, exactly.[/color]

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.


  #5  
Old February 27th, 2006, 10:35 AM
Mark J. McGinty
Guest
 
Posts: n/a
Default Re: ASP classes, code included multiple times - how to avoid?


"Noozer" <dont.spam@me.here> wrote in message
news:VncMf.72667$H%4.28156@pd7tw2no...[color=blue]
> 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.[/color]

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



  #6  
Old February 27th, 2006, 04:55 PM
Chris Hohmann
Guest
 
Posts: n/a
Default Re: ASP classes, code included multiple times - how to avoid?

"Noozer" <dont.spam@me.here> wrote in message
news:VncMf.72667$H%4.28156@pd7tw2no...[color=blue]
> 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.
>
> ???[/color]

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.


  #7  
Old February 28th, 2006, 04:25 AM
Noozer
Guest
 
Posts: n/a
Default Re: ASP classes, code included multiple times - how to avoid?


"Mark J. McGinty" <mmcginty@spamfromyou.com> wrote in message
news:e8bftc4OGHA.2064@TK2MSFTNGP09.phx.gbl...[color=blue]
>
> "Noozer" <dont.spam@me.here> wrote in message
> news:VncMf.72667$H%4.28156@pd7tw2no...[color=green]
>> 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.[/color]
>
> 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.[/color]

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.



  #8  
Old February 28th, 2006, 08:15 AM
Paxton
Guest
 
Posts: n/a
Default Re: ASP classes, code included multiple times - how to avoid?


Noozer wrote:[color=blue]
> "Mark J. McGinty" <mmcginty@spamfromyou.com> wrote in message
> news:e8bftc4OGHA.2064@TK2MSFTNGP09.phx.gbl...[color=green]
> >
> > "Noozer" <dont.spam@me.here> wrote in message
> > news:VncMf.72667$H%4.28156@pd7tw2no...[color=darkred]
> >> 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.[/color]
> >
> > 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.[/color]
>
> 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.[/color]

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

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

/P.

  #9  
Old March 1st, 2006, 06:25 AM
Noozer
Guest
 
Posts: n/a
Default Re: ASP classes, code included multiple times - how to avoid?

[color=blue][color=green]
>>
>> <!-- #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.[/color]
>
> You might want to look at this post wrt include file extensions:
>
> http://groups.google.co.uk/group/mic...c14a5ae7975140[/color]

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

Thanks!


  #10  
Old March 2nd, 2006, 02:45 PM
Dave Anderson
Guest
 
Posts: n/a
Default Re: ASP classes, code included multiple times - how to avoid?

Noozer wrote:[color=blue]
> I always wondering about which extension to use. I had just recently
> switched away from .asp to .inc. Back I go!!![/color]

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.


  #11  
Old March 2nd, 2006, 02:45 PM
Mike Brind
Guest
 
Posts: n/a
Default Re: ASP classes, code included multiple times - how to avoid?


Dave Anderson wrote:[color=blue]
> Noozer wrote:[color=green]
> > I always wondering about which extension to use. I had just recently
> > switched away from .asp to .inc. Back I go!!![/color]
>
> 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.
>[/color]

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

;-)

--
Mike Brind

 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles