Object Oriented Programming (Oops) | Concept in C#

Object Oriented Programming (OOP) is a modular approach and software designing pattern in which you can build an application. The data remain confined to be used within stipulated program area. In fact, under this system, complete program is decomposed into a number of entities called object. Each object possesses a set of data and functions to be operated on them. The data values belonging to an object can’t be accessed into another object. However, the objects can communicate among them through the functions. Object-oriented programming aka OOP is a widely used concept in the programming world and almost all major programming languages follow the object-oriented programming principles. In essence, OOP is a programming approach that is closely related to the ideas of classes and objects. This article will offer a thorough explanation of the fundamental ideas of object-oriented programming.

Object-oriented programming is dominating the world of programming because of its significant features:

  • OOP offers the inheritance idea, which improves the code’s reusability.
  • OOP makes use of polymorphism to give code flexibility.
  • The “don’t repeat yourself” (DRY) idea is supported by OOP, which makes code debugging very simple.
  • Only a few features of OOP are listed here; however, there are many more features of OOP that make it dominant over procedural programming

 Object Oriented Programming also promotes reusability feature to develop productive logic. Reusability means, if a code for a specific operation  is already created then it can be reused in another  code for same operation.

Some examples of object oriented programming languages are C#, C++, simula-67,Eiffel, small talk, Visual Basic, etc.

Object Oriented Programming (Oops) | Concept in C#

Features of Object Oriented Programming (OOP)

  • It puts more emphasis on the data items than on the functions.
  • By breaking out the program or problem into several objects, it simplifies both.
  • The objects share information through functions.
  • Data remain secured from outer interference.

Object and Class are the two basic elements of object oriented programming.

public class ParentClass {
    public ParentClass() {
        Console.WriteLine("Parent Constructor.");
    }
    public void print() {
        Console.WriteLine("I'm a Parent Class.");
    }
}
public class ChildClass: ParentClass {
    public ChildClass() {
        Console.WriteLine("Child Constructor.");
    }
    public static void Main() {
        ChildClass child = new ChildClass();
        child.print();
    }
}

 

Basic Concept of Object Oriented Programming

In this segment, let us review the basic concept of Object Oriented Programming in C#.

They are as follows.

  • Inheritance
  • Encapsulation
  • Abstraction
  • Polymorphism
  • Class
  • Object

Object Oriented Programming (Oops) | Concept in C#

Objects

We have already discussed that the object programming allows us to disintegrate a complete program into a number of entities. These entities are called objects. Hence, an object is an unique entity that contains characteristics and behaviours (termed as data and functions for software objects). The characteristics are the properties  or attributes whereas, behaviours are the actions to be carried on them. The lifetime  starts after the initialization od an object. When an object dies, its location (storage), which the object occupied is released and then the computer is shut down or the storage is taken up (used) by another object. Releasing a storage means,  the storage occupied by the object is , invalid. The lifetime of an object ends, when its storage is disposed.

Some time is needed to create an object. Some time is needed to destroy an object.In  an object, two things are involved: the location which is the storage, and the value stored in the object. The meaning of lifetime and storage duration are similar; but the duration is seen more from the point of view of the location than from the point of view of the value. The storage duration is the time from when a location is allocated to an object to the time when the location is deallocated from the object.

Let uas discuss some real world objects:

Object Oriented Programming (Oops) | Concept in C#

A television can be considered as an object that posses the following characteristics and behaviours:

Characteristics (Attributes) Behaviour
1. It is rectangular in shape  It is used to view news.
2. It has a flat screen  It is also used to watch games
3. It contains number of channel  It is used to view different entertainment   channels.

 

Class

Class is defined as a blue print, a template or prototype through which similar types of objects are created. The objects of class possess different characteristics (attributes) and common behaviours described within the class. The word “partial” in the phrase implies that it has to do with dividing up class implementation. The partial classes function similarly to the regular classes, but their definitions can be broken up into sections and placed in various files when using Visual Studio or within the same code (in the Ubuntu editor). Use of incomplete classes has no impact on how code is executed. However, it comes in really handy while working on a sizable programming project. As a result, we have chosen to demonstrate how partial classes can be used in C# in this post. Let’s begin by adding some C# examples that demonstrate how to use partial classes in our programmes. For this, a C# file is required so that we may develop and run our scripts.Let us consider a real world class ‘Bulb’ to understand is associativity with the object:     Bulb   

Object Oriented Programming (Oops) | Concept in C#

Here, you can see that the class ‘Bulb’ is defined with some characteristics and behaviours, that becomes a blue print for the object ‘Cfl-Bulb’ and ‘Led-Bulb’. Hence, these objects will possess different characteristics and common behaviours within the class ‘Bulb’.    

Object-oriented programming is all about the concepts of objects and classes. The classes are referred as templates for the objects while the objects are instances of a class so, the objects can inherit all the characteristics, variables, and functions of the class. This page offers explanations about what OOP is and why it should be used. Additionally, it teaches the ideas behind objects, classes, methods, and some other core OOP ideas.

Oops in C# Documentation link :

https://learn.microsoft.com/en-us/dotnet/csharp/fundamentals/tutorials/oop

https://learn.microsoft.com/en-us/dotnet/csharp/

Other C# Post :

History of C# and Its Versions

Features of C# programming

Introduction of C# Programming Language

I am a skilled software developer with 3 years of experience in .NET programming and Power BI development. I create tailored web applications and insightful Power BI visualizations that drive business success. With a passion for emerging technologies, I deliver innovative solutions that exceed client expectations.

Leave a Comment