Topic :Introduction To Object Oriented Programming ( OOP ) in C++ Programming Language:

Introduction to OOP:

OOP means Object Oriented Programming and is used in different languages and C++ is one of them. what really distinguish C++ from C is that C++ supports Object Oriented Programming. It is one of the most powerful techniques and influential development ever used in computer programming. Nowadays it has gained a Widespread use. Like C++ many languages support OOP like Java, PHP, VB.NET, etc.



Object-Oriented Programming , Infobrother:

OOP took the best ideas of structured programming and combined them with several New concepts. The result was a different and better way of organizing a program. in the most general sense, a program can be organized in one of two ways: around its code (what is happening) or around its data ( who is being affected ). using only structured programming techniques, programs are typically organized around code. this approach can be thought of as "code acting on data: ".

OOP use all features of procedural programs we just read about: they contain variables that are operated on by instructions written in sequence, selection, and loop statements. However, OOP requires a different way of thinking and adds several new concepts to programming, such as.


  • » We Analyze the objects with which we are working. both the attributes of those objects and the tasks that Need to be performed with on those Objects.
    » We pass Messages to Objects, requesting the objects to take action.
    » The same Message works differently (and Appropriately ) when applied to the various objects.
    » A Method can work appropriately with different types of data it receives, without the need for separate Method names.
    » Objects can Assume or Inherit traits of Previously created objects, thereby reducing the time it takes to create new objects.
    » Information hiding is more complete that in procedural programs



The Object Oriented Programming is divided into following major Concepts

Let's us try to Understand a little about all these, through a simple example. Human beings are living forms, broadly categorized into two types, Male and Female. Every Human being (Male or Female) has two legs, two hands, two eyes, one nose, one heart etc. there are body parts that are common for Male and Female, but there are some specific body parts, present in a Male which is Not Present in Female, and some body parts present in Female but not in Males. All Human Beings walk, eat, see, talk, hear etc. Now again, both Male and Female having same these function, but there are some specifics to both, which is not valid for the other. For Example, A Female can give birth, while a Male Can't, so this is only for the Female.

Human Anatomy is interesting, isn't it? But let's see how all this related to C++ and OOP. Here we will try to explain all the OOP concepts through this Example and Incoming Chapters, we will discuss pro-grammatically these all topics:



Classes:

Here We can take Human Being as a Class. A Class is a Blueprint for any functional entity which defines its properties and its functions. Like Human Being, having body parts, and performing various actions.



Data Abstraction:

Abstraction Means, showcasing only the required things to the outside world while hiding the details. Continuing our example, Human Being's can talk, walk, hear etc. But the details are hidden from the outside world. We can take our skin as the Abstraction factor in our case, hiding the inside Mechanism. Nobody can see our bones, Muscle Movement when we Walking. The whole world can see only our legs Movement, not inside Mechanism.



Encapsulation:

When We Walk, our Legs gone Bend to let us walk. Our hands gone bend to hold things. This binding of the Properties to function is called Encapsulation.



Information Hiding:

People can see what we doing, what we eating, or watching. but they don't know, what's going in our mind. what we are thinking. they don't know what we have in our bag or in a pocket. they can see our shirt, but can't see our vest behind the shirt. that is Information Hiding.



Inheritance:

My Father has Curly Black hair, and mine Too. It's Mean I Inherit the hair_Property from my Father. Human Inherit Properties like Looks, Hair, Eyes, sound mostly from their parents. and Animals or Birds from their Parents using the concept of Inheritance.



Polymorphism:

Every Morning, we have a Meeting with our Boss. After Meeting, Our Boss used to say "Let's back to work", so Me just open my laptop and start work, while my friend starting work on files, another person took marker and start writing something on boards. as our Boss's Order, or Message was Same for all "Let's back to work" but every body do different action. that's the concept of Polymorphism.



Uses Of OOP in Programming:

Classic Procedural Programming languages before C++ ( such as C ) often focused on the Question "What should the Program do Next ?. The way we structure a Program in these language is:


  • » Split it up into a set of tasks and sub tasks.
    » Make functions for the tasks.
    » Instruct the computer to perform them in sequence.



With large amounts of data or large numbers of tasks, this makes for complex and unmaintainable programs.

Consider the task of Modeling the Operation of Laptop. such a program would have lots of separate variables storing information on various Laptop parts, and there'd be no way to group together all the code that relates to, say, the keyboard's button. It's hard to keep all these variables and the connections between all the functions in mind.

To manage this complexity, it's Nicer to package up self-sufficient, modular pieces of code. People think of the world in term of interacting objects. We'd talk about interactions between the keyboard, screen, CPU, etc. OOP allows Programmers to pack away details into neat, self-contained boxes (Objects) so that they can think of the objects more abstractly and focus on the interactions between them, in this way the OOP definitions will be:


  • » Encapsulation: Grouping related data and functions together as objects and defining an interface to those objects.
    » Inheritance: Allowing code to be reused between related types.
    » Polymorphism: Allowing a value to be one of several types, and determining at runtime which functions to call on it based on its type.
    » Abstraction: Providing only Essential Information to the outside world and hiding their background details.
    » Information Hiding: Will Protect our data to Modify form outside of Class. so our data will safe from outsider.



Procedural Programs consist of a series of Steps or Procedures that take place one after the other. The Programmer determines the exact conditions under which a Procedure takes place, how often it takes place when the Program stops.







I Tried my Best to Provide you complete Information regarding this topic in very easy and conceptual way. but still if you have any Problem to understand this topic, or do you have any Questions, Feel Free to Ask Question. i'll do my best to Provide you what you need.

Sardar Omar.
InfoBrother





WRITE FOR INFOBROTHER

Advertising






Advertisement