HN user

mediaobelia

2 karma
Posts0
Comments2
View on HN
No posts found.

This avoids cluttering up the base class with loads of methods which won't be meaningful for most of the types

I'd argue that shelfLife is meaningful for all Items, and it's unnecessarily presumptuous to assume only Carts will want to know about shelfLife. Plus it's less code to simply add a shelfLife method in Item to return infinity. Later, when you realize expirationDate is what you really want to know you'll have less code to modify to get the logic correct.

In most cases you'll have fewer problems doing things the traditional OO way and sending the expirationDate message directly to the item.

Biological taxonomy is just not a good analogy. Object behavior hierarchies aren't analogous to any real world thing, IME. They are what they are.