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.
OOP has the following important features.
Class
A class is the core of any modern Object Oriented Programming language such as C#.
In OOP languages it is mandatory to create a class for representing data.
A class is a blueprint of an object that contains variables for storing data and functions to perform operations on the data.
A class will not occupy any memory space and hence it is only a logical representation of data.
To create a class, you simply use the keyword "class" followed by the class name:
class Employee
{
}
Object
Objects are the basic run-time entities of an object oriented system. They may represent a person, a place or any item that the program must handle.
"An object is a software bundle of related variable and methods."
"An object is an instance of a class"
oops-in-csharp.jpg
A class will not occupy any memory space. Hence to work with the data represented by the class you must create a variable for the class, that is called an object.
When an object is created using the new operator, memory is allocated for the class in the heap, the object is called an instance and its starting address will be stored in the object in stack memory.
When an object is created without the new operator, memory will not be allocated in the heap, in other words an instance will not be created and the object in the stack contains the value null.
When an object contains null, then it is not possible to access the members of the class using that object.
class Employee
{
}
Syntax to create an object of class Employee:
Employee objEmp = new Employee();
All the programming languages supporting Object Oriented Programming will be supporting these three main concepts,
Encapsulation
Inheritance
Polymorphism
Abstraction
Abstraction is "To represent the essential feature without representing the background details."
Abstraction lets you focus on what the object does instead of how it does it.
Abstraction provides you a generalized view of your classes or objects by providing relevant information.
Abstraction is the process of hiding the working style of an object, and showing the information of an object in an understandable manner.
Real-world Example of Abstraction
Suppose you have an object Mobile Phone.
Suppose you have 3 mobile phones as in the following:
Nokia 1400 (Features: Calling, SMS)
Nokia 2700 (Features: Calling, SMS, FM Radio, MP3, Camera)
Black Berry (Features:Calling, SMS, FM Radio, MP3, Camera, Video Recording, Reading E-mails)
Abstract information (necessary and common information) for the object "Mobile Phone" is that it makes a call to any number and can send SMS.
So that, for a mobile phone object you will have the abstract class as in the following,
abstract class MobilePhone {
public void Calling();
public void SendSMS();
}
public class Nokia1400: MobilePhone {}
public class Nokia2700: MobilePhone {
public void FMRadio();
public void MP3();
public void Camera();
}
public class BlackBerry: MobilePhone {
public void FMRadio();
public void MP3();
public void Camera();
public void Recording();
public void ReadAndSendEmails();
}
Abstraction means putting all the variables and methods in a class that are necessary.
For example: Abstract class and abstract method.
Abstraction is a common thing.
Example
If somebody in your college tells you to fill in an application form, you will provide your details, like name, address, date of birth, which semester, percentage you have etcetera.
If some doctor gives you an application to fill in the details, you will provide the details, like name, address, date of birth, blood group, height and weight.
See in the preceding example what is in common?
Age, name and address, so you can create a class that consists of the common data. That is called an abstract class.
That class is not complete and it can be inherited by other classes.
Encapsulation
Wrapping up a data member and a method together into a single unit (in other words class) is called Encapsulation.
На этой странице сайта вы можете посмотреть видео онлайн Introduction to Object Oriented Concepts C plus plus JAVA python длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь INFORMATION TECHNOLOGY 22 Июль 2019, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 15 раз и оно понравилось 3 зрителям. Приятного просмотра!