Class with only shared members/procedures VS Module

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Daniel Fernandes

    Class with only shared members/procedures VS Module

    Hi there

    Is there any difference I need to be aware when I create a class with
    only shared members & procedures when compared to a module (which is a
    shared class) ?

    I am asking this because I have seen at work a class that declares a
    Database connection as a shared member and I wonder if that's a very
    bad programming practice..

    By the way the environment of execution is ASP.Net.


    Cheers
    Daniel
  • Cor Ligthert

    #2
    Re: Class with only shared members/procedures VS Module

    Daniel,

    ASPNET environment

    A class is stateless
    A shared class belongs to all active users from that moment.

    A module is nothing more than a class with only shared members.

    (The shared class is in my opinion a little bit the same as the cache in
    ASPNET)

    I hope this helps a little bit?

    Cor


    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: Class with only shared members/procedures VS Module

      * daniel.fernande s@sesame.co.uk (Daniel Fernandes) scripsit:[color=blue]
      > Is there any difference I need to be aware when I create a class with
      > only shared members & procedures when compared to a module (which is a
      > shared class) ?[/color]

      There is one big difference: Modules are imported automatically,
      classes with shared members not. Modules are used to "group" methods,
      classes represent entities.

      --
      Herfried K. Wagner [MVP]
      <URL:http://dotnet.mvps.org/>

      Comment

      • JD

        #4
        Re: Class with only shared members/procedures VS Module

        "Shared" data is not shared across web farms or web gardens. May or not be a
        problem depending on the data you are storing and if its updateable.

        "Shared" data is not multithreaded safe. Cache and Application classes, both
        very much like "Shared" members, have synchronization in mind. Application
        synchronization is done by the client with lock and unlock, Cache is
        mutlithreaded safe. May or may not be a problem depending on the data you
        are storing and if its updateable.

        "Daniel Fernandes" <daniel.fernand es@sesame.co.uk > wrote in message
        news:eb72e7.040 8200517.33d1445 b@posting.googl e.com...[color=blue]
        > Hi there
        >
        > Is there any difference I need to be aware when I create a class with
        > only shared members & procedures when compared to a module (which is a
        > shared class) ?
        >
        > I am asking this because I have seen at work a class that declares a
        > Database connection as a shared member and I wonder if that's a very
        > bad programming practice..
        >
        > By the way the environment of execution is ASP.Net.
        >
        >
        > Cheers
        > Daniel[/color]


        Comment

        • JD

          #5
          Re: Class with only shared members/procedures VS Module

          Misread your question a bit. Both items I mentioned apply to both cases you
          mentioned.

          "JD" <no@address.org > wrote in message
          news:ewYeDYthEH A.1888@TK2MSFTN GP10.phx.gbl...[color=blue]
          > "Shared" data is not shared across web farms or web gardens. May or not be[/color]
          a[color=blue]
          > problem depending on the data you are storing and if its updateable.
          >
          > "Shared" data is not multithreaded safe. Cache and Application classes,[/color]
          both[color=blue]
          > very much like "Shared" members, have synchronization in mind. Application
          > synchronization is done by the client with lock and unlock, Cache is
          > mutlithreaded safe. May or may not be a problem depending on the data you
          > are storing and if its updateable.
          >
          > "Daniel Fernandes" <daniel.fernand es@sesame.co.uk > wrote in message
          > news:eb72e7.040 8200517.33d1445 b@posting.googl e.com...[color=green]
          > > Hi there
          > >
          > > Is there any difference I need to be aware when I create a class with
          > > only shared members & procedures when compared to a module (which is a
          > > shared class) ?
          > >
          > > I am asking this because I have seen at work a class that declares a
          > > Database connection as a shared member and I wonder if that's a very
          > > bad programming practice..
          > >
          > > By the way the environment of execution is ASP.Net.
          > >
          > >
          > > Cheers
          > > Daniel[/color]
          >
          >[/color]


          Comment

          • David

            #6
            Re: Class with only shared members/procedures VS Module

            On 2004-08-20, Daniel Fernandes <daniel.fernand es@sesame.co.uk > wrote:[color=blue]
            >
            > Is there any difference I need to be aware when I create a class with
            > only shared members & procedures when compared to a module (which is a
            > shared class) ?
            >
            > I am asking this because I have seen at work a class that declares a
            > Database connection as a shared member and I wonder if that's a very
            > bad programming practice..[/color]

            In general that's a bad idea unless you *really* need the connection to
            hang around for transaction purposes. ASP.Net does connection pooling
            automatically, so the best practice is to grab your connections then
            close them as quickly as possible.

            As somebody else mentioned, the only difference between modules and
            classes with only shared members is the fact that the names in the
            module are imported automatically For me, that's enough to avoid
            modules entirely.

            Comment

            • Daniel Fernandes

              #7
              Re: Class with only shared members/procedures VS Module

              David <dfoster@woofix .local.dom> wrote in message news:<slrncidld i.8i3.dfoster@w oofix.local.dom >...[color=blue]
              > On 2004-08-20, Daniel Fernandes <daniel.fernand es@sesame.co.uk > wrote:[color=green]
              > >
              > > Is there any difference I need to be aware when I create a class with
              > > only shared members & procedures when compared to a module (which is a
              > > shared class) ?
              > >
              > > I am asking this because I have seen at work a class that declares a
              > > Database connection as a shared member and I wonder if that's a very
              > > bad programming practice..[/color]
              >
              > In general that's a bad idea unless you *really* need the connection to
              > hang around for transaction purposes. ASP.Net does connection pooling
              > automatically, so the best practice is to grab your connections then
              > close them as quickly as possible.
              >
              > As somebody else mentioned, the only difference between modules and
              > classes with only shared members is the fact that the names in the
              > module are imported automatically For me, that's enough to avoid
              > modules entirely.[/color]



              Thanks all of you for the info.
              There is another thing I wasn't sure about is that Shared data is
              bound to the ASP.Net application and not per HTTP request. Coming from
              the tradition ASP background I didn't thought that was the case so
              it's pretty clear now.
              I think the biggest issue with keeping a database connection as Shared
              data is that as someone mentioned it's not thread safe which means
              something will go wrong when two threads want to use that connection
              in the same time...

              Thanks again

              Daniel

              Comment

              Working...