Re: advice on filtering TreeNode objects
Re: advice on filtering TreeNode objects
- Subject: Re: advice on filtering TreeNode objects
- From: Alex Rice <email@hidden>
- Date: Sun, 3 Nov 2002 14:48:24 -0700
On Sunday, November 3, 2002, at 05:33 AM, Andreas Mayer wrote:
Am Sonntag, 03.11.02 um 09:42 Uhr schrieb Alex Rice:
I need to apply a filter to the root treenode and have it filter all
the children on some condition, like hiding todo items that are
completed, for example. I'm sure I can code it for that particular
case, but I would rather implement a general-purpose filtering
scheme, so I can expand it to keyword searching or other filters
later on. I just can't conceptualize how to do it. Seems like there
must be a design pattern here. Any suggestions?
IMHO filtering is not a feature of a tree data structure but one of
your particular data stored inside that tree. So I wouldn't build it
into the TreeNode class but in the data source of your outline view.
If filtering is a common task in your app a filter protocol seems the
way to go.
Thanks for responding, but I'm not really understanding you. Here are
some more relevant details.
The data class is a Todo item class, with accessors for it's state,
notes, due date, etc. The data class inherits from TreeNode. It's class
signature is:
@interface ToDoItem : TreeNode <NSCoding>
Any filtering of the content shown by the NSOutlineView would
necessarily have to override the behavior of the TreeNode class,
especially these methods, right?
- (int) numberOfChildren;
- (NSArray*) children;
It's likely that all of the methods in the TreeNode interface would
have to be changed to correctly handle filtering. So if all methods
need to be overridden, it may as well be a feature of the TreeNode
interface, or as you say, a protocol which TreeNode could implement.
The ToDoItem class itself does not have any knowledge of parent/child
relationships- that's all inherited from the TreeNode class. My
implementation of NSOutlineViewDataSource just calls methods in the
TreeNode interface to return the correct item the NSOutlineView.
Also what is a filter protocol? It's not in my Design Patterns book,
unless it's called by another name. Do you have any examples you can
point me to?
Alex Rice <email@hidden>
Mindlube Software
http://mindlube.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.