GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes Singleton or static Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Singleton or static" Watch "Singleton or static" New topic
Author

Singleton or static

Sunny Jain
Ranch Hand

Joined: Jul 23, 2007
Posts: 433

Hi All,

I am doing some development work in which i am making one class file which will do the validation of method arguments.
i am confuse How should i design this class?
Whether i make this class as singleton and then call its non static method OR
make this class as normal and make the methods as static?

Can someone tell which will be the better option?
Is there any other alternative to this?


Thanks and Regards,
SCJP 1.5 (90%), SCWCD 1.5 (85%), The Jovial Java, java.util.concurrent tutorial
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

I think it depends on how the validation works. For example, if validation might be specific to instances, then you might want this to be neither static nor a singleton.

What are some of the factors you're considering?


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Sunny Jain
Ranch Hand

Joined: Jul 23, 2007
Posts: 433

Actually the module i am developing a module, it will be having around 50 classes, and around 200 methods. so instead of validating method argument in every method, i want to make a class which will do it. So i will call its method from every method in another classes. So I have following options:

either create a different Object of validation class every time or
Make the validation class a singleton class or
make the validation method as static.

I was thinking its not good to create a new Validation class Object every time
i want to validation something.
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
I agree with marc, furthermore I could see a case for making a Validator object a field of the class. It seems to me that different use cases could have different validation rules that are such that you would need to configure them before hand.



Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Singleton or static