I’m Harping on This

Look at the Finder for a second. Look at Mail. Open your Safari bookmarks. Look at Xcode’s sidebar.

In each case you have a tree view of different things. Under the hood, that view is backed by a data structure which contains different things.

Now, those different things have some things in common — an icon and name, for instance. But they’re otherwise quite different.

* * *

In the bad old days you’d make some kind of subclass for all of these things. Call it ListMember. Your Folder and File class (or whatever) would descend from ListMember.

But these days we’re smarter: we use protocols. There’s no reason Folder and File should descend from the same class — they’re almost entirely different, and inheritance is a pain to deal with, so we use protocols instead.