C++ Programming Tutorials - Object Orientated Programming (OOD)

BASIC CONCEPTS OF OBJECT ORIENTATED PROGRAMMING

It is necessary to understand some of the concepts used extensively in object-oriented programming. This includes:

  • Objects
  • Classes
  • Data abstraction and encapsulation
  • Inheritance
  • Polymorphism

Objects

Objects are the basic run-time entities in a object-oriented system. They may represent a person, a place, a bank account, a table or any item that the program has to handle. They may also represent user-defined data such as vectors, time and lists.

When a program is executed, the objects interact by sending messages to one another. For example, if “customer” and “account” are two object in a program, then the customer object may send a message to the account object requesting for the bank balance. Each object contains data, and code to manipulate the data.

Object can interact without having to know details of each other’s data or code. It is sufficient to know the type of message accepted and the type of response returned by the objects.

C++ Classes

We just mention that an object contains data and code to manipulate that data. The entire set of data and code of an object can be made a user-defined data types with the help of a class. In fact, objects are variables of the type class.

Once a class has been defined, we can create any number of objects belonging to that class. Each object is associated with the data of type class with which they are created. A class is thus a collection of objects of similar type. For example, mango, apple and orange are member of the fruit.

Classes are user-defined data types and behave like the built-in types of a programming language. The syntax used to create an object is no different than the syntax used to create an integer object in C. If fruit has been defined as a class, then the statement.
Fruit mango;

Will create an object mango belonging to the class fruit.

Learn C and C++ Tutorials C++ Tutorial: Object Orientated Programming Tutorial.