jQuery in Action, 2nd edition*
The moose likes Java in General and the fly likes Calling member object method using static method. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Calling member object method using static method." Watch "Calling member object method using static method." New topic
Author

Calling member object method using static method.

shan raj
Ranch Hand

Joined: Dec 16, 2008
Posts: 42
Hi,

I have created singleton object. It contains couple of static methods and non-static methods. I have created one Logger class object, while initializing the singleton object. In the static method i am calling the member object method to do some operation. The sample code given below. The code is working fine.

My question here is, Does the singleton class can have static methods and call it member object method is right approach.

Kindly provide your suggestions.

Thanks in advance,
Shan

pawan chopra
Ranch Hand

Joined: Jan 23, 2008
Posts: 410

Well, I do not think there is any problem until and unless your singleton is not breaking at any point. If you want kindly go through this article Simply Singleton. It is a very good article on singleton and give all the aspects and issues related to Singleton.


Pawan Chopra
SCJP - DuMmIeS mInD
Suhas Bilaye
Ranch Hand

Joined: Sep 10, 2009
Posts: 80
It is perfectly alright to call the member methods (non-static) from the static methods. Many a times it is required to do the initial setup which might be a different method it can be called from the static method of returning an instance or from the private constructor.


Thanks and Regards,
Suhas
http://www.xplore-java.blogspot.com/
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 917

while the answers given by pawan chopra and Suhas Bilaye are right,

I am looking at your example....
Why dont you use the logging api already within java and save yourself the trouble ?
also there are other apis like log4j that do the same work.


My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
shan raj
Ranch Hand

Joined: Dec 16, 2008
Posts: 42
Thanks for the answer.

Hi Salvin, I took this an sample example to explain my issue. Actual usage for this type is different in my project.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling member object method using static method.
 
Similar Threads
Combining State and Singleton design patterns
Switch between class implementation
Difference between Static and Instance Methods
Singleton Pattern Question
Difference between private constructor and making class final ?