5 ms·
I agree with some points and disagree with others here. I think I see three underlying problems: 1) Mutable state has consequences, and OO happens to highligh
by alaricsp 17y ago
I agree with some points and disagree with others here.
I think I see three underlying problems:
1) Mutable state has consequences, and OO happens to highlight some of them
2) The author would probably prefer generic functions, the "other way" to do OO IMHO, as they give you polymorphism while leaving the encapsulation issue to other mechansism, such as modules, as they mention.
3) OO examples are just terrible. Who on Earth writes a Bike class? I've seen whole arguments about whether Car should inherit from Vehicle and all this rubbish, all because people are taking vague and non-realistic examples, then getting tangled when they try and realise them. This is a road sure to lead to meaningless discussions and confusion on the parts of students. Instead, let's think about real software objects, such as files, windows, threads, and connections; and problem-domain objects such as users, orders and so on (as long as one is gently aware of the subtle issue that a 'user' is a person while the 'user' in the system is an object that models a person). OO can work well for modelling such objects.
- gdp 17y ago> Who on Earth writes a Bike class? http://java.sun.com/docs/books/tutorial/java/concepts/inheritance.html http://java.sun.com/docs/books/tutorial/java/concepts/inheri... http://www.novio.be/blog/?p=621 http://www.novio.be/blog/?p=621 http://www.roseindia.net/software-tutorials/detail/9172 http://www.roseindia.net/software-tutorials/detail/9172 The 'Bike' is a very common example used in OOP texts, hence why it was included in this discussion. I agree that it's kinda terrible, but this is the common textbook way that OO is described.
- jobu 17y agoAs stated in other posts here, the problem isn't so much the 'bike' example as the 'real world' context. Try using the bike example in a game context. You have to map controller buttons to bike.turnLeft(), bike.brake(), etc. These generic examples make a whole lot more sense in a valid context.
- kragen 17y agoTerrible textbooks aren't evidence that object-orientation isn't a useful style. They're evidence that it's popular and not trivial to understand. That's evidence that it is useful. Your post is more evidence that it's popular (since you're bothering to write about it even though you don't like it) and not trivial to understand (since you didn't bother to mention any of the important aspects of it).
- CodeMage 17y agoWho on Earth writes a Bike class? I've seen whole arguments about whether Car should inherit from Vehicle and all this rubbish, all because people are taking vague and non-realistic examples, then getting tangled when they try and realise them. While I agree with your point, I don't think the problem has anything to do with Bike, Car and Vehicle as a choice of classes and that files, windows, threads and connections are guaranteed to be used any better. The problem is that people who use these classes as an example don't put them in the context of a concrete domain. I'm pretty sure that I would write a Bike (or Bicycle) class myself if I was developing a bicycle racing game. So the advice to the authors should be to choose a problem domain (hopefully something fun) and stick to it. Whether Car inherits from Vehicle or User implements Principal depends, ultimately, on the problem domain.