Hacker News new | past | comments | ask | show | jobs | submit login

Humans walk(), eat() and rest().

Invoices don't do shit.

We need both.




If I understand you correctly you're saying something like TweedHeads.walk(), TweedHeads.eat() and TweedHeads.rest() make it sensible to define Human as a class.

But then how would you attach makelove() or fight() or discuss() to a single Human? When do we use TweedHeads.discuss(visitor4rmindia) vs visitor4rmindia.discuss(TweedHeads)?


It took me a minute to realize that TweedHeads was an object and not a class.


discuss() and fight() and makelove() are usually (hopefully!) commutative.

I think the more interesting observation to make is: what is the type of the argument to discuss? SentientBeing? CanDiscussMixin?

In the first case, I bet you could imagine objects to "discuss" with that would only awkwardly inherit from SentientBeing, and in the second, your major objects will quickly grow loads of mixins. Of course there's also the "implements interface" appproach.

I think all the models break down at some point...maybe the choice of which one to use is dependent on the problem.


Actually, what I was leading up to was that _neither_ is "valid". The better way (in this case) would be:

  discuss (TweedHeads, visitor4rmindia);
This, to me, underlines some of the problems of the OOPS approach. Everything starts "looking like" methods even when they would be more natural as simple functions.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: