I want to note, the purpose of classes and other fundamentally important language and technology features is not exactly "simplifying" anything. They create fundamentally new approaches. Even though the final result can be compared with some non-OOP solution; then, the OOP solution can look much simpler and maintainable. However, this is not the point. The real point it to solve much more complex problems as yours in much more efficient and maintainable manner. In other words, the point is avoiding poor solutions at all, so you would not have a material for comparison in "simplicity" (which is, by the way, a very fuzzy notion, to discuss it seriously here).
A language that doesn't affect the way you think about programming, is not worth knowing.
Ultimately, this is perfectly true for OOP. It gives you principally new mechanism, first of all,
dynamic dispatch based on the mechanism of
virtual methods, and, thanks to it,
late binding and
polymorphism. Please see:
https://en.wikipedia.org/wiki/Dynamic_dispatch[
^],
https://en.wikipedia.org/wiki/Virtual_function[
^],
https://en.wikipedia.org/wiki/Late_binding[
^],
https://en.wikipedia.org/wiki/Polymorphism_%28computer_science%29[
^].
If you don't use it, your "classes" could be almost pointless, some way of code structuring at best. There are so many developers who use many classes (and sometime event virtual functions) without understanding of their true purpose and even the trace of OOP. Everything without dynamic dispatch mechanism (including encapsulation and inheritance) is just prerequisite for real OOP. Using classes just for sake of using classes (as well of some other language features) is one of the common mistakes.
Now, I would like to bring your attention to what I think is the worst in your code. This is
immediate constants 1, 2, 8 and 9 hard coded in lines like
case 9:
this is not maintainable. You could at least use some
enum
declaration.
And every developers needs to read this, first of all:
Peter Norvig, Teach Yourself Programming in Ten Years,
http://norvig.com/21-days.html[
^].
—SA