Search
Winners

Win Prizes

Social Presence
Twitter Twitter LinkedIn YouTube Google

Like us on Facebook
Advertisements
Top Articles Author
Sat, 23-Aug-2014 Authors
Goud.Kv
250
All Time Authors
Sourav.Kayal
39750
Sheonarayan
37300
Niladri.Biswas
33350

Latest members | More ...


(Statistics delayed by 5 minutes)
Ads
 Article

OOPS for Beginners - Features

SheoNarayan
Posted by under OOPS category on for Beginner level | Views : 107230 red flag
If you found plagiarised (copied) or inappropriate content,
please let us know the original source along with your correct email id (to communicate) for further action.
Rating: 4.5 out of 5
2 vote(s)
This article introduces readers to OOPS (object-oriented programming system) and focus on its characteristics in little details.

Introduction

According to Wikipedia,  Object-oriented programming (OOP) is a programming paradigm that uses "objects" and their interactions to design applications and computer programs. Programming techniques may include features such as abstraction, encapsulation, inheritance, and polymorphism. In this article I will try to descibe each one of them.

In order to understand this article, you should know basics concepts of an object, class.  Lets see what are they.

Object

Basically an object is anything that is identifiable as an single material item. You can see around and find many objects like Camera, Monitor, Laptop etc. In OOP perspective, an object is nothing but an instance of a class that contains real values instead of variables

Class

A class is a template definition of the methods and variables for a particular kind of object. In other words, class is the blue print from which an individual objects are created.

Now lets see basic features of Object Oriented Programming one by one.

Abstraction

Abstraction is a process of identifying the relevant qualities and behvaiors an object should possess. Lets take an example to understand abstraction. A Laptop consists of many things such as processor, motherboard, RAM, keyboard, LCD screen, wireless antena, web camera, usb ports, battery, speakers etc. To use it, you don't need to know how internally LCD screens, keyboard, web camera, battery, wireless antena, speakers works.  You just need to know how to operate the laptop by switching it on. The intrinsic details are invisitble. Think about if you would have to call to the engineer  who knows all internal details of the laptop before operating it. This would have highly expensive as well as not easy to use everywhere by everyone. So here the Laptop is an object that is designed to hide its complexity.

Think If you need to write a piece of software to track the students details of a school, you may probably need to create Students objects. People comes in all different backgrounds, educational qualifications, locations, hobbies, ages and have multiple religion, language but in terms of application, an student is just a name, age, class and roll number, while the other qualities are not relevant to the application. Determining what other qualities (background, qualifications, location, hobbiels etc) are in terms of this application is abstraction.

In object-oriented software, complexity is managed by using abstraction. Abstraction is a process that involves identifying the critical behavior of an object and eliminating irrelevant and complex detilals. A well thought-out abstraction is usually simple, and easy to use in the perspective of the user, the person who is using your object.


Encapsulation

Encapsulation is a method for protecting data from unwanted access or alteration by packaging it in an object where it is only accessible through the object's interface. Encapsulation are often referred to as information hiding. But both are different. Infact information hiding is actually the result of Encapsulation. Encapsulation makes it possible to separate an object's implementation from its orgiinal behavior - to restrict access of its internal data. This restriction facilitate certains detiails of an object;s behavior to be hidden. This allows to protect an object's interal state from corruption by its user.

It is the mechanism by which Abstraction is implemented. In other words you can say that it is the result of the Encapsulation. For example,  the Laptop is an object that encapsulates many technologies/hardwares that might not be understood clearly by most people who use it.

Inheritance 

Inheritance is the ability to define a new class or object that inherits the behaviour and its functionality of an existing class. The new class or object is called a child or subclass or derived class while the original class is called parent or base class. For example, in a software company Software Engineers, Sr. Software Engineers, Module Lead, Technical Lead, Project Lead, Project Manager, Program Manager, Directors all are the employees of the company but their work, perks, roles, responsibilities differs. So in OOP, the Employee base class would provide the common behaviours of all types/level of employee and also some behaviours properties that all employee must have for that company. The particular sub class or child class of the employee would implement behaviours specific to that level of the employee. So by above example you can notice that the main concept behind inheritance are extensibility and code reuse (in this case you are extending the Employee class and using its code into sub class or derived class).

Polymorphism

As name suggests, Polymorphism means an ability to assume different forms at different places. In OOP, it is a language's ability to handle objects differently based on their runtime type and use. Polymorphism is briefly described as "one interface, many implementations".Ppolymorphism is a characteristic of being able to assign a different meaning or usage to something in different contexts - specifically, to allow an entity such as a variable, a function, or an object to have more than one form.

There are two types of polymorphism.

  1. Compile time polymorphism - It is achieved by overloading functions and operators
  2. Run time polymorphism - It is achieved by overriding virtual functions

Lets say you have a class that have many Load methods having different parameters, this is called Compile time polymorphism. Lets take another example where you have a virtual method in the base class called Load with one parameter and you have redefined its functioanlity in your sub class by overriding base class Load method,  this is called Run time polymorphism.

 

In this small article, I have tried to explain basic features of OOPS in little details. OOPS in itself is a very vast subject and explaining each and every features is near to impossible for me. If you have any comments of suggestions, please respond to this article.

Take care and thank you very much for reading.

Page copy protected against web site content infringement by Copyscape
About the Author

SheoNarayan

Full Name: Sheo Narayan
Member Level: HonoraryPlatinum
Member Status: Microsoft_MVP,Administrator
Member Since: 7/8/2008 6:32:14 PM
Country: India
Regards, Sheo Narayan http://www.dotnetfunda.com
http://www.snarayan.com

Microsoft MVP, Author, Writer, Mentor & architecting applications since year 2001. Connect me on http://www.facebook.com/sheo.narayan | https://twitter.com/sheonarayan | http://www.linkedin.com/in/sheonarayan
Login to vote for this post.
Found interesting? Add this to:


Comments or Responses

Posted by: Slkubsad on: 10/14/2008

The article looks good.
It would be better if each feature of OOPs has sample code with it. Example would definetly give clear picture of the OOPS concepts.

Thanks,
Suresh

Posted by: SheoNarayan on: 10/14/2008

Thanks Slkubsad,

I will try to put some code for every features. Thanks

Posted by: Simple_hi on: 4/15/2010

Really very helpful for beginners.....

Posted by: Karthikanbarasan on: 1/7/2011 | Points: 25

Hi,

Very good article for begineers...

Thanks
Karthik

Posted by: Karthikanbarasan on: 1/7/2011 | Points: 25

It will be good if u can add some real time examples for each feature of the OOPS... In most of the interviews they are asking for the real time example so that its useful for them as well...

Thanks
Karthik

Posted by: Chiragkanzariya on: 11/22/2012 | Points: 25

Nice Article.

You can also check Basic concept of OOP here http://chiragkanzariya.blogspot.in/2012/11/oops-concept-with-real-world-example.html

Login to post response

Comment using Facebook(Author doesn't get notification)