"I have a mind like a steel... uh... thingy." Patrick Logan's weblog.

Search This Blog

Friday, June 25, 2004

Do objects have too much freedom?

Isaac Gouy quotes, in a comment on Jim's blog...
"But Smalltalk's mechanism suffers from a serious drawback: Initialization is not enforced. new creates objects but does not initialize them... A second drawback with both Smalltalk and Ruby is that initialize, being an ordinary method, does not chain: You must remember to begin your initialize methods with a call to the superclass's initialize method."
Hey, but this just plain, old message sending, as with any object. It just happens that that "object" is a class. That's the advantage, and the tradeoff.

So, in general, inheritance is not as good as composition. But why is *this* message sequence worse than any other?

Do objects have too much freedom?

1 comment:

Ian Bicking said...

Contracts would also address this, as the underlying criticism seems to be that there's a contract (perhaps implicit) that any instance of a class will be initialized in some way -- including in subclasses. Maybe it's even valid to have a contract that a certain section of code (a method definition for a particular class) will be run on instance creation (that would be a contract that addressed future compatibility in addition to current functionality).

A contract probably won't be statically checked. But it would probably express the requirement well, and provide early warning of object misuse.

Blog Archive

About Me

Portland, Oregon, United States
I'm usually writing from my favorite location on the planet, the pacific northwest of the u.s. I write for myself only and unless otherwise specified my posts here should not be taken as representing an official position of my employer. Contact me at my gee mail account, username patrickdlogan.