4 ms·
Absolutely what happened to me. A class is not a car, you don't explode your car when you go off road, create a SUV using the base of the car along with what's
by zeth___ 8y ago
Absolutely what happened to me.
A class is not a car, you don't explode your car when you go off road, create a SUV using the base of the car along with what's in the trunk, then do it back again when you reach a road.
Analogies are a terrible way to teach. Both dogs and cows are mammals with 4 legs and a tail, but you will have an interesting experience playing catch with a cow and trying to milk a dog.
I only learned what a class is and why it matters after writing a bunch of C spaghetti code trying to keep track of special_fn_for_strings, special_fn_for_ints, special_fn_for_big_ints, etc. You can teach that way quite easily if you have more than a week to do it in.
- slobotron 8y agoSome would argue that OOP and class hierarchies are orthogonal concepts, so any analogy with biological taxonomies is bound to leave you unenlightened for a long time.
- gleenn 8y agoAnd yet sadly that almost always what authors reach for when looking to explain OOP...
- ibeckermayer 8y agoCan you go into a bit more detail about what you mean with these special fn_for_* things? I learned OOP recently with all the animal->mammal->cat analogies, however those all seem to focus on inheritance and miss the key concept which might be summarized as “managing context”. Am I on the right track here?
- Majora320 8y agoI'm not the original commenter (and on mobile, so this response might be a little terse), but I think what he's talking about is polymorpism. For an example, if you have two classes, Int and String, and you have a method special_fn you want to implement for both in different ways, (e.g. "addition/concatanation"), you can either make a bunch of special_fn_* stuff, or simply create an interface SpecialFner with the special_fn method, and implement it for Int and Str. This lets you use this interface in other places without worrying about all the different versions of this function.