What is Object-Oriented Programming

Object-oriented programming is a method of developing software in which the structure of the software is determined by objects interacting with one another to do a job. This interaction occurs through the exchange of messages between the objects. An object can perform an action in response to a message.

In the world around you, you interact in an object-oriented environment. To go shopping, for example, you interact with a car object. An automobile item is made up of several things that work together to transport you to the destination. Put the key in the ignition and spin it. An electrical signal is sent to the starting item, which interacts with the engine to start the automobile.

As a driver, you are isolated from the logic of how the objects of the system work together to start the car. You just Initiate the sequence of events by executing the start method of the ignition object with the key. You then wait for a response (message) of success or failure.

Similarly, users of software programs are isolated from the logic needed to accomplish a task. For example, when you print a page in your word processor, you initiate the action by clicking a print button. You are isolated from the internal processing that needs to occur; you just wait for a response telling you if It printed.

In the software program, the button object interacts with a printer object, which interacts with the actual printer to accomplish the task of printing the page.

The Characteristics of OOP

This section will provide some basic concepts and words common to all 001′ languages. Don’t worry about how these ideas are implemented in a certain programming language. As you learn more about OOP design and implementation, I hope you will understand the ideas better.

We live in an object-oriented world. You’re a thing. You can interact with objects. You are an object with data like height and hair colour. Also, you have techniques that you do or that are done to you, like eating and walking. So, objects? An object in OOP is a structure for storing and manipulating data.

For example, say you wanted to track product inventory data. You’d construct a product object to manage and use product data. If you want your app to print, you work with a printer object that manages the data and methods required to communicate with your printers.

Abstraction

When you interact with objects in the world, you are often only concerned with a subset of their properties. Without this ability to abstract or filter out the extraneous properties of objects. you would find it hard to process the plethora of information bombarding you and concentrate on the task at hand.

Due to abstraction, two individuals dealing with the same object typically deal with distinct subsets of characteristics. Like when I drive my vehicle. The car’s speed and direction must be known. Because the automobile has an automatic gearbox, I don’t need to know the engine’s RPM.

On the other hand, this information would be critical to a mutant driver, who would not filter It out. When constructing objects in OOP applications, It Is important to Incorporate this concept of abstraction.

The objects include only the information that Is relevant In the context of the application. If you were building a shipping application, you would construct a product object with attributes such as size and weight. The colour of the Item would be extraneous information and would be ignored. On the other hand, when constructing on the order-entry application, the colour could be important and would be included as an attribute of the product object.

Encapsulation

Another important feature of OOP is encapsulation. Encapsulation is the process in which no direct access is granted to the data; instead, it is hidden. If you want to gain access to the data, you have to interact with the object responsible for the data. In the previous inventory example, if you wanted to view or update information on the products, you would have to work through the product object.

To read the data, you would send the product object a message. The product object would then read the value and send back a message telling you what the value is. The product object defines which operations can be performed on the product data. If you send a message to modify the data and the product object determines it is a valid request, it will perform the operation for you and send a message back with the result. You experience encapsulation in your daily life all the time.

Consider an HR department. They enclose (conceal) personnel data. They decide how to utilise and modify data. Any requests for personnel data or updates must go via them. Network security is another. A network security administrator must be contacted for any security information or policy changes.

The network users’ security data is encapsulated. Encapsulating data makes your system’s data more safe and dependable. You understand how data is accessed and what actions are done on it. This facilitates software maintenance and troubleshooting. You may also change the methods used to work with the data, but you don’t have to change the other objects that utilise the method.

Polymorphism

Polymorphism is the ability of two different objects to respond to the same request message in their own unique way. For example, I could train my dog to respond to the command bark and my bird to respond to the command chirp. On the other hand, I could train them to both responds to the command speak. Through polymorphism, I know that the dog will respond with bark and the bird will respond with a chirp. How does this relate to OOP?

You can create objects that respond to the same message in their own unique implementations. For example, you could send a print message to a printer object that would print the text on a printer, and you could send the same message to a screen object that would print the text to a window on your computer screen.

Another good example of polymorphism is the use of words in the English language. Words have many different meanings, but through the context of the sentence, you can deduce which meaning is intended. You know that someone who says “Give me a break!” is not asking you to break his leg! In OOP you implement this type of polymorphism through a process called overloading. You can implement different methods of an object that have the same name.

The object can then tell which method to implement depending on the context (in other words, the number and type of arguments passed) of the message. For example, you could create two methods of an inventory object to look up the price of a product. Both these methods would be named getPrice. Another object could call this method and pass either the name of the product or the product ID.

The inventory object could tell which getPrice method to run by whether a string value or an integer value was passed with the request.

Inheritance

Most real-life objects can be classified into hierarchies. For example, you can classify all dogs together as having certain common characteristics such as having four legs and fur. Their breeds further classify them into subgroups with common attributes such as size and demeanour.

You also classify objects according to their function. For example, there are commercial vehicles and recreational vehicles. There are trucks and passenger cars. You classify cars according to their make and model. To make sense of the world, you need to use object hierarchies and classifications.

You use inheritance in OOP to classify the objects in your programs according to common characteristics and functions. This makes working with the objects easier and more intuitive. It also makes programming easier because it enables you to combine general characteristics into a parent object and inherit these characteristics in the child objects.

For example, you can define an employee object that defines all the general characteristics of employees in your company. You can then define a manager object that inherits the characteristics of the employee object but also adds characteristics unique to managers in your company. Because of inheritance, the manager object will automatically reflect any changes to the characteristics of the employee object.

Aggregation

Aggregation is when an object consists of a composite of other objects that work together. For example, your lawn mower object is a composite of the wheel objects, the engine object, the blade object, and so on. In fact, the engine object is a composite of many other objects. There are many examples of aggregation in the world around us.

The ability to use aggregation in OOP is a powerful feature that enables you to accurately model and implement business processes in your programs.

Show More

Leave a Reply

Back to top button