Topic : Introduction to Object Oriented Programming: |OOP|

Introduction to OOP:

The Object Oriented Programming or OOP is a Programming Model where programs are Organized around objects and data rather than action and Logic: OOP Allows decomposition of a Problem into a Number of Entities called Objects and then builds data and functions around these Objects:



  • OOP Concepts:

    » The software is divided into a number of small units called objects. The data and Methods are built around these objects.
    » The data of the objects can be accessed only by the Methods associated with that object.
    » The Methods of one object can access the Methods of another object.



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:


  • In OOP:

    » 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, there by reducing the time it takes to create new objects.
    » Information hiding is more complete that in procedural programs.





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 programmatically 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 went Bend to let us walk. Our hand's 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 best 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 I just open my laptop and start work, while my friend starting work on files, another person took the marker and start writing something on boards. as our Boss's Order, or Message was Same for all "Let's back to work" but everybody do different action. that's the concept of Polymorphism.



Why OOP?

OOP is all about architecting Our software. Let’s compare software to a house. Would you want a bunch of builders to just start building your house without predefined rules and agreements? I bet you wouldn’t! Your house would be a mess. Still, that’s what often happens in software and, as expected, a lot of software turns out a mess! Returning to our house metaphor, let’s say your lamps were built right into the ceiling. Whenever a lamp broke you’d need a new ceiling! Luckily, that’s not the case. Yet in software, when a small detail needs to change, we often find ourselves rewriting huge pieces of code. And in many cases functionality that had nothing to do with the change breaks anyway. By abstracting away certain functionality we can just worry about the detail and we’re sure other parts of the system won’t break. On top of that, we can reuse code so that if functionality needs to change we’re sure it’s changed everywhere where we use it. How that’s done will become clear throughout the book.



In Term of Programming, 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.


















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