How Java Supports Software Reusability
Java is a programming language originally developed by Sun Microsystems that is well known for its heavily object-oriented design and nearly complete cross-platform abilities. Software reusability stems from the idea that a programming problem should only be solved once and, from then on, the code for the solution simply copied into a project that needs it.
-
The Problem
-
At first glance, code reusability sounds as simple as copy and pasting code. However, code written specifically for another project tends to make use of things specific to that project, and it is sometimes easier to rewrite the code from scratch than to make the modifications needed to make it work in a new project.
Object Oriented
-
One way Java attempts to enforce software reusability is by enforcing object-oriented principles. Many of the practices that lead to overly project-specific coding in languages such as C are simply impossible in Java.
-
Java Interfaces
-
Another way Java addresses this problem is through the use of interfaces. Interfaces are an optional feature of Java that allow a developer to define a set of method calls needed to complete a task, and then separately write a class that implements that interface. This ensures that, in the future, the code can be used in any situation that the original interface could be used in. Ideally, developers also need to play along, by writing methods and classes that implement interfaces and that require broader interfaces rather than project-specific classes whenever possible.
-