Вы находитесь на странице: 1из 7

Basic Understanding of OOPS

By: Abel Livingstone M. Appaji

Basic Understanding of OOPS

Contents
INTRODUCTION: ..............................................................................................................................................3 IMPORTANT TERMS........................................................................................................................................4 ATTRIBUTES.......................................................................................................................................................5 REFERENCES :....................................................................................................................................................7

Basic Understanding of OOPS

Introduction:
The purpose of this document is to give the basic understanding about the OOPS (Object Oriented Programming) Concept with simple definition and more generic examples. Object oriented programming is a general term in todays programming world and every programmer should be aware of this term. This is not just a term but also a programming model. This model tries to resolve the problem, by providing the software solution as a real life model. Object-oriented programming can trace its roots to the 1960s. As hardware and software became increasingly complex, researchers studied ways in which software quality could be maintained. Object-oriented programming was deployed in part as an attempt to address this problem by strongly emphasizing discrete units of programming logic and re-usability in software. Object Oriented Programming, also known as OOP, is a computer science term which is used to describe a computer application that is composed of multiple objects which are connected to each other. Traditionally, most computer programming languages were simply a group of functions or instructions. With OOP, every object can handle data, get messages, and transfer messages to other objects. The objects will all act as independent units in their own right, and they will be responsible for carrying out a certain process. Because the objects are not dependent on each other, OOP is seen as being more flexible than older methods of programming. It has become quite popular, and it is now used in a number of advanced software engineering projects. Many programmers feel that object oriented programming is easier for beginners to learn than previous programming methods. Because it is easier to learn, it can also be analyzed and maintained without a large amount of difficulty. However, there are some people who feel that OOP is more complicated than older programming methods. To understand object oriented programming, there are a few concepts you will need to become familiar with.

Basic Understanding of OOPS

Important Terms
Following are the basic terms related to the Object Oriented Programming. Class: Class is the formal definition that provides the basis for the all objects. Every object begins life as a class. The class code defines all the behaviors and attributes of the class. The class is collection of code that forms a template for the creation of objects. Object: An Object is the implementation of a class. The class is a collection of code. This code acts as a template for creating an object. Instance: One can have an instance of a class or a particular object. The instance is the actual object created at runtime. Interface: An interface is the publicly exposed method, property or function that can be used to manipulate an object. An interface actually provides a means by which the internal code of the object can be executed without exposing all of the implementation detail to the consumer of the object. Abstraction: Abstraction is the ability to provide a virtual representation of a physical object or process. Example: The example is a bank account. People own savings accounts, checking accounts, credit accounts, investment accounts, but not generic bank accounts. In this case, a bank account can be an abstract class and all the other specialized bank accounts inherit from bank account.

Basic Understanding of OOPS

Attributes
The following are the 3 attributes of OOPS. Encapsulation Inheritance Polymorphism The above attributes are detailed below with generic examples. Encapsulation: Encapsulation is the ability of a class to hide its inner working from the application that is implementing it. It allows a developer to define an object as a black box, meaning that the interface that the object exposed are well defined public, and the actual implementation details of the objects are hidden. Example: For example Customer, Waiter and Kitchen are three shielded objects in the 'cup of coffee' example. Customer and kitchen do not know each other. The waiter is the intermediary between those two. Objects can't see each other in an Object Oriented world. Inheritance: Inheritance is the ability to pass changes made to attributes and behaviors of the parent class to the subclasses whose foundation they provide. Example: For example, a Red Delicious apple is part of the classification apple, which in turn is part of the fruit class, which is under the larger class food. That is, the food class possesses certain qualities (edible, nutritious etc) which also, logically, apply to its subclass, fruit. In addition to these qualities, the fruit class has specific characteristic (juicy, sweet etc) that distinguish it from other food. The apple class defines those qualities specific to apple (grown on trees, not tropical etc). A Red Delicious apple would, in turn, inherit all the qualities of all preceding classes and would define only those qualities that make it unique. The hierarchy is, Food Fruit Apple Red Delicious apple

Basic Understanding of OOPS

Polymorphism: Polymorphism is the ability to implement interfaces generically in the applications. Polymorphism allows objects to be represented in multiple forms. Polymorphism is in two forms as method overloading and method overriding. (a) Method overloading This allows two or more methods within the same class can share the same name, as long as their parameters are different. Example: The same class has two methods with same name as Area (). One is to calculate the area of Triangle which requires the length of the three sides as input parameters, and another is to calculate the area of rectangle which requires the length of the four sides as input parameters. Polymorphism allows the area calculating logic in generic way according to the number of values input by calling the method Area (). If the number of input parameters are three then it is for the area of triangle and if the number of input parameters are four then the it is for the are calculation of the rectangle. (b) Method overriding This allows a general call to specify methods that will be common to all of its derivatives, which allowing derived classes to define the specific implementation of the same or all of those methods. Overridden methods are those that implement the one interface, multiple methods aspect of polymorphism. Part of the key to successfully applying polymorphism is understanding that the base classes and derived classes form a hierarchy that moves from lesser to greater specialization. Used correctly, the base class provides all elements that a derived class can use directly. It also defines those methods that the derived class must implement on its own. This allows the derived class the flexibility to define its own methods, yet still enforces a consistence interface. Thus, combining inheritance with overridden methods, a base class can define the general form of the methods that will be used by all of its derived classes. Example: For example, each class derived from class TwoDShape defines a method called area (). This suggests that it might be better to make area () a virtual method of the TwoDShape class, allowing each derived class to override it, defining how the area is calculated for the type (triangle, triangle, etc.) of shape that the class encapsulates.

Basic Understanding of OOPS

References :
#1. http://msdn2.microsoft.com/ #2. http://www.c-sharpcorner.com #3. http://en.wikipedia.org/ #4. VB6 Distributed Applications, BPB Publication. #5. The Complete Reference C#, Tata McGraw Hill.

Basic Understanding of OOPS