Singleton Object

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

    #1

    Singleton Object

    Hi ,
    Can anyone tell me when I can use singleton pattern. Will
    it be good for implementing the dataaccess Layer. Will it
    be usefull for the buisness object layer . Could you give
    me a practicle example for using the singleton object.

    Regards,
    Srini
  • Hans Kesting

    #2
    Re: Singleton Object


    "Srini" <rsrinivasanhom e@yahoo.com> wrote in message
    news:0ae301c393 be$b07e6a90$a40 1280a@phx.gbl.. .[color=blue]
    > Hi ,
    > Can anyone tell me when I can use singleton pattern. Will
    > it be good for implementing the dataaccess Layer. Will it
    > be usefull for the buisness object layer . Could you give
    > me a practicle example for using the singleton object.
    >
    > Regards,
    > Srini[/color]

    For dataaccess you probably want to use static methods, so NO instance.
    A singleton could be used to hold configuration information that should not
    change (much).

    Hans Kesting


    Comment

    • Cowboy \(Gregory A. Beamer\)

      #3
      Re: Singleton Object

      Singletons are most useful for Application settings, where you want the
      object instantiated for the app and any changes in settings affect all
      users.You could put your connection settings in a singleton, for example.

      A data layer can be implemented as Static methods, ala the Microsoft Data
      Access Application Block, but a Singleton is not a good idea unless everyone
      is accessing the same exact data in the same exact manner, or you do not
      mind if another person alters someone else's data access path. As this is
      not a normal situation, this is not a good place for a singleton pattern.

      --
      Gregory A. Beamer
      MVP; MCP: +I, SE, SD, DBA

      *************** *************** *************** *************** **********
      Think Outside the Box!
      *************** *************** *************** *************** **********
      "Srini" <rsrinivasanhom e@yahoo.com> wrote in message
      news:0ae301c393 be$b07e6a90$a40 1280a@phx.gbl.. .[color=blue]
      > Hi ,
      > Can anyone tell me when I can use singleton pattern. Will
      > it be good for implementing the dataaccess Layer. Will it
      > be usefull for the buisness object layer . Could you give
      > me a practicle example for using the singleton object.
      >
      > Regards,
      > Srini[/color]


      Comment

      • Sherif ElMetainy

        #4
        Re: Singleton Object

        Hello

        I usually use Singletons when I want my singleton object to implement some
        interface.
        For example in the code below I can have a singleton object of datatype
        IDbCustomerMana ger that can be either SQLCustomerMana ger or
        AccessCustomerM anager. This makes switching between Access and SQL easy. If
        I don't need this feature I use static methods, fields and properties.

        interface IDbCustomerMana ger{
        void AddCustomer(Cus tomer cust);
        }

        class SqlCustomerMana ger : IDbCustomerMana ger {
        void AddCustomer(Cus tomer cust) { // Add customer to a SQL server
        database }
        }
        class AccessCustomerM anager : IDbCustomerMana ger {
        void AddCustomer(Cus tomer cust) { // Add customer to an Access
        database }
        }

        Best regards,
        Sherif

        "Srini" <rsrinivasanhom e@yahoo.com> wrote in message
        news:0ae301c393 be$b07e6a90$a40 1280a@phx.gbl.. .[color=blue]
        > Hi ,
        > Can anyone tell me when I can use singleton pattern. Will
        > it be good for implementing the dataaccess Layer. Will it
        > be usefull for the buisness object layer . Could you give
        > me a practicle example for using the singleton object.
        >
        > Regards,
        > Srini[/color]


        Comment

        • Steve Jansen

          #5
          Re: Singleton Object

          Sherif,

          You are describing Interface inheritance, not an implementation of the
          Singleton pattern.

          See http://www.dofactory.com/Patterns/PatternSingleton.aspx for a
          description and examples.

          -Steve Jansen

          "Sherif ElMetainy" <elmeteny.NOSPA M@wayout.net.NO SPAM> wrote in message
          news:%23XYmsr$k DHA.2200@TK2MSF TNGP12.phx.gbl. ..[color=blue]
          > Hello
          >
          > I usually use Singletons when I want my singleton object to implement some
          > interface.
          > For example in the code below I can have a singleton object of datatype
          > IDbCustomerMana ger that can be either SQLCustomerMana ger or
          > AccessCustomerM anager. This makes switching between Access and SQL easy.[/color]
          If[color=blue]
          > I don't need this feature I use static methods, fields and properties.
          >
          > interface IDbCustomerMana ger{
          > void AddCustomer(Cus tomer cust);
          > }
          >
          > class SqlCustomerMana ger : IDbCustomerMana ger {
          > void AddCustomer(Cus tomer cust) { // Add customer to a SQL server
          > database }
          > }
          > class AccessCustomerM anager : IDbCustomerMana ger {
          > void AddCustomer(Cus tomer cust) { // Add customer to an Access
          > database }
          > }
          >
          > Best regards,
          > Sherif
          >
          > "Srini" <rsrinivasanhom e@yahoo.com> wrote in message
          > news:0ae301c393 be$b07e6a90$a40 1280a@phx.gbl.. .[color=green]
          > > Hi ,
          > > Can anyone tell me when I can use singleton pattern. Will
          > > it be good for implementing the dataaccess Layer. Will it
          > > be usefull for the buisness object layer . Could you give
          > > me a practicle example for using the singleton object.
          > >
          > > Regards,
          > > Srini[/color]
          >
          >[/color]


          Comment

          Working...