What are the advantages and disadvantages of an object-oriented approach to programming

Benefits:

  • The object model is quite natural, since it is primarily focused on the human perception of the world, and not on computer implementation.
  • Classes allow you to construct from useful components with simple tools that abstract away from implementation details.
  • Data and operations on them form a definite entity, and they are not spread throughout the program, as is often the case in procedural programming, but are described together. Localization of code and data improves the visibility and maintainability of software.
  • Encapsulation allows you to introduce modularity, which makes it easier to parallelize the execution of a task across multiple workers and update versions of individual components.
  • The ability to create extensible systems.
  • Using polymorphism is useful when:
    • Processing heterogeneous data structures. Programs can work without distinguishing the type of objects, which greatly simplifies the code. New species can be added at any time.
    • Changes in behavior during execution. At runtime, one object can be replaced with another, which makes it easy, without changing the code, to adapt the algorithm depending on which object is used.
    • Implementation of work with heirs. Algorithms can be generalized so that they can already work with more than one kind of object.
    • Opportunities to describe application-independent parts of the domain in the form of a set of universal classes, or a framework, which will be further expanded by adding parts specific to a particular application.
  • Code reuse:
    • Reduces development time that can be devoted to other tasks.
    • Reusable components usually contain far fewer bugs than newly developed ones, as they have been tested more than once.
    • When a component is used by several clients at once, the improvements made to its code simultaneously have a positive effect on many programs that work with it.
    • When a program relies on standard components, its structure and user interface become more uniform, making it easier to understand and easier to use.

Disadvantages:

  • In complex class hierarchies, fields and methods are usually inherited from different levels. And it is not always easy to determine which fields and methods actually belong to a given class.
  • The code for processing a message is sometimes "smeared" in many methods (in other words, processing a message requires not one, but many methods that can be described in different classes).
  • Documenting classes is more difficult than it was with procedures and modules. Since any method can be overridden, the documentation should say not only what a given method does, but also what context it is called in.
  • Inefficiency and wasteful allocation of memory at runtime (due to overhead of dynamic linking and runtime type checking).
  • Excessive versatility. There are often more methods than the current program actually needs. And since redundant methods cannot be removed, they become dead weight.

Read also:


Comments

Popular posts from this blog

Methods for reading XML in Java

XML, well-formed XML and valid XML

ArrayList and LinkedList in Java, memory usage and speed