Since the invention of the computer, many programming approaches have been tried. These included techniques such as modular programming, top-down programming, bottom-up programming and structured programming. The primary motivation in each case has been the concern to handle the increasing complexity of programs that are reliable and maintainable. These techniques became popular among programmers over the last two decades. With the advent of languages such as C, Structured programming became very popular and was the main technique of the 1980s. Structured programming was a powerful tool that enabled programmers to make moderately complex programs fairly easily. However, as the programs grew larger, even the structured approach failed to show the desired results in terms of bug-free, easy-to-maintain, and reusable programs.
An object is a representation of a real world concept which possesses both properties and functionalities (states & behavior). In real world any object (like human) inherits some properties and functionalities from its ancestors. So a programming language can be said as an Object Oriented Programming Language if it supports the concept of objects (abstract data types) and inheritance and polymorphism.
Definition of Object Oriented Programming
Object Oriented Programming is an approach to program organization and development that attempts to eliminate some of the pitfalls of conventional programming methods by in incorporating the best of structured programming features with several powerful new concepts like data encapsulation, inheritance and abstract data types. It is a new way of organizing and developing programs and has nothing to do with any particular language. However, not all languages are suitable to implement the OPP concepts easily.
Object Oriented Programming was developed because limitations were discovered in earlier approach to programming. To appreciate what OOP does, first all discuss what these limitations one and how they arose from traditional programming.
C++ and Object Oriented Programming
A well written program in C++ programming language will show the elements of both object oriented programming style and procedural programming. C++ programming language is designed for software development and to overcome the drawbacks of the procedural programming languages. C++ provides the programmers with all tools to implement Object Oriented Programming concepts in their programs. A programmer can
- Use public and private access specifies to restrict the access to the data, objects and functionality
- Can completely hide the sensitive from the unauthorized access
- Can use multiple inheritances
And many more features that a programmer can use to program. Due to this functionality of C++ Programming Language it is the one of the most used programming language in any Operating system platform.
A simple Object Oriented Program
Here is a simple object oriented “Hello World” program. The program will be explained in the next few pages.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include <stdio.h> // The HelloWorld class definition. class HelloWorld { public: HelloWorld() {} // Constructor. ~HelloWorld() {} // Destructor. void print() { printf("Hello World!\n"); } }; // Note that a semicolon is required here. // The main progam. int main() { HelloWorld a; // Create a HelloWorld object. a.print(); // Send a "print" message to the object. return 0; } |