4 ms·
I think one major problem with OO was that many people did not really get object oriented thinking (and I was probably among them). It is very easy to do object
by jpalomaki 10y ago
I think one major problem with OO was that many people did not really get object oriented thinking (and I was probably among them). It is very easy to do objects that are just dummy data container instead of smart things that interact with each other.
Just think how many Java tutorials started with the procedural "Hello World" example and then proceeded to introduce objects and taught the idea of encapsulation by reminding how important it is to protect the private members by creating a list of get/set methods that are used to access them.
This leads to objects with interface like this:
class Person {
public void setStomachContents(...);
public void getStomachContents(...);
public void setThoughts(...);
}
While I believe a "proper" object would have interface more like this:
class Person {
public void eat(...);
public void listen(...);
public Event<ProcessedFoodItem> output;
}
- sbov 10y agoYou are glossing over a lot of design decisions by excluding method arguments. Whether or not that is a proper solution depends upon the requirements. A more useful example for beginners would be showing when you want an "eat" on a person class vs an "eaten by" on a food class vs when you need to pull out something more heavy handed. Eg if your only axis of change is the foods you eat, and behavior is based primarily upon food, person as a dumb bag of data is likely the correct answer. Your behavior should probably be in a food class.
- technion 10y agoOne of my complaints on the subject is that academia is so fascinated with OOP. I took multiple courses on the subject, and the issue I'm hitting is that your "proper" example would probably have failed me a course, because the "bad" example you've given is exactly what we were taught.
- jpalomaki 10y agoTwo books that affected my thinking on the subject were Domain Driven Design[1] by Eric Evans and Object Thinking[2] by David West. Many years since I read the books and I don't claim to have studied them in detail so I'm not saying if they were good or bad, but at least I got some ideas out of them. [1] https://www.amazon.com/Domain-Driven-Design-Tackling-Complexity-Software/dp/0321125215/ref=sr_1_1?ie=UTF8&qid=1489391539&sr=8-1&keywords=evans+object+oriented https://www.amazon.com/Domain-Driven-Design-Tackling-Complex... [2] https://www.microsoftpressstore.com/store/object-thinking-9780735691308 https://www.microsoftpressstore.com/store/object-thinking-97...