Basics of object-oriented programming

Object-oriented programming (OOP below) is considered one of the most modern and sophisticated approaches in this area. Existed before him procedural and functional method involves writing code in a single file. With the development of software technology is getting longer and longer, and developers became more difficult to maintain and modify. OOP solves this problem by sharing a piece of code into separate entities called classes and objects.

Classes and objects - what is the difference?

The OOP made in programming never be certain: the class and the object. The class can be called a data type, or - to put it simply - a piece of code that has characteristics, called class fields and possible actions - class methods. Object - an entity that has certain properties, it belongs to a class.

Example

One of the most common and understandable example is the analogy with animals. In abstract animal has certain properties (color, appearance, weight, etc.) - the class used to describe it. Specific animals (elephant, tortoise) are already objects of this class.

The three main principles of the OOP

There are three main concepts, also called "three pillars of the PLO," without which the very concept of it is impossible - encapsulation, inheritance and polymorphism. Without an understanding of the work of these basic principles to move forward in the study of the OOP difficult. Let's briefly look at each of them.

  1. Encapsulation - a principle that allows the user to hide the implementation of some of the methods and values of the fields. In the C# programming language for this purpose, so-called access modifiers (public, private, etc.).
  2. Inheritance - a principle that allows you to create a class based on another. The first class is called the heir, and the second - parent. In a derived class implements all the methods and fields of the class parent.
  3. Polymorphism - a principle that allows objects with the same interface have different implementation. Polymorphism adds several new concepts: abstract / virtual method and override the method.
    • Abstract method - a method to be implemented in the derived class, and must not - run a parent.
    • Virtual method - a method that can be overridden in a derived class, and can have (or may have), the implementation of in-class parent.

Overriding methods — change implementation of a virtual method.


20 November 2016

You may be interested in

16 September 2023
Everything you need to know about 10 Gbps servers
In today's digital world, speed is everything. This is why bandwidth is such an important factor whe ...