OO Concepts   «Prev  Next»
Lesson 6The uses and benefits of object-oriented programming
ObjectiveUses and benefits of object-oriented programming.

OO Programming helps you Manage Complexity

Like structured programming in legacy systems, object-oriented programming (OOP) is used to manage the complexity of software systems. However, OOP technology provides several advantages because they are easier to maintain, have more reusable components, and are more scalable. Identifying the source of errors becomes easier because objects are self-contained (encapsulation). The principles of good OOP design contribute to an application's maintainability.
  • Reusable: Because objects contain both data and functions that act on data, objects can be thought of as self-contained boxes (encapsulation). This feature makes it easy to reuse code in new systems. Messages provide a predefined interface to an object's data and functionality. If you know this interface, you can make use on an object in any context you want. OOP languages like Java make it easy to expand on the functionality of these boxes (polymorphism and inheritance), even if you do not know much about their implementation (again, encapsulation).
  • Scalable: OO applications are more scalable then their structured programming roots. As an object's interface provides a roadmap for reusing the object in new software, it also provides you with all the information you need to replace the object without affecting other code. This makes it easy to replace old and aging code with faster algorithms and newer technology.

OO Programming

Object-oriented programming was invented to manage simulations of processes. For example, a simulation of a phone network might involve many different customers, calling on a varied set of phone lines at varying and unpredictable times. Classes would model phone company equipment and resources. OOP also works well for applications that are user-interface intensive, especially graphical user interfaces. Classes commonly represent windows, menus, menu items, check boxes, text fields, lists, and much more. The user, rather than being restricted to a fixed set of commands, can generally do anything at anytime.
If there is one thing that distinguishes a problem that is right for object-oriented programming from one that is not, it is flow of control. If the program follows a very linear, step-by step approach, traditional programming can solve it fairly easily. On the other hand, if the program must continually respond to internal and external events that do not occur at precisely defined points, then the problem is likely a good candidate for an object-oriented solution. There are also a number of additional benefits in using OOP, such as code reuse and team programming, that you will see in later lessons.


Abstraction and inheritance are two fundamental concepts in object-oriented programming (OOP), widely used in languages like Java. Each offers distinct advantages that contribute to more efficient and maintainable code. Here's a detailed look at the benefits of both: Abstraction: Abstraction is the concept of hiding the complex reality while exposing only the necessary parts. It helps in reducing programming complexity and effort. Here are some advantages of using abstraction in Java:
  • Simplification: Abstraction simplifies the design of your system by hiding the complex implementation details from the user. Developers can use objects and methods without knowing the intricacies of their workings.
  • Modularity: It allows you to separate the interface from the implementation. The user interacts with only the interface, thus enabling the developer to modify the implementation without affecting the interface.
  • Reusability: Abstraction enables the programmer to reuse components and methods, which can reduce development time and increase the reliability of software through previously tested and proven components.
  • Scalability: Systems designed with abstraction are more scalable since changes in the underlying code or technology generally don’t affect higher-level components.
  • Maintainability: Changes to low-level code can be made with minimal or no impact on the high-level system, making it easier to manage and update.

In Java, abstraction is primarily achieved through abstract classes and interfaces. These structures allow you to define required methods that must be implemented, ensuring a certain level of uniformity in how objects behave.
Inheritance: Inheritance allows a class to inherit properties and behaviors (methods) from another class. Considered one of the pillars of OOP, it offers the following advantages:
  • Code Reusability: Inheritance supports the reuse of existing code. You can create a new class based on an existing class. The new class inherits all of the properties and behaviors of the existing class, and new features can be added or existing ones modified.
  • Method Overriding: Derived classes can modify inherited methods. This is useful for creating a general class structure that provides generic methods, which can then be tailored by derived classes.
  • Hierarchy: Inheritance helps to create a hierarchical classification of classes that reflects real-world relationships. This makes the structure of software easier to understand and manage.
  • Polymorphism: Through inheritance, objects of different classes can be treated as objects of a common super class, primarily when a subclass extends a superclass. This is key to many Java frameworks that use polymorphic behaviors, like method overriding and interface implementation, to interact with user-defined and built-in classes.

In Java, inheritance is straightforward to implement, making it a useful tool for creating comprehensive class hierarchies that reflect real-world relationships and improve code manageability and extensibility. Both abstraction and inheritance are powerful concepts in Java that help software developers build robust and scalable applications efficiently. They enhance readability, reduce redundancy, and improve the software development life cycle.

Other Approaches to Software Engineering

Although most of today's problems are solved with either a structured or an object-oriented solution, other approaches have their advocates. Here are some other approaches to software development.
  • Functional programming: Functional programming sounds a lot like procedural programming, but in reality it's quite different. Functional programming concentrates on the evaluation of expressions rather than the execution of commands. Functional languages include Lisp, Scheme, and ML. These languages and this style of programming are popular in some universities, but have not really caught on in the rest of the world. The primary uses of functional programming are in teaching and artificial intelligence.
  • Data flow programming: In data flow programming, the key element is data that flows between functions. Flow of control is not precisely specified; only dependency relationships that specify which operations must complete before other operations must begin are specified. Data flow programming is in some sense orthogonal to OOP. Both techniques and styles can profitably be used in one language. Data flow programming hasn't caught on in a big way. Perhaps the most popular environment for it is Pictorius's Prograph.
  • Fourth-generation Languages: Fourth-generation languages, of which the most popular is SQL (Structured Query Language), define the answer that's wanted rather than the method by which the answer is generated. For example, a typical fourth-generation language inquiry looks like this
    SELECT LastName FROM SalesPeople 
    WHERE Quota > 5000
    

    You neither know nor care what data structure is used to store the information you're requesting. It could be an array. It could be a linked list. It could be a hash table. Similarly, you neither know nor care what algorithm is used to search that data structure for the requested information.
  • The Spaghetti code Approach: Finally, I feel compelled to mention that one of the most popular, if not always the most effective, approaches is the quick-and-dirty, anything-that-works non-methodology. This methodology is often identified by a lack of 1) subroutines, 2) functions, or 3) classes, an almost complete lack of 1) comments, 2) flow control structures that spontaneously jump from place to place, and a general disdain for anything that might make the code more understandable. A quick-and-dirty solution is often adequate for small problems, especially those that need to work only once, but programmers who attempt to scale this up to more complex problems rapidly discover the need for more formal approaches.


SEMrush Software