Object-oriented programming (OOP) works by modeling applications on real-world objects. Three principles of OOP are encapsulation, inheritance, and polymorphism. They are given thorough coverage in this book.
The benefits of OOP are real. These are the reason why most modern programming languages, including Java, are object-oriented (OO). I can even cite two well-known examples of language transformation to support OOP: The C language evolved into C++ and Visual Basic was upgraded into Visual Basic.NET.
This section explains the benefits of OOP and provides an assessment of how easy or hard it is to learn OOP.
The benefits of OOP include easy code maintenance, code reuse, and extendibility. These benefits are presented in more detail below.
The reason for this is there is interdependency among different parts of a large program. When you change something in some part of the program, you may not realize how the change might affect other parts. OOP makes it easy to make applications modular, and modularity makes maintenance less of a headache. Modularity is inherent in OOP because a class, which is a template for objects, is a module by itself. A good design should allow a class to contain similar functionality and related data. An important and related term that is used often in OOP is coupling, which means the degree of interaction between two modules. Loosely coupling among parts make code reuse—another benefit of OOP—easier to achieve.
One of the main challenges to class reusability is creating good documentation for the class library. How fast can a programmer find a class that provides the functionality he/she is looking for? Is it faster to find such a class or write a new one from scratch? Fortunately, Java core and extended APIs come with extensive documentation.
Reusability does not only apply to the coding phase through the reuse of classes and other types; when designing an application in an OO system, solutions to OO design problems can also be reused. These solutions are called design patterns. To make it easier to refer to each solution, ach pattern is given a name. The early catalog of reusable design pattern can be found in the classic book Design Patterns: Elements of Reusable Object-Oriented Software, by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides.
In OOP, extendibility is achieved through inheritance. You can extend an existing class, add some methods or data to it, or change the behavior of methods you don't like. If you know the basic functionality that will be used in many cases, but you don’t want your class to provide very specific functions, you can provide a generic class that can be extended later to provide functionality specific to an application.
Java programmers need to master OOP. As it happens, it does make a difference if you have had programmed using a procedural language, such as C or Pascal. In the light of this, there is bad news and good news.
First the bad news.
Researchers have been debating the best way to teach OOP at school; some argue that it is best to teach procedural programming before OOP is introduced. In many curricula, we see that a OOP course can be taken when a student is nearing the final year of his/her university term.
More recent studies, however, argue that someone with procedural programming skill thinks in a paradigm very different from how OO programmers view and try to solve problems. When this person needs to learn OOP, the greatest struggle he/she faces is having to go through a paradigm shift. It is said that it takes six to 18 months to switch your mindset from procedural to object-oriented paradigms. Another study shows that students who have not learned procedural programming do not find OOP that difficult.
Now the good news.
Java qualifies as one of the easiest OOP languages to learn. For example, you do not need to worry about pointers, don’t have to spend precious time solving memory leaks caused by forgetting to destroy unused objects, etc. On top of that, Java comes with very comprehensive class libraries with relatively very few bugs in their early versions. Once you know the nuts and bolts of OOP, programming with Java is really easy.