473,786 Members | 2,304 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Class based on singleton pattern and instance methods in that clas

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....corr ect?

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

Thank you for your clarification
Jan 13 '06 #1
5 1609
KJ
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?

Jan 13 '06 #2
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?

Jan 13 '06 #3
KJ
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*.

Jan 13 '06 #4
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....corr ect?

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

Thank you for your clarification

Jan 13 '06 #5
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" <Di*******@disc ussions.microso ft.com> wrote in message
news:7D******** *************** ***********@mic rosoft.com...
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?

Jan 13 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
64124
by: DBA | last post by:
Hi All, What is the diff. between a singleton class and a static class in C#?
7
2191
by: Atul Malaviya | last post by:
>From a design/usability perspective. When will one use a singleton pattern and when a class with purely static members? What are the pros and cons? I have inherited a code base which is full of both these and I am a bit confused on this count. Singleton insures one object of a class in the application. A class with purely static members and a private constructor also strives to
16
10993
by: A_PK | last post by:
Hi, I am a VB.net beginner, I do not know what are the major difference between Module vs Class. Could someone guide me when is the best situation to use Module or Class. I have no idea when should I use module or class, because no matter i use module or class, i always could get the results that are what i want. but just the declare and calling method is a bit different.
14
3034
by: Paul Bromley | last post by:
Forgive my ignorance on this one as I am trying to use a Singleton class. I need to use this to have one instance of my Class running and I think I understand how to do this. My question however is can a singleton class have a number of paramterised constructors enabling me to pass in parameters or not? I am trying to use the following to send in a parmeter to a constructor, but getting an error with it. I have a feeling that I am not...
2
2422
by: baba | last post by:
Hi all, I'm quite new to C#. I am trying to implement some basics reusable classes using this language and the .NET Framework technology. What I'm trying to do now is to implement a singleton class. I did have a look at the Microsoft "Patterns and Practices" article "Implementing Singleton in C#" (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpatterns/html/ImpSingletonInCsharp.asp)
7
1351
by: Brett Romero | last post by:
I need a static version of a class that can be referenced anywhere as a singleton and the same class that can be used as instances. Can this be done without basically creating the same class twice (one with static methods and one without)? Thanks, Brett
12
3120
by: titan nyquist | last post by:
I have a class with data and methods that use it. Everything is contained perfectly THE PROBLEM: A separate thread has to call a method in the current instantiation of this class. There is only ever ONE instantiation of this class, and this outside method in a separate thread has to access it. How do i do this?
13
20775
by: learning | last post by:
Hi I have a static class written by other team which encapsulates a database instance. but I need to extend it to incldue other things. I know that C# static class is sealed and can;t be inherited & I don't want to copy + paste code. How can I inherit those member variables? Thanks
19
6075
by: =?Utf-8?B?Sko=?= | last post by:
I have a logging component that I will access in other assemblies. So it was brought up to me that I should pass an instance around to these components instead of just making the logging class static. If I make it static I wouldn't need to pass an instance around. What is your take on this?
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9491
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10163
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9959
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7510
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5532
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4063
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.