Goodbye, shitty "Car extends Vehicle" object-orientation tutorial
11–20 of 134 posts
Re: Goodbye, shitty "Car extends Vehicle" object-orientation tutorial
#12Fairly annoying how quickly a mostly useless rant such as this has jumped to the top of HN.
Re: Goodbye, shitty "Car extends Vehicle" object-orientation tutorial
#13> You can’t add code to ducks. You do if you are creating a piece of software to track ducks. I don't get the impression that the person who wrote this ever had to seriously teach software development to software developers. Simplistic metaphors are used so frequently for this kind of thing because it prevents the learner from having to ascend more than one conceptual hurdle at a time. The alternative that he's propo…
I agree, but he gets to a much simpler, teachable example near the end, which is representing shapes. Mathematically, a circle is an ellipse, and an ellipse is a polygon. It's much cleaner than the biology or work-place inspired taxonomy. A simple drawing program can feel less contrived, but, then again, so can simple games that use an object hierarchy unrelated to polygons. Fundamentally, though, I do agree with you…
Well, the circle-ellipse problem complicates that example a little bit: http://en.wikipedia.org/wiki/Circle-ellipse_problem.
Re: Goodbye, shitty "Car extends Vehicle" object-orientation tutorial
#14Re: Goodbye, shitty "Car extends Vehicle" object-orientation tutorial
#15Re: Goodbye, shitty "Car extends Vehicle" object-orientation tutorial
#16> You can’t add code to ducks. You do if you are creating a piece of software to track ducks. I don't get the impression that the person who wrote this ever had to seriously teach software development to software developers. Simplistic metaphors are used so frequently for this kind of thing because it prevents the learner from having to ascend more than one conceptual hurdle at a time. The alternative that he's propo…
You can explain is-a using examples that actually make sense to model using inheritance, like a set of game objects that have an interface like: class GameObject { public: // Called every frame to update the object's logical state. void Update(GameState* state); // Called to draw the object. Draw(GraphicsContext* context); } class EnemySpaceship : public GameObject { /* ... */ }; class SpaceDebris : public GameObject…
it isn't pointless. It is the key point of the design : http://www.objectmentor.com/resources/articles/lsp.pdf
Re: Goodbye, shitty "Car extends Vehicle" object-orientation tutorial
#17The best explanation I found was Chapter 2 of Apple's "Object-Oriented Programming with Objective-C":
Every object has both state (data) and behavior (operations on data). In that, they’re not much different from ordinary physical objects. It’s easy to see how a mechanical device, such as a pocket watch or a piano, embodies both state and behavior.
http://developer.apple.com/library/mac/documentation/cocoa/c...
Re: Goodbye, shitty "Car extends Vehicle" object-orientation tutorial
#18Re: Goodbye, shitty "Car extends Vehicle" object-orientation tutorial
#19> You can’t add code to ducks. You do if you are creating a piece of software to track ducks. I don't get the impression that the person who wrote this ever had to seriously teach software development to software developers. Simplistic metaphors are used so frequently for this kind of thing because it prevents the learner from having to ascend more than one conceptual hurdle at a time. The alternative that he's propo…
Re: Goodbye, shitty "Car extends Vehicle" object-orientation tutorial
#20I think a simple example from GUI programming would do much better. How about window classes? I did something like this recently:
class Window {
public method show()
public method title(newTitle)
public method close()
}
Easy enough. What if I want a modal window though? Almost everything in it would be the same as a regular window, except I might need to do some things slightly different for show()ing and close()ing the window. Aha! A perfect example of an appropriate time to create a subclass: public class ModalWindow extends Window {
public method show()
public method close()
}
Programming tends to attract practical individuals. I think teaching "car extends vehicle" then is usually going to cause one of two results: either a student that then uses that approach all the time, even in cases where it's not warranted, because they don't understand when it's appropriate and when it's not; or a pragmatic student that resists using it because the given examples don't apply to anything that they're actually going to have any chance of working on.