Singleton Object

Discussion in 'ASP .Net' started by Srini, Oct 16, 2003.

  1. Srini

    Srini Guest

    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
     
    Srini, Oct 16, 2003
    #1
    1. Advertising

  2. Srini

    Hans Kesting Guest

    "Srini" <> wrote in message
    news:0ae301c393be$b07e6a90$...
    > 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


    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
     
    Hans Kesting, Oct 16, 2003
    #2
    1. Advertising

  3. 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" <> wrote in message
    news:0ae301c393be$b07e6a90$...
    > 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
     
    Cowboy \(Gregory A. Beamer\), Oct 16, 2003
    #3
  4. 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
    IDbCustomerManager that can be either SQLCustomerManager or
    AccessCustomerManager. This makes switching between Access and SQL easy. If
    I don't need this feature I use static methods, fields and properties.

    interface IDbCustomerManager{
    void AddCustomer(Customer cust);
    }

    class SqlCustomerManager : IDbCustomerManager {
    void AddCustomer(Customer cust) { // Add customer to a SQL server
    database }
    }
    class AccessCustomerManager : IDbCustomerManager {
    void AddCustomer(Customer cust) { // Add customer to an Access
    database }
    }

    Best regards,
    Sherif

    "Srini" <> wrote in message
    news:0ae301c393be$b07e6a90$...
    > 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
     
    Sherif ElMetainy, Oct 16, 2003
    #4
  5. Srini

    Steve Jansen Guest

    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" <> wrote in message
    news:%23XYmsr$...
    > 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
    > IDbCustomerManager that can be either SQLCustomerManager or
    > AccessCustomerManager. This makes switching between Access and SQL easy.

    If
    > I don't need this feature I use static methods, fields and properties.
    >
    > interface IDbCustomerManager{
    > void AddCustomer(Customer cust);
    > }
    >
    > class SqlCustomerManager : IDbCustomerManager {
    > void AddCustomer(Customer cust) { // Add customer to a SQL server
    > database }
    > }
    > class AccessCustomerManager : IDbCustomerManager {
    > void AddCustomer(Customer cust) { // Add customer to an Access
    > database }
    > }
    >
    > Best regards,
    > Sherif
    >
    > "Srini" <> wrote in message
    > news:0ae301c393be$b07e6a90$...
    > > 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

    >
    >
     
    Steve Jansen, Oct 16, 2003
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Proton Projects - Moin

    Singleton - Whether Cloneable overrides Singleton

    Proton Projects - Moin, Mar 26, 2007, in forum: Java
    Replies:
    4
    Views:
    3,261
    Proton Projects - Moin
    Mar 27, 2007
  2. Wilhelm
    Replies:
    1
    Views:
    167
  3. Trans
    Replies:
    12
    Views:
    281
    Robert Klemme
    Sep 14, 2007
  4. Paul McMahon
    Replies:
    3
    Views:
    207
    David A. Black
    Jun 9, 2008
  5. Charles Oliver Nutter

    Singleton methods without the singleton class

    Charles Oliver Nutter, Mar 15, 2010, in forum: Ruby
    Replies:
    4
    Views:
    204
    Charles Oliver Nutter
    Mar 22, 2010
Loading...

Share This Page