Object-Oriented Programming (OOP) Concepts Explained

What is Object-Oriented Programming (OOP)?

Acronym: Object-Oriented Programming, such as JAVA-based programming, is not structured; it addresses natural problems.

Objects: The Building Blocks of OOP

Objects are the building blocks of OOP. They are real-world representations, for example, a pencil. An object has two characteristics: state and behavior:

  • State: Parameters that define and differentiate it from other objects of the same type.
  • Behavior: Actions performed by objects.
  • The parameters or variables that define the state of an object are called attributes or member variables.
  • The actions performed by objects are called methods or member functions.

The attributes of an object should be hidden from the rest of the objects; that is, they will not be able to directly access the attributes of an object to change its state or consult it. To access the attributes of an object, you should use methods. The act of hiding the internal implementation of an object, that is, how it is built and its components, is called encapsulation.

Classes: Blueprints for Objects

A class is a template or prototype that defines a particular object type. A class defines the attributes and methods that an object will have. Through classes, we create or instantiate objects of the same type. These objects are distinguished from each other through their state, i.e., the value of their attributes.

Messages are the way different objects communicate with each other. An object by itself is not very helpful but is often used within an application or program that uses other objects.

Encapsulation: Protecting Data

Encapsulation covers the information stored, and you can only obtain information and specify which actions are performed by what is commonly called the object’s interface, which will consist of public methods.

The data and the implementation are hidden from other objects that interact in the program, which greatly enhances the protection of data and structures against external modifications to the object.

Abstraction: Simplifying Complexity

Abstraction refers to the ability to ignore certain aspects of reality in order to facilitate the completion of a task.

Inheritance: Reusing Code

Inheritance in OOP is a fundamental mechanism that can also be defined as the transmission of characteristics from parents to children, understanding here features like methods and attributes of a class. The child class may add attributes, methods, and refine the methods of the parent class.

Polymorphism: Many Forms

The term polymorphism suggests the possibility that the same message, sent to different objects, executes different methods. This means we can define two different classes in two transactions with the same name and appearance but with different implementations for each class.

Overloading: Multiple Methods, Same Name

Method overloading occurs when a class has methods with the same name but differ either in the number or type of parameters of those methods.

Java: An Object-Oriented Language

Java’s origins date back to 1990. Java is a programming language, object-oriented.

Applets: Interactive Web Programs

An applet is a dynamic and interactive program that can run within a Web page that is loaded into a Web browser, and another property for the use of Java servlets on the Internet are.

Servlets: Server-Side Java

A servlet is a Java application that runs on a server and attends to a series of requests from a client who is a Web browser. Unlike applets, servlets have no graphical interface.