DNotes LLC

DNotes LLC

Drupal development, hosting, and consulting

OOP : Data and Logic Encapsulated

Listening to msonnabaum's talk entitled "We're getting OOP wrong and there's still time to fix it was refreshing to me, because it pointed out how D8's OOP implementation as it currently stands is missing out on many of the key benefits of OOP, and that's probably partially responsible for all the frustrated developers at present.

It also introduced me to a very concise statement of what OOP is all about - a definition that is doubtless one reason why so many people are excited about it:

One of the most fundamental concepts of objects is to encapsulate data with the logic that operates on that data. -- Eric Evans, Domain Driven Design

So, in D7, which is its own flavor of procedural code, we have the $node object, but it consists only of data; when you want to do something with that data, you have to call a separate function, e.g. node_save($node).

If we really implemented OOP, the logic to deal with the data would be encapsulated with that data, so you would simply call $node->save().

It's kinda nice, in a way. I hope one day I can say the same about PSR0.

Technologies: