I guess reducing conditional statements is a side effect of OOP because of polymorphism. IMHO, the major benefits of OOP are
- it makes code make sense;
With inheritance, you can easily define "relationships" between classes. e.g. Dog
IS A KIND OF Animal
, so Dog
inherits Animal
and Dog
has all the methods/functions and fields/variables that Animal
has. In most OO languages, if not all, there is this thing called interface
or protocol
. This defines another kind of relationship. A CAN BE USED AS relationship. With all these relationships, your code would probably make sense.
I think abstraction is the most important aspect of OOP. With classes and objects, you can write:
SuperMarket market = new SuperMarket();
goToTheSuperMarket(market);
Instead of
for (int i = 0 ; i < 1000 ; i++) {
walk();
}
turnLeft();
for (int i = 0 ; i < 1000 ; i++) {
walk();
}
...
Which is very functional.
- it encapsulate stuff in the code that external users don't need to know.
Encapsulation is in OOP is also very important too. I really like this feature. It allows you to hide some functionality of your class.
You see, there are so many other benefits to OOP. OOP not only reduces the number of conditionals.