• 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

In which class should i locate static final instance?

 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


For this to work, the displayFilter always has to be non - null. I thought about implementing the Null-Object pattern and creating a NULL_FILTER


But I couldn't decide where/how to implement it. I could implement it in my UIDataModel and set the displayFilter = NULL_FILTER whenever the client method called setFilter(null). But that would introduce ugly passing of null arguments and checking for nulls that always makes me wince. I could implement it as its own class but client classes would have to instantiate a new NullFilter() every time they wanted to stop filtering results. Seems kinda clumsy, but I'm not too experienced in such matters. Or should I not have a filter in this class at all and let the View handle the filtering of the results. Although I suspect this is a bad idea if the goal is to make the View as *dumb* as possible. How would you guys handle this situation?
[ July 06, 2006: Message edited by: Garrett Rowe ]
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I like the null object pattern idea, but this time you might just have a default implementation. Make it a full blown class and your UI can default its variable:

private Filter filter = new DefaultFilter();

Your setFilter() method would throw an exception on a null argument. Clients would create a DefaultFilter() or a new FancyFilter() or whatever they want to use.

Now that I've typed that I don't much like DefaultFilter as a name. Maybe PassAllFilter or something.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the advice Stan. I couldn't decide whether this was exposing too much of the implmentation to other classes.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic