I'm writing documentation for an object-oriented language, and I wonder what kind of classes would be a good example for inheritance.
Some common examples:
class Person {
}
class Employee extends Person {
}
Currently my favorite, but I don't like Person->Employee because 'Employee' does not exactly look like fun.
class Bicycle {
}
class MountainBike extends Bicycle {
}
I found this in some Java tutorial, but it's not really obvious what attributes a bike should have.
class Animal {
}
class Bird extends Animal {
}
Same as the bicycle.
class A {
}
class B extends A {
}
Too abstract. The main problem is that such a class will need even more abstract attributes and methods.
Does anyone have a better example for a simple class hierarchy?
I like the idea of using Printers as an example. Say you're working for HP, Brother, Lexmark, or some other entity, and you need to come up with a program that is capable of generating driver specific modules for a variety of operating systems.
After demonstrating inheritance you can move towards abstraction and method overload/override. The init method in Printer class is a good candidate for abstraction. Subclasses will need to implement their own initialization processes.
You can also extend this example and start demonstrating proper usage of Interfaces and Composition. What is the difference between a IS-A and HAS-A concept? Some printers may have WiFi and Bluetooth capabilities. Or, Some of the InkJet printers may have scanning capabilities while other only have feeders etc. How would you implement this?
I think using printers is more closely related to computers and computer science in general. You can use this example and even further demonstrate examples that deal with networking between embedded systems and PC's, SmartPhones, and other IoT's.
Being a counter-strike game admirer this is what I would love to share:
Webshop could be a good option as well.
If you are into video games could be something like this: