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

Ask a Question related to ASP Components, Design and Development.

  1. #1

    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.

    ???


    Noozer Guest

  2. Similar Questions and Discussions

    1. URGENT: How can I avoid my SOURCE CODE from DECOMPILERS like Anakrino9??
      > I'm scare because using Anakrino9 I was able to DECOMPILE my PROJECT. I have threr Do you know what also is unfair? Crossposting is. ...
    2. My code (included) for streaming is broken...
      Hello, I've included everything I have, simple, but, it seems right to me, hehe. But, it isn't. I have an embedded video object and a single...
    3. My PHO code times out after 30s
      Ted Pottel uttered the immortal words: It's supposed to. The manual and docs at php.net are very useful:...
    4. Limiting duplicates in a dynamic dropdown? - Code included
      I'm using this script to dynamicaly populate 2 dropdowns and dispaly the results. Choose a component type from the first drop down, lets say 'car'...
    5. avoid repitive code while sorting hash arrays
      suppose I have a hash like %users =( 'cvs' => { 'uname' => 'cvs', 'uid' => 582, 'gid' => 500 }, 'radvd' => { 'uname' => 'radvd',
  3. #2

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

    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
    ([url]http://msdn.microsoft.com/library/en-us/script56/html/31910d85-2ee9-4234-9444-2ef61f669ec5.asp)?[/url]
    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.


    Dave Anderson Guest

  4. #3

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


    "Dave Anderson" <GTSPXOESSGOQ@spammotel.com> wrote in message
    news:1202l6u84jjad8@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
    > ([url]http://msdn.microsoft.com/library/en-us/script56/html/31910d85-2ee9-4234-9444-2ef61f669ec5.asp)?[/url]
    Yes, exactly.



    Noozer Guest

  5. #4

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

    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.


    Dave Anderson Guest

  6. #5

    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...
    > 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



    Mark J. McGinty Guest

  7. #6

    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...
    > 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.


    Chris Hohmann Guest

  8. #7

    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...
    >
    > "Noozer" <dont.spam@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.



    Noozer Guest

  9. #8

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


    Noozer wrote:
    > "Mark J. McGinty" <mmcginty@spamfromyou.com> wrote in message
    > news:e8bftc4OGHA.2064@TK2MSFTNGP09.phx.gbl...
    > >
    > > "Noozer" <dont.spam@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:

    [url]http://groups.google.co.uk/group/microsoft.public.inetserver.asp.general/browse_frm/thread/ca050b1830acd940/71c14a5ae7975140?hl=en#71c14a5ae7975140[/url]

    /P.

    Paxton Guest

  10. #9

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

    >>
    >> <!-- #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:
    >
    > [url]http://groups.google.co.uk/group/microsoft.public.inetserver.asp.general/browse_frm/thread/ca050b1830acd940/71c14a5ae7975140?hl=en#71c14a5ae7975140[/url]
    I always wondering about which extension to use. I had just recently
    switched away from .asp to .inc. Back I go!!!

    Thanks!


    Noozer Guest

  11. #10

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

    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.


    Dave Anderson Guest

  12. #11

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


    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

    Mike Brind Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139