Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!zaphod.mps.ohio-state.edu!swrinde!mips!bridge2!jarthur!nntp-server.caltech.edu!news From: ernest@pundit.cithep.caltech.edu (Ernest Prabhakar) Newsgroups: comp.sys.next Subject: Re: How do I sort a list? Keywords: SortableList, List, Storage, Categoriess Message-ID: <1991Jun3.173343.18585@nntp-server.caltech.edu> Date: 3 Jun 91 17:33:43 GMT References: <1645@toaster.SFSU.EDU> Sender: news@nntp-server.caltech.edu Organization: California Institute of Technology, Pasadena Lines: 32 Eric P. Scott writes > Assume I have a list of objects, and I want to sort them > according to some arbitrary criteria. As far as I can tell, the > least unpleasant approach is to subclass List and use poseAs: > to add a sort method: > > > -=EPS=- The most general way to do this would be to create a Category of List. "List (SortableList)". For lack of anything better, I suggest you use the conventions in Stepstone's classes. Implement "rankRelativeTo:" for each object you want. Use "qsort" (the system call) to do the sorting. Implement "sort" as part of the category. I did this for the "Deck" object as part of the "DeckOfCards" object suite. If I did it again (which I might), I'd make Deck a category first, then perhaps a subclass. In fact, has anyone tried to get the functionality of StepStone's classes on top of NeXT's (sorting, finding, set operations) List and Storage objects? You could probably do it entirely as categories. Even if Stepstone dies, let's keep the dream of reusable objects alive! -- Ernie P. "Wherefore art thou Objective-C++?" -- Ernest N. Prabhakar Caltech High Energy Physics CaJUN President NeXTMail:ernest@pundit.cithep.caltech.edu "...and ourselves, your servants for Jesus sake." - II Cor 5:13a