Zebra0.com

systems object-modelingObject Oriented Programming Terminology

Object Oriented Programming Terminology

In the early days of computing, things (called entities today) were represented by data.

An employee might have data for name, Social Security number, hourly rate, etc.

A date would consist of month, day, and year.

An appointment would have a date, time, and place.

In a program, this data was usually stored as a data structure. In a database, one piece of data, such as employee name, is stored in a field. All of the data fields for one employee is called a record (or row), and the records for all of the employees is called a table.

The concept of object oriented programming was developed in the late 1980s. This new paradigm viewed things (now called objects), not just as data, but also the functions and procedures that might affect that object.

The concept of an Employee would still have data (now called attributes or properties) such as name, social security number, hourly rate, etc. but it would now also include how to compute pay, how to give an Employee a raise, or calculate commission. The ways to calculate pay, give a raise, or calculate commission are called methods.

A Date object would have the properties month, day, and year but would also have methods for finding the day of the week, or the next day. (This is non-trivial: the next day can be in the same month, the next month, or even the next year!)

Programming languages such as C++, Java, Python, and C# use object oriented programming extensively.  

A programmer creates a Class, such as the Date class. The code for the class includes the properties month, day, year, and the methods. The methods might include ways to guarantee that the month, day, and year are always valid. There might be a method to get today's date from the system clock, or to find the date one week from today. Often, the code for the class is in a separate file. After thorough testing, that class can be included in many programs. The concept of encapsulation, where a class does just one thing (and does it consistently and accurately) is one of the reasons object oriented programming has become so popular.

A class is just a definition, or blueprint, or template of what a car is. We have to create an instance of the class to use it. Consider: you can't drive a blueprint of a car, you need an actual instance of a car to be able to drive it.

A programmer who uses the class can simply declare instances of the Date class and then use the methods of the class. without having to write, or even look at the code for the class. This lets the programmer using the class focus on other tasks. Consider: You get in your car, put the key in the ignition and turn the key. You can think about where you need to go, you don't have to think about what actually happens when you turn the key in the ignition.

With object oriented programming, these methods are always from the point of the view of the object. We ask an instance of the date class what day of the week it is, or what date is 7 days later than it.

Inheritance is a way to describe a base class and then expand that base class into a more specialized class. For example if you have defined a Car class, you don't have to start over to define a convertible. You say that a Convertible is a Car, but it has a top which can go up and down. We would say that the Car is the base class and Convertible is the derived class.

Polymorphism is the concept that different classes can have methods with the same name that do similar things. For instance a method to find the area of a shape would be written differently for a circle, square, rectangle or triangle, but all of the methods would have the same name: area, not circle area, square area, etc. The +  symbol can be used for addition for many different data types, even a Date: today+7 is one week from today.

NEXT: Object Oriented Programming Terminology (Adobe)