Object-Oriented Programming (OOP)

Object-oriented programming (OOP) is a type of computer programming that is based on the idea of objects, which are bundles of code. Some famous programming languages (e.g., Java, C++, and Python) are used for OOP. The bundles of code in OOP are useful because programmers can easily insert or remove them from programs and reuse them in other programs. OOP is useful to programmers because the objects can make programming less time-consuming and make coding errors less common. Although OOP has a number of benefits, it is not as flexible as some types of procedural programming.

89407595-100209.jpg89407595-100210.jpg

Major Principles of OOP

OOP is based on the idea of objects. In OOP, objects are bundles of code that have specific functions. All OOP objects have states and behaviors. This is similar to objects in the real world. For example, a cell phone—which is an object in real life—also has states and behaviors. The phone can be turned on or off, which are two of its states. The phone can also place calls, display the time, and more; these are all behaviors of the phone. The state of an object in OOP is stored in fields in the coding. Objects in OOP are used for many functions, and they can make programming simpler.

In OOP, objects are separated into different classes. Just as real-life objects can be classified by groups (e.g., tools, clothes, furniture), OOP objects can belong to different classes. The classes in OOP are blueprints that explain how objects in a particular class should be made.

Objects in real life have classes (e.g., houses), but they also have subclasses (e.g., ranches, cottages, mobile homes). Objects can also belong to subclasses in OOP. The subclasses are important because each member of the subclass can inherit particular traits from the main class. For instance, if the class of objects were houses and the subclass were mobile homes, the subclass would inherit certain traits, such as having rooms and a door, that are common to the main class. In the same way, a coding object that belongs to a subclass can inherit traits from its main class. This idea is called inheritance, and it is a fundamental concept in OOP.

Another fundamental idea people working with OOP have to understand is that idea of an interface. Objects in OOP have interfaces. Objects in everyday life have interfaces too. For example, a television has buttons a user can press to interact with it. A person can push the power button to turn the TV on and off. The TV's power has only two functions, so a person cannot make the TV do something it was not designed to do using the interface. A person could not change the colors on the TV screen using the power button. The TV's interface determines how people interact with the TV. In the same way, an OOP object's interface will allow the object to have specific, set functions. People can use an interface to make an object perform one of those functions. But a person cannot use the interface to make the object perform a function it was not designed for.

A package is another concept that is important to OOP. Packages are spaces that organize sets of related classes and interfaces. Packages are similar to folders in a filing system. Each folder has a name and holds similar types of information. Programs can include hundreds and even thousands of classes, so it is important to use packages to organize this information.

Encapsulation, data abstraction, and polymorphism are other important concepts in OOP. Encapsulation is the process of putting many pieces of data into a single unit. OOP allows programmers to put these pieces together, which hides unnecessary data from users. This provides users with a clear and simple interface. Data abstraction is another important concept. This aspect of OOP allows users to reuse objects and even small programs over and over again without fully understanding how they work. Just as a person can use a cell phone without understanding the elements that make it function, a programmer can use objects and subprograms without understanding the code that makes them work. A final important concept in OOP is polymorphism, which is related to abstraction. This concept allows users to give general commands to all members of a class, even though each member of the class may execute the command in a different way. A real-life example of this is a teacher asking two students to add together two numbers. One student may add the numbers together on paper. The other student may add the numbers together on a calculator. Even though the two students used different methods, both executed the action the teacher asked them to perform.

Benefits of OOP

OOP is popular with many programmers because it has a number of benefits. Objects that are used in OOP can be designed and written by one programmer and adopted by another. A programmer can use objects that another programmer has already written and tested for accuracy. Once an object is written and tested, it can be easily inserted into another program using OOP. Another benefit is that objects in OOP can be removed. If programmers find that a particular object is causing program errors, the problematic object can be removed without changing or deleting the entire program.

Although OOP is useful because objects can be easily added or removed, this type of programming does not allow programmers to simply string objects together to create a useable program. Objects are tools that programmers can use and reuse in a number of ways, but they are only building blocks that can be added to sound programming structures.

Bibliography

Doherty, Erin. "What Is Object-Oriented Programming? OOP Explained in Depth." Educative, 15 Apr. 2020, www.educative.io/blog/object-oriented-programming. Accessed 29 Dec. 2022.

Gillis, Alexander S. "Object-Oriented Programming (OOP)." TechTarget. 2022, www.techtarget.com/searchapparchitecture/definition/object-oriented-programming-OOP. Accessed 29 Dec. 2022.

Hock-Chuan, Chua. "Java Programming Tutorial: Object-Oriented Programming (OOP) Basics." Nanyang Technological University. Nanyang Technological University. Apr. 2013. Web. 11 Aug. 2015. www.ntu.edu.sg/home/ehchua/programming/java/J3a‗OOPBasics.html

"Lesson: Object-Oriented Programming Concepts." Oracle. Oracle. Web. 11 Aug. 2015. docs.oracle.com/javase/tutorial/java/concepts/index.html

Nakov, Svetlin. "Chapter 20. Object-Oriented Programming Principles (OOP)." Introduction to Programming with C#/Java Books. Svetlin Nakov and Team. www.introprogramming.info/english-intro-csharp-book/read-online/chapter-20-object-oriented-programming-principles/#‗Toc362296569

"Object-Oriented Programming." MDN Web Docs, 25 July 2024, developer.mozilla.org/en-US/docs/Learn/JavaScript/Objects/Object-oriented‗programming. Accessed 14 Nov. 2024.

"Object-Oriented Programming (C# and Visual Basic)." Microsoft Developer Network. Microsoft. Web. 11 Aug. 2015. msdn.microsoft.com/en-us/library/Dd460654.aspx