| Author |
In which class should i locate static final instance?
|
Garrett Rowe
Ranch Hand
Joined: Jan 17, 2006
Posts: 1295
|
|
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 ]
|
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
|
 |
Stan James
(instanceof Sidekick)
Ranch Hand
Joined: Jan 29, 2003
Posts: 8791
|
|
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.
|
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
|
 |
Garrett Rowe
Ranch Hand
Joined: Jan 17, 2006
Posts: 1295
|
|
|
Thanks for the advice Stan. I couldn't decide whether this was exposing too much of the implmentation to other classes.
|
 |
 |
|
|
subject: In which class should i locate static final instance?
|
|
|