2 ms·
There are many times when the objects really do have both data and behavior -- glancing at the real code that was the basis of my example, I see that the Loggin
by mcherm 15y ago
There are many times when the objects really do have both data and behavior -- glancing at the real code that was the basis of my example, I see that the LoggingDatabaseConnection has real state (the place to log to) and the pool flushing one has real state (keeps track of open cursors so they can be auto-closed when it is returned to the pool).
Of course, you also could be (and I was) using a deficient language like Java which doesn't HAVE any way to use a function or lambda. But I agree with you: a simple lambda a better solution where it is available.
And this kind of use is quite far from what Alan Kay intended when he designed SmallTalk. The original idea was that the objects would correspond to real-world entities. I would contend that since then OOP has evolved, and now the key idea of an object is the pairing of data and methods. Choosing the abstractions which will make the code most readable is one of the great challenges of programming well, and I find that just going for the nouns every time is NOT the best answer.