Introduction to Object Oriented
Programming
Object Oriented Programming Feature
Object Oriented Programming (OOP) is one of the most popular programming languages. This article is an introduction to Object Oriented Programming (OOP) and how to implement OOP in C# including abstraction, encapsulation, inheritance and polymorphism.
OOP Features
Object Oriented Programming (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.
The software is divided into a number of small units called objects. The data and functions are built around these objects.
The data of the objects can be accessed only by the functions associated with that object.
The functions of one object can access the functions of another object.
Principle of OOP
Encapsulation
Refers to the creation of self-contained modules (classes) that bind processing functions to its data members. The data within each class is kept private. Each class defines rules for what is publicly visible and what modifications are allowed.
Inheritance
Classes may be created in hierarchies, and inheritance lets the structure and methods in one class pass down the class hierarchy. By inheriting code, complex behaviors emerge through the reuse of code in a parent class. If a step is added at the bottom of a hierarchy, only the processing and data associated with that unique step must be added. Everything else above that step may be inherited. Reuse is considered a major advantage of object orientation.
Polymorphism
Object oriented programming lets programmers create procedures for objects whose exact type is not known until runtime. For example, a screen cursor may change its shape from an arrow to a line depending on the program mode. The routine to move the cursor on screen in response to mouse movement can be written for "cursor", and polymorphism lets the right version for the given shape be called.
Abstraction
An abstraction denotes the essential characteristics of an object that distinguish it from all other kinds of objects and thus provide crisply defined conceptual boundaries, relative to the perspective of the viewer. [Booch]
Abstraction denotes a model, a view, or some other focused representation for an actual item. It's the development of a software object to represent an object we can find in the real world. Encapsulation hides the details of that implementation.