• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Calling member object method using static method.

 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

 
Ranch Hand
Posts: 419
Mac jQuery Objective C
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 2911
150
Google Web Toolkit Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
shan raj
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic