Object Oriented Programming Concepts in C#
· Object Oriented Programming (OOP) is a programming model where programs are organized around objects and data rather than action and logic.
· OOP allows decomposing a problem into many entities called objects and then building data and functions around these objects.
· A class is the core of any modern object-oriented programming language such as C#.
· In OOP languages, creating a class for representing data is mandatory.
· 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; hence, it is only a logical representation of data.
· To create a class, you use the keyword "class"
For Example:
class Employee
{
}
Object
· The software is divided into several small units called objects.
· The data and functions are built around these objects.
· An object's data can be accessed only by the functions associated with that object.
· The functions of one object can access the functions of another object.
· "An object is a software bundle of related variables and methods."
· "An object is an instance of a class."
· Abstraction is "To represent the essential feature without representing the background details."
· Abstraction provides a generalized view of your classes or objects by providing relevant information.
Real-world Example of Abstraction
· Suppose you have an object Mobile Phone.
· Suppose you have three mobile phones as in the following:
Nokia 1400 (Features: Calling, SMS)
Nokia 2700 (Features: Calling, SMS, FM Radio, MP3, Camera)
BlackBerry (Features: Calling, SMS, FM Radio, MP3, Camera, Video Recording, Reading E-mails)
· Abstract information (necessary and common information) for the "Mobile Phone" object is that it calls any number and can send an SMS.
· Encapsulation means hiding the internal details of an object, in other words, how an object does something.
· Encapsulation prevents clients from seeing its inside view, where the behavior of the abstraction is implemented.
Real-world Example of Encapsulation
· Let's use as an example Mobile Phones and Mobile Phone Manufacturers.
· Suppose you are a Mobile Phone Manufacturer and have designed and developed a Mobile Phone design (a class). Now by using machinery, you are manufacturing Mobile Phones (objects) for selling; when you sell your Mobile Phone, the user only learns how to use the Mobile Phone but not how the Mobile Phone works.
· This means that you are creating the class with functions and by with objects (capsules), of which you are making available the functionality of your class by that object and without interference in the original class.
Real-world Example of Polymorphism
A teacher behaves with his students.
A teacher behaves with their seniors.
Here the teacher is an object, but the attitude is different in different situations.
Take the first step towards data-led growth by partnering with MSA Infotech. Whether you seek tailored solutions or expert consultation, we are here to help you harness the power of data for your business. Contact us today and let’s embark on this transformative data adventure together. Get a free consultation today!
We utilize data to transform ourselves, our clients, and the world.
Partnership with leading data platforms and certified talents