Object-Oriented Programming Concepts “In Simple English”

Yann Mulonda
6 min readJun 9, 2018

Intro to C#

In this article, we are going to explore c#, an OOP language, in order to showcase and understand OOP concepts.

What is C#?

C# is a simple, modern, general-purpose, object-oriented programming language developed by Microsoft within its .NET initiative led by Anders Hejlsberg. C# is a modern, general-purpose, object-oriented programming language developed by Microsoft and approved by the European Computer Manufacturers Association (ECMA) and International Standards Organization (ISO). C# is based on object-oriented programming concepts.

Want to read this story later? Save it in Journal.

The following reasons make C# a widely used professional language:

  • It is a modern, general-purpose programming language
  • It is object-oriented.
  • It is component-oriented.
  • It is easy to learn.
  • It is a structured language.
  • It produces efficient programs.
  • It can be compiled on a variety of computer platforms.
  • It is a part of .Net Framework.

What is The .Net Framework?

The .Net framework is a revolutionary platform that helps you to write the following types of applications:

  • Windows applications
  • Web applications
  • Web services

The .Net framework applications are multi-platform applications. The framework has been designed in such a way that it can be used in any of the following languages: C#, C++, Visual Basic, JScript, COBOL, etc. All these languages can access the framework as well as communicate with each other.

The .Net framework consists of an enormous library of codes used by client languages such as C#. Following are some of the components of the .Net framework:

  • Common Language Runtime (CLR)
  • The .Net Framework Class Library
  • Common Language Specification
  • Common Type System
  • Metadata and Assemblies
  • Windows Forms
  • ASP.Net and ASP.Net AJAX
  • ADO.Net
  • Windows Workflow Foundation (WF)
  • Windows Presentation Foundation
  • Windows Communication Foundation (WCF)
  • LINQ

A C# program consists of the following parts:

  • Namespace declaration
  • A class
  • Class methods
  • Class attributes
  • A Main method
  • Statements and Expressions
  • Comments

Here is a small program of C#:

Let us look at the various parts of the given program:

  • The first line of the program using System; — the using keyword is used to include the System namespace in the program. A program generally has multiple using statements.
  • The next line has the namespace declaration. A namespace is a collection of classes. The “HelloWorldApplication” namespace contains the class HelloWorld.
  • The next line has a class declaration, the class “HelloWorld” contains the data and method definitions that your program uses. Classes generally contain multiple methods. Methods define the behavior of the class. However, the HelloWorld class has only one method Main.
  • The next line defines the Main method, which is the entry point for all C# programs. The Main method states what the class does when executed.
  • The next line /*…*/ is ignored by the compiler and it is put to add comments in the program.
  • The Main method specifies its behavior with the statement Console.WriteLine(“Hello World”);

“WriteLine” is a method of the Console class defined in the System namespace. This statement causes the message “Hello, World!” to be displayed on the screen.

It is worth to note the following points:

  • C# is case-sensitive.
  • All statements and expressions must end with a semicolon (;).
  • The program execution starts at the Main method.

OOP Concepts

In the class-based object-oriented programming paradigm, “object” refers to a particular instance of a class where the object can be a combination of variables, functions, and data structures. A good understanding of OOPs concepts can help in decision-making when designing an application. How you should design an application and what language should be used.

Object-oriented programming is a programming style that is associated with concepts like class, object, Inheritance, Encapsulation, Abstraction, and Polymorphism.

1. Class

A class is a collection of methods and variables. It is a blueprint that defines the data and behavior of a type.

Let’s take Human Being as a class. A class is a blueprint for any functional entity which defines its properties and its functions. Like Human Beings, having body parts, and performing various actions.

We can define a class using the class keyword and the class body enclosed by a pair of curly braces, as shown in the following example:

public class humanBeing
{
// declare field properties, event, delegate, and method
}

2. Inheritance

Inheritance is a feature of object-oriented programming that allows code reusability when a class includes property of another class. Considering HumanBeing a class, that has properties like hands, legs, eyes, mouth, etc, and functions like walk, talk, eat, see, etc.

Men and Women are also classes, but most of the properties and functions are included in HumanBeing. Hence, they can inherit everything from class HumanBeing using the concept of Inheritance. Here is a code example:

Inheritance code example

Output:

Calling the human being constructor
I'm a man, a male human being
I'm a human being

3. Objects

My name is Yann, and I am an instance/object of class Man. When we say, Human Being, Man or Woman, we just mean a kind, you, your friend, and I. We are the forms of these classes. We have a physical existence while a class is just a logical definition. We are the objects.

The syntax for creating an object of a class Man:

Man Yann = new Man();

4. Abstraction & Encapsulation

Encapsulation is a way to achieve “information hiding” so, you don’t “need to know the internal workings of the mobile phone to operate” with it. You have an interface to use the device behavior without knowing implementation details.

  • You get into the car, press a button, or turn the key to start the car and drive away, you don’t need to know what exactly happens behind the scenes with the engine and all the mechanics to operate your car. Internal details of the starting operations are hidden from you
  • Your laptop is connected to the internet, you don’t need to understand how the internet works to use it.
  • In code or while writing code, Encapsulation is to hide the variables or something inside a class, preventing unauthorized parties from using it. So the public methods like getter and setter access it and the other classes call these methods for accessing

Abstraction on the other side can be explained as the capability to use the same interface for different objects. Different implementations of the same interface can exist. Details are hidden by encapsulation.

A process of picking the essence of an object you really need

In other words, pick the properties you need from the object Example:
a. TV — Sound, Visuals, Power Input, Channels Input.
b. Mobile — Button/Touch screen, power button, volume button, sim port.
c. Car — Steering, Break, Clutch, Accelerator, Key Hole.
d. Human — Voice, Body, EyeSight, Hearing, Emotions.

To put it simply, ABSTRACT everything you need and ENCAPSULATE everything you don’t need. Source — (StackOverflow)

5. Polymorphism

Polymorphism is a concept, which allows us to redefine the way something works, by either changing how it is done or by changing the parts used to get it done. This can be done in two ways, overloading and overriding.

If we walk using our hands, and not legs, here we will change the parts used to perform something. Hence this is called Overloading.

Polymorphism: Early binding or Overloading code example

Output:

10
15

And if there is a defined way of walking, but I wish to walk differently, but using my legs, like everyone else. Then I can walk like I want, this will be called as Overriding.

Polymorphism: Late binding or Overriding code example

Output:

Hello! Nice to meet you!

If you enjoyed this article, please give it a few claps for support.

You might also like Algorithm’s Efficiency | Big O “In Simple English”

Cheers!!!

📝 Read this story later in Journal.

👩‍💻 Wake up every Sunday morning to the week’s most noteworthy stories in Tech waiting in your inbox. Read the Noteworthy in Tech newsletter.

--

--

Yann Mulonda

Co-Founder & CIO @ITOT | DevOps | Senior Site Reliability Engineer @ICF󠁧󠁢󠁳󠁣󠁴 | "Learning is experience; everything else is just information!”