Let’s start with “Object”. The Basic Concepts Of Object-Oriented approach first thing that we should do in the Object-Oriented approach is to start thinking in terms of Objects. The problem to be solved is divided into objects. Start analyzing the problem in terms of objects and the nature of communication between them. Program object should be chosen such that they match closely with real-world objects. Let’s start creating objects using real-life things, for example, the dog. You can create an object representing a dog, It would have data like How hungry, is it? How happy is it? Where is it? Now think what are the different functions you can perform on a dog, like eat, bark, run and dig.
In Basic Concepts Of Object-Oriented approach the following can be treated as objects in different programming problems:
- Employees in a payroll system
- Customers and accounts in a banking system
- Salesman, products, customers in a sales tracking system
- Data structures like linked lists, stacks, etc.
- Hardware devices like magnetic tape drive, keyboard, printer, etc.
- GUI elements like windows, menus, events, etc. in any window-based application.
Each object contains data and the functions that operate on the data. Objects can interact without having to know details of each other’s data or functions. It is sufficient to know the type of message accepted and the type of response returned by the object. For example, in the banking system, customer object may send a message named as check balance to the account object to get the response, i.e. bank balance. An Object-Oriented system can be considered as a network of cooperating objects which interact by sending messages to each other. Let’s see how objects interact by sending messages to one another.
Objects of a similar type can be grouped together to form a class. Can you tell to which class dog belongs? Yes, of course, it belongs to the animal class. Now, let us concentrate on the creation of objects. This can be easily answered if we look at the way of creating any variable in common programming languages. Almost all computer languages have built-in data types, for example, integer, character, real, boolean, etc. One can declare as many variables of any built-in type as needed in any problem solution. In a similar way, one can define many objects of the same class. You can take a class as a type created by a programmer.