Class based on singleton pattern and instance methods in that clas

Discussion in 'ASP .Net' started by =?Utf-8?B?RGlmZmlkZW50?=, Jan 13, 2006.

  1. Hello All,

    I am designing a class based on singleton pattern. Inside this class I have
    multiple instance methods. My question is since there will be only one
    instance of this class at any instance of time in the whole application there
    is no use in having these methods as instance methods I can as well have
    static methods....correct?

    If I leave these methods as instance methods would they have any wrong
    impact on my application?

    Thank you for your clarification
    =?Utf-8?B?RGlmZmlkZW50?=, Jan 13, 2006
    #1
    1. Advertising

  2. =?Utf-8?B?RGlmZmlkZW50?=

    KJ Guest

    If you mark the methods public static, than anyone can call them
    without an instance, and then what good is the Singleton pattern? Am I
    missing something here?
    KJ, Jan 13, 2006
    #2
    1. Advertising

  3. Re: Class based on singleton pattern and instance methods in that

    My question is if a class is marked as singleton how will the instance
    methods in that class work?

    Is it a good practice to have instance methods inside a singleton class?
    Whats the use of having singleton class with instance methods if you are
    going to have only one instance of the class?

    Did I make sense?

    Thank you.

    "KJ" wrote:

    > If you mark the methods public static, than anyone can call them
    > without an instance, and then what good is the Singleton pattern? Am I
    > missing something here?
    >
    >
    =?Utf-8?B?RGlmZmlkZW50?=, Jan 13, 2006
    #3
  4. =?Utf-8?B?RGlmZmlkZW50?=

    KJ Guest

    Re: Class based on singleton pattern and instance methods in that

    The instance methods in the class will be called on the single instance
    that is created, right? So if the methods are static, then you don't
    really need an instance, and it defeats the purpose of using the
    singleton pattern. Therefore, you MUST have *instance* methods, because
    the point of singleton is single-*instance*.
    KJ, Jan 13, 2006
    #4
  5. Diffident,
    you may be getting confused about what a class in Singleton pattern does -
    it DOES return an instance, it's just that you can only ever have ONE
    instance. So, instance methods make perfect sense.
    Does this help?
    Peter

    --
    Co-founder, Eggheadcafe.com developer portal:
    http://www.eggheadcafe.com
    UnBlog:
    http://petesbloggerama.blogspot.com




    "Diffident" wrote:

    > Hello All,
    >
    > I am designing a class based on singleton pattern. Inside this class I have
    > multiple instance methods. My question is since there will be only one
    > instance of this class at any instance of time in the whole application there
    > is no use in having these methods as instance methods I can as well have
    > static methods....correct?
    >
    > If I leave these methods as instance methods would they have any wrong
    > impact on my application?
    >
    > Thank you for your clarification
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Jan 13, 2006
    #5
  6. =?Utf-8?B?RGlmZmlkZW50?=

    Bruce Barker Guest

    Re: Class based on singleton pattern and instance methods in that

    you are a little confused. you don't mark a class as singleton, you
    implement a class that follows the pattern.the singleton pattern is when a
    instance of a class is created/requested, the same instance is always
    returned.

    static methods are owned by the class and will not have access to instance
    members. they can be called without creating an instance of the (singleton)
    class.

    instance methods belong to the instance, can access instanse mebersm, and
    can only be called from an instance reference.

    note: a common singleton practice is to have static methods that create an
    instance, then call the instance methods.

    -- bruce (sqlwork.com)



    "Diffident" <> wrote in message
    news:...
    > My question is if a class is marked as singleton how will the instance
    > methods in that class work?
    >
    > Is it a good practice to have instance methods inside a singleton class?
    > Whats the use of having singleton class with instance methods if you are
    > going to have only one instance of the class?
    >
    > Did I make sense?
    >
    > Thank you.
    >
    > "KJ" wrote:
    >
    >> If you mark the methods public static, than anyone can call them
    >> without an instance, and then what good is the Singleton pattern? Am I
    >> missing something here?
    >>
    >>
    Bruce Barker, Jan 13, 2006
    #6
    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. Wilhelm
    Replies:
    1
    Views:
    153
  2. Summercool Summercool

    Singleton pattern vs Class variables and methods

    Summercool Summercool, Sep 16, 2007, in forum: Ruby
    Replies:
    1
    Views:
    98
    Marcin Raczkowski
    Sep 16, 2007
  3. Kenneth McDonald
    Replies:
    5
    Views:
    298
    Kenneth McDonald
    Sep 26, 2008
  4. Daniel DeLorme
    Replies:
    14
    Views:
    236
    Brian Candler
    Dec 14, 2008
  5. Charles Oliver Nutter

    Singleton methods without the singleton class

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

Share This Page