Atom constructs are cool
This screen shot illustrates something very cool about the Atom feed format. (If you’ve written an RSS parser but haven’t done Atom yet, you might find this interesting.)
What you’re looking at is part of the Atom spec (leftmost), then part of the list of files of my XML-related classes, then the interface for a class named RSAtomPerson.
(Note to people who don’t program in Cocoa: the â€œRSâ€ prefix is there because, in Cocoa, you typically prefix your class names with some initialsâ€”your own, your company’s, or the name of the project.)
Atom is more complex than RSS, yesâ€”but, at the same time, the Atom folks did a cool thing that mitigates this complexity: they defined certain â€œconstructsâ€ that are re-used in different places. If you’re using an object-oriented language (such as Objective-C, Python, and C++) you can map these constructs to classes.
For example, a Person construct has three pieces of information: name, URL, and email address. Wherever a person is identified in an Atom feed, it uses a Person construct. You might have a whole bunch of Person constructs in a single feedâ€”but, each time a person is identified, it’s done the same way.
There are other constructs too, for content, dates, and links. (The Content construct is probably the most complex, but you only need to do it once, and then you can handle titles, summaries, and content elements.)
What I like about this is that it practically tells you how to write an Atom feed parser: it suggests breaking up your code into a collection of small classes for each of the different constructs. Though an object-oriented language isn’t required to parse Atom feeds, the Atom spec is a case of object-oriented thinking applied to feed formats, which is cool.
Going back to the screen shotâ€”you can see it, a direct line between the spec and its expression in object-oriented code. Nice.