Better HN
topnewbestaskshowjobs
Log inSign up

mediaobelia

2 karma · joined Mar 20, 2016 (10y ago) · 2 submissions

Submissions

comment 10y ago · link · parent

> 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.

comment 10y ago · link · parent

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.