Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Singleton or static

 
Deepak Chopra
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Deepak Chopra
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic