• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: advice on filtering TreeNode objects
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: advice on filtering TreeNode objects


  • Subject: Re: advice on filtering TreeNode objects
  • From: Andreas Mayer <email@hidden>
  • Date: Tue, 5 Nov 2002 05:38:26 +0100

Am Sonntag, 03.11.02 um 22:48 Uhr schrieb Alex Rice:

Thanks for responding, but I'm not really understanding you.

Mike already answered most of it. But I'll try it myself anyway ...

Any filtering of the content shown by the NSOutlineView would necessarily have to override the behavior of the TreeNode class, especially these methods, right?

Depends. If you need the filtering elsewhere, this might be the right approach. If you only need it in the outline view, you may add it to the corresponding data source methods, like

- (int)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item
and
- (id)outlineView:(NSOutlineView *)outlineView child:(int)index ofItem:(id)item

It's likely that all of the methods in the TreeNode interface would have to be changed to correctly handle filtering.

I think that depends on what and how you are filtering.

So if all methods need to be overridden, it may as well be a feature of the TreeNode interface,

But the TreeNode class implements a tree data structure. Filtering is not an inherent feature of a tree. Thatfor it would be better to seperate that functionality from the basic tree. You might be able to put it in a category.

The ToDoItem class itself does not have any knowledge of parent/child relationships- that's all inherited from the TreeNode class.

Hm. If I'm not mistaken, a subclass has - per definitionem - knowledge of anything that it's superclass knows. That's the point of subclassing, no? As a matter of fact, I think that in this case - for exactly the reason you stated (ToDoItems do not need any knowledge of the tree structure), ToDoItem should _not_ be a subclass of TreeNode. Instead TreeNode should hold references to the ToDoItems - just like the NSDictionary and NSArray classes work.

My implementation of NSOutlineViewDataSource just calls methods in the TreeNode interface to return the correct item the NSOutlineView.

You mean you implemented the data source methods in the TreeNode class? I woudn't do that, unless you want to limit the use of the TreeNode class to trees that are data sources for outline views.

Also what is a filter protocol?

There is no filter protocol that I'm aware of. Just design your own.

Do you have any examples you can point me to?

Sorry, no. But I'm thinking about something like this:

- @interface TreeNode : NSObject
// the basic tree class

- @protocol FilterProtocol
// a protocol that declares filter methods - something like - (BOOL)isFiltered:(id)object

- @interface TreeNode (Filtered) <FilterProtocol>
// a category to the tree class that implements the filter protocol

- @interface ToDoItem : NSObject
// just holds the data

- @interface ToDoItemOutlineViewDataSource : NSObject
// knows about the tree that holds the toDoItems and the nature of the toDoItems themselves

Whether you want to implement the FilterProtocol for the TreeNode class or the ToDoItem class depends on what data you need for filtering. Or maybe you find it easier to put that code directly in the ToDoItemOutlineViewDataSource class.

The advantage of this design is, that you get three building blocks independent of each other and fully reusable: A tree class, a to do item class and a filter protocol. Only the data source class, that ties everything together, is specialized.

I hope that helps somewhat. If not, please excuse me - it's 5:30 AM right now ... ;-)


bye. Andreas.
_______________________________________________
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.

  • Follow-Ups:
    • Re: advice on filtering TreeNode objects
      • From: Alex Rice <email@hidden>
References: 
 >Re: advice on filtering TreeNode objects (From: Alex Rice <email@hidden>)

  • Prev by Date: Re: Terminating an Application ?
  • Next by Date: Re: NSDocuments without window associations
  • Previous by thread: Re: advice on filtering TreeNode objects
  • Next by thread: Re: advice on filtering TreeNode objects
  • Index(es):
    • Date
    • Thread