Object Oriented Basics

The most basic thing to start programming is to learn OOPs. After having clear concepts of OOPs one can easily implement these concepts in any programming languages. Each programming language support OOPs in different manners, differing in syntax and structure.
Basically OOPs is a software develeopment paradigm that suggests developers to split a programg in building blocks called

Objects
. It suggests to think of real world in terms of simple Objects that have certain features like Identity(every object is different and can be differenciated from other), Behaviour(what object can do? or set of functions or actions an Object can do) and State(data stored in Object at given moment). Object is considered to be building block of OOPs as all things in OOPs revolve around consideration in form of Objects.





Class
is a template/blueprint for Object as it defines the attributes and methods that implement behaviour of set of similar Objects. A class is an abstract definition that is made concrete at run-time when objects based upon the class are instantiated and take on the class' behaviour.

In class definition we try to generalize methods and attributes for similar type of Objects and when we create Objects from that class, we try to Specialize each Object having some attributes and methods from the class alongwith some special ones that are specific to that particular Object. This might seem to be as Inheritance relationship alongwith Generalization and Specialization.

Example...
Consider the concept of a 'vehicle' class. The class developed by a programmer would include methods such as Steer(), Accelerate() and Brake(). The class would also include properties such as Colour, NumberOfDoors, TopSpeed and NumberOfWheels. The class is an abstract design that becomes real when objects such as Car, RacingCar, Tank and Tricycle are created, each with its own version of the class' methods and properties.




Encapsulation

Its basically Info hiding or Data hiding. In that manner its a technique to exclude irrelevant details from inherited members implying that irrelevant data is not accessible to outside world and just available for inside wrapped functions. Its a process of covering up of data and function into a single unit.It actually seperates the external aspects from the internal implementation details of the Object. Also defined as wrapping up of data and functions into a single unit.




Abstraction

Abstraction is actually representation of essential features without including background data or explanation. Its basically representation of complex things in simple manner.
Example... For considering a real world example, Colors are abstracted to be known as RGB, which is actually a representation of vast colors in a simple manner as all colors are composed of these basic R(ed)G(reen)B(lue) combinations




Polymorphism

The most wide area of OOPs is Polymorphism which leads to many other concepts of OOPs. Its representation or appearence of Objects/Functions in different forms.
Also refer to as a single Interface having many implementations. Its basically a characteristic to assign different meaning or usage to something in different contexts to allow variables, functions, Objects to have different forms.
a)Compile time Polymorphism(Function and Operator Overloading)
b)Run time Polymorphism(Done using Interfaces and Virtual functions)

Polymorphism helps programmer for re-usage of same type of functions and we dont have to re-define functions again and again. These similar functions differ in Signature(composed of Return type and number and data type parameters).
Virtual keyword is used in Base class functions and they can be overridden(action of editing/modifying members of Base class function) using Override keyword.
Example...
public void MuxInt(int a, int b)
{return a*b}
public void MuxInt(int a, int b, int c)
{return a*b*c}

Polymorphism leads to Overloading and Overriding and also leads to Inheritance.



Inheritance

One of the most important Concept of OOps is Inheritance. When we create Classes we try to Generalize the Fields/Attributes and methods. Actually we implement some Classes as Bases classes and try to just define respective Attribiutes/Fields and Methods/Functions and we try to write most of them and leave some without implementation(Intterfaces). We make them to be Generalized in future by any class. Any Derived class at any time can Inherit from the Base Classes and can add their own new methods and can update the older ones(by adding implementation).

Simple Example is of a Car Class, in Base Class we define attributes like Color, Type of Engine, Model, Year, Name, Speed and Methods/Functions like Movement, Braking etc..and later on when a new car comes, we just make a derived class and use the Base Class's define Attributes and Methods to differ the specific Car.

Comments

Popular Posts