Theory of Programming Languages/Object Oriented Programming

This is a lesson in in the course, Theory of Programming Languages, which is a part of The School of Computer Science

Objective
Students will learn the history of object oriented programming, and will understand the key features that make it distinct.

Students will be able to answer:
 * 1) What is notable about object oriented programming?
 * 2) What problems did object oriented languages solve?
 * 3) What modern languages are object oriented?

Object-Oriented Programming


Object-oriented programming (OOP) is a programming paradigm that uses "objects" – data structures consisting of data fields and methods – and their interactions to design applications and computer programs. Programming techniques may include features such as information hiding, data abstraction, encapsulation, modularity, polymorphism, and inheritance.

Object-oriented programming is a paradigm first developed in the 1960's that has many unique characteristics. It was not commonly used in mainstream software application development until the early 1990s. Many modern programming languages now support OOP. If you are currently learning programming, it is likely that you are learning languages which are at least partially object oriented. (Examples include: Java, C++, Python)

One of the first unique characteristics of this paradigm is the use of "objects". Objects are data structures which contain "fields" and "methods" to describe their content and functionality. Objects themselves correspond to types, which often correspond to the data relevant to the methods it contained. For example, a "person" object might contain a name and a function which could print that name. Multiple objects can be created from one type, "Steve" and "Martha" might both be people but contain different data.

Let's consider that as an example: (This is written in Java) The class "Person" is like a cookie cutter, where we design what a person contains. Then we can use that class to make objects - in this case the objects steve and martha.

Programs written in other non object-oriented languages (such as BASIC) are often only long strings of commands. These strings may be broken up into subroutines, but the code remains accessible from all other parts of the program (global in scope). This can cause bugs to have wide reaching ramifications. Object-oriented languages can bundle up data into discrete objects, and thereby evade this problem. The data is accessed by calling specially written methods which can modify or retrieve information from other sections of code. These act as a kind of intermediary, which quarantines different sections of code.

By concealing the actual nitty gritty programming behind methods used to access data, programming can be made much easier to read and contribute to - you don't need to know exactly how a program might read text from a file, but you can write an object which utilizes that functionality to check the spelling on the text. This concept is called abstraction. This offers an additional boon in that command names may be reused, programmers need not think of brand new function names when contributing to a large project.

Lets enumerate through the core ideas behind Object-oriented programming:

Encapsulation
Encapsulation is a twofold notion. First, it is the process by which data is bundled together with operators (in the example above, the Person object had the data Name and a method sayName which printed that data). Secondly, it is the hiding or limiting of access to data so as to ensure security,

Consider this example from Wikipedia, which displays the limiting of access to secure data: As the comments explain, because the balance of the account is labeled as private, it cannot be modified.

Object-oriented programming language examples

 * C++
 * C
 * Objective-c
 * Java
 * PHP
 * Python
 * Ruby
 * Smalltalk

Assignments

 * 1) In pseudocode (or an OO language) write a series of objects which inherit characteristics from other objects. For example: a house object which inherits "building material" from a "building" object, and inherits size from "thing" object.
 * 2) Write a list of five well known object oriented programming languages.
 * 3) Write a list of five problems which are well suited for object oriented programming languages.


 * Previous Lesson
 * Next Lesson
 * Course Home Page