History
In 1960s, as hardware and software became increasingly complex, manageability often became a concern. Researchers studied ways to maintain software quality and developed object-oriented programming. Object-oriented programming (OOP) is a computer science term used to characterize a programming language. The term ‘object-oriented programming’ was coined by Xerox PARC to designate a computer application that describes the methodology of using objects as the foundation for computation. Currently Java, J2EE, C++, C#, Visual Basic.NET, ActionScript are some of the popular OOP programming languages. The first programming language to use objects was Simula 67.
Understanding OOP
To begin life with OOP, terms such as objects, class, methods, inheritance, polymorphism,encapsulation are some terms to be remembered.
- Objects: An object is the primary entity of OOP. Anything to be dealt with (like in real life) are objects. Say you are developing an applications for a school. The stdents, the teachers, the clarks can be treated as objects.
- Class: Class is a blueprint of an object which consists of the properties, behaviour and functions (called "methods" in OOP). Let's take the school application for example. Let there be a class called "school". A teacher Mr. XYZ is an object of class schools. We can call it as "Mr. XYZ is a member variable of class school".
- Method: Every useful objects have methods. Mr. XYZ, the teacher, and the member variable of class "school", takes classes in school, does his lunch at recess, attends meetings, and other works. In programming point of view, to make use of Mr. XYZ, we can create methods like TakeClass( ), HaveLunch( ), AttendMeeting( ) etc.
- Property: Do you have any specific property that distinguishes you besides being a human? Well, in OOP, properties are set to give a distinction to class.
So, let's see what OOP can do for you!
- Inheritance: To be precise, inheritance is a speciality of a class which maintains hierarchy, thus giving you the strength of code reusability, more productivity and efficiency.
Mr. XYZ is a teacher, a teacher is a human, a human is a living thing. So if we create three classes, Teacher( ), Human( ), LivingThing( ), we can say Teacher( ) class is derived from Human( ) class, the Human( ) class is again derived from LivingThing( ) class. For Teacher( ) class, Human( ) class is considered as "Base Class".The Teacher( ) class " inherits" all methods and properties and also its own methods and properties. Neat, isn't it?
There are two kinds of relationships in inheritance technique- "is-a" relationship and "has-a" relationship. - Polymorphism: Polymorphism is an useful feature in OOP. It allows re-using methods. Like Mr. XYZ, Mr.PQR, another teacher who also takes classes. For Polymorphism, we don't have to create another TakeClass( ) method for Mr. PQR. One is good enough! Neat again, isn't it? And oh yes, this kind of polymorphism is called "Method Overloading".
- Encapsulation: Say you are working with a class which is derived from a class called,say, "root". Now since any damage in root( ) class can affect the class you're working with, you might be interested to "encapsulate" the root( ) class, means hiding it from outer world to prevent accidental damage.

No comments:
Post a Comment