Object-Oriented Programming (OOPs) in C#
OOPs, stand for Object-Oriented Programming System. It is a technique, not technology. It means it doesn’t provide any syntaxes or APIs instead it provides suggestions to design and develop objects in programming languages.
Why Object-Oriented Programming?
If we want to represent the real world objects in a programming language for automating the business by achieving the security and reusability then we need the concept oops. OOPs provide some principles and by using those principles we can develop the real world objects in a programming language by achieving both security and reusability.
All living and non-living things are considered as objects. So the real-world objects such as Person, Animal, Bike, Computer, etc. can be developed in object-oriented programming languages by using the OOPs concept.
Why we need real-world objects in a program?
We need real-world objects in a program because the real-world objects are part of our business. As we are developing applications (software) for automating the business, we must have to create the business-related real-world objects in the project.
For example, to automate the Bank business we must create real-world objects like Customer, Manager, Clerk, Office Assistant, Marketing Executive, Computer, Printer, Chair, table, etc. So along with Bank object, we must also have to create all the above objects because without all the above objects we cannot run Bank business.
So technically we call the above objects are business objects.
What is OOPs?
OOPs (Object Oriented Programming System) is a concept (methodology) that provides a way of developing a program by creating partitioned memory area for both data and methods that can be used as a template for creating copies of such modules (objects) on demand.
Unlike procedural programming language, here in oops, programs are organized around objects and data rather than action and logic.
Points to Remember:
- Oops, principles are design patterns which suggest that how we should develop a program so that we can reuse it from other layers of the project effectively and with high scalability.
- Scalability means we have to develop the project in such a way that it should accept future changes without doing major changes in the project, that small change also should be accepted from external files like properties file, XML file etc. Scalability is achieved by developing classes by integrating them in the loosely coupled way.
- We should develop the project with scalability as there will be a growth in business, according to the growth in business we must add required changes to the project with minimal modifications.
- As a developer, we must remember that in the initial stage of business customer never makes a significant investment. As the business grows customer increase investment according to the growing new requirements are added to the projects. To add those new requirements we should not design the project entirely.
- So we must design the project by following OOPs principles strictly even though they are not needed at the initial stage but for accepting future changes
How many OOPs principles do we have?
OOPs, provide 4 principles. They are
Let’s understand the definitions of OOPs Principle in this article. From the next article onwards we will discuss all these principles in details using some real-time examples.
The process of binding the data and functions together into a single unit (i.e. class) is called encapsulation.
The process of creating a class by hiding its internal data members from outside the class and accessing it only through publicly exposed methods or properties is known as data encapsulation.
Data encapsulation is also called data hiding because by using this principle we can hide the internal data from outside the class.
The process by which the members of one class are transferred to another class is called as inheritance.
The class from which the members are transferred is called as Parent/base class and the class which inherits the members of the Parent class is called as Derived/ child class.
We can achieve code reusability through inheritance.
The word Polymorphism is derived from the Greek word, where Poly means many and morph means faces/ behaviors. So, the word polymorphism means the ability to take more than one form.
Same function/ operator will show different behaviors when passed with different types of values or with the different number of values.
There are two types of polymorphism
- Static polymorphism/compile-time polymorphism /early binding
- Dynamic polymorphism / Run time polymorphism / Late binding
Static polymorphism is achieved by using function overloading and operator overloading whereas dynamic polymorphism is achieved by using function overriding.
The process of representing the essential features without including the background details is called as data abstraction.
The process of defining a class by providing necessary details to call the object operations (i.e. methods) by hiding or removing its implementation details is called data abstraction.
Functions or methods are a good example of abstraction because we never know what they do internally, what we know only is how to consume them.
There are two types of abstractions available
- Data abstraction
- Functional abstraction
What types of programming languages comes under OOP system?
The programming languages which implements all the above four principles provided by OOPs are called object-oriented programming languages. Examples: Java, .net, c++, etc.
In this article, I try to explain the basics of Object-Oriented Programming Principle in C#. I hope this article will help you with your need. I would like to have your feedback. Please post your feedback, question, or comments about this article.