Object-Oriented Programming (OOP)

FIELDS OF STUDY

Software Development; Programming Methodologies; Computer Science

ABSTRACT

Object-oriented programming (OOP) is a paradigm based on objects that act as containers for data and functionality that interoperate to create the final application. Object-oriented programming languages (OOPLs) are based on the OOP paradigm. They were designed to improve upon traditional procedural programming.

PRINCIPAL TERMS

UNDERSTANDING OBJECT-ORIENTED PROGRAMMING

Object-oriented programming (OOP) is a paradigm based on objects that are containers for the data and functionality. These objects work together to form the completed program. A class defines what properties an object has and what functionality it provides. The properties represent the object's state, which is stored in a field or variable. The functions, or methods, define the object's behavior. For example, an airplane object would have properties (states) such as wingspan, speed, weight, and color and have methods (behaviors) such as taxi, take off, climb, descend, turn, and land. The methods and properties that an object must make available for use by other components in the program are known as its interface. Related classes and interfaces are organized into groups called packages.




The benefit of object-oriented design lies in the reusability of the object database. Because each object has only one job, the code for an object remains applicable for any instance where the object is needed.





The benefit of object-oriented design lies in the reusability of the object database. Because each object has only one job, the code for an object remains applicable for any instance where the object is needed.

In the real world, many objects share the same properties and functionality. For example, all aircraft can take off and land and share common properties, such as speed. However, specific types of aircraft offer added functionality and properties that distinguish them from other types. For example, helicopters can hover as well as take off and land. In this way, a helicopter can be thought of as a specialist class of aircraft. OOP models this concept using a technique called “inheritance.” Using inheritance, an aircraft class could be created that includes a takeoff and land method, and then a helicopter child class could inherit that functionality from the aircraft parent class and add the hover functionality. Similarly, an interface for aircraft would require that any object within the aircraft class have the methods for take off and land.

Object-oriented programming languages

(OOPLs) are based on the OOP paradigm. There are different types of OOPLs. Pure OOPLs such as Java and Ruby are based solely on OOP. Hybrid languages, such as Python, are based primarily on the OOP approach but support elements of the procedural programming paradigm. The final type are procedural languages that have been extended to include OOP concepts, such as COBOL and Fortran.

IMPROVING SOFTWARE DEVELOPMENT

OOPLs were designed to improve upon procedural languages. They allow greater modularity of code than do procedural languages. This makes it easier to prevent and correct problems within the program. OOPLs offer strong data integrity and data security because an object's methods and properties can be made private, or hidden. OOPLs work well with all types of data, unlike string-oriented languages, which are designed to work with strings of characters. OOP programs are also easy to extend as new features are needed. OOPLs also promote the reuse of code through inheritance. They are easy to scale and are a good fit for applications that need to adapt to future changes. OOPLs are good for projects where developers who work independently on very different systems need to collaborate with one another, as the details do not need to be shared or accessed by every developer.

The different types of OOPLs have different strengths and weaknesses. Pure languages offer the benefits of OOP while preventing the errors and inefficiencies that occur in procedural languages. However, they lack the ability to use procedural approaches when they would be the best choice. Hybrid languages offer the benefits of OOP while affording the programmer the flexibility to use certain procedural techniques when appropriate.

SAMPLE PROBLEM

A developer is creating code that will be used to perform basic calculations like addition and multiplication. The following is an early version that only offers the ability to perform the addition of two numbers.




Object-Oriented Programming (OOP)

Identify the classes, instance variables, and methods within the code.

Answer:

The first section of code defines a class, Calculator, that has two properties (input1 and input2) and one method (Add) that adds two numbers together and returns the result. Two variables are defined in the class, number1 and number2.

Two variables are defined in the instance of the calculator class created in the addNumbers() method. The first is the myCalculator variable. This variable is used to reference the instance of the Calculator object created in the method. The second variable is the myResult variable, which is used to store the value returned when the function calls the myCalculator.Add method.

SUCCESSFUL SOFTWARE

OOP offered a new programming paradigm that addressed many of the shortcomings of procedural and string-oriented programming. It also allowed the development of hybrid languages that gave programmers access to the best features of both approaches. OOPLs, both pure and hybrid, have become the most widely used languages and grown to dominate software development. The ability of OOPLs to incorporate other paradigms will likely allow them to remain relevant as new programming paradigms are developed.

—Maura Valentino, MSLIS

Belton, Padraig. “Coding the Future: What Will the Future of Computing Look Like?” BBC News, BBC, 15 May 2015, www.bbc.com/news/business-32743770 . Accessed 24 Feb. 2016.

Friedman, Daniel P., and Mitchell Wand. Essentials of Programming Languages. 3rd ed., MIT P, 2008.

Haverbeke, Marijn. Eloquent JavaScript: A Modern Introduction to Programming. 2nd ed., No Starch Press, 2014.

MacLennan, Bruce J. Principles of Programming Languages: Design, Evaluation, and Implementation. 3rd ed., Oxford UP, 1999.

Schneider, David I. An Introduction to Programming Using Visual Basic. 10th ed., Pearson, 2016.

Scott, Michael L. Programming Language Pragmatics. 4th ed., Morgan Kaufmann Publishers, 2016.

Van Roy, Peter, and Seif Haridi. Concepts, Techniques, and Models of Computer Programming. MIT P, 2004.

Weisfeld, Matt. The Object-Oriented Thought Process. 4th ed., Addison-Wesley, 2013.

Zakas, Nicholas C. The Principles of Object-Oriented JavaScript. No Starch Press, 2014.