• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Singleton or static

 
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
The overall mission is to change the world. When you've done that, then you can read this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic