OOP Fundamentals using C# | What is Object Oriented Programming?


Object-Oriented Programming - Concepts & Fundamentals

Classes & Objects


What is OOP?

As the name suggests, OOP is a programming paradigm that is driven by the use of objects. It focuses on the definition of a systems data model and how the objects in that model might interact with one and other, rather than focusing on procedure or functionality of a given object, but what is an object ?

Almost anything can be defined as an object, a human being for example; a human being has many defining attributes such as eye color, age, height etc. We are also capable
of performing many actions, such as breathing or eating, so you could say that a standard human-being has several variables attached to them, e.g age, height, eye color, and they are capable of some functionality, like breathing etc. If we were to use this information to define a basic class(c#) for the human-being, we could create unique instances of that class, using the class definition as "template" of sorts. So in essence, an object is a single instance of a given class.

Classes

Here is a basic class definition for a human using psuedo-code.
     
 public class Human{ 

    //variable declaration
    private int age; 
    private int hunger; 
    private string eyeColor; 
    private float height; 
    
    //class constructor
    public Human() 

    { 

    } 

    //functionality / methods
    public void Eat() 

    {   
         //do stuff
    } 

    public void Breathe() 

    { 
         //do stuff
    } 

 } 


This class represents the basic template of the human object, the "DNA" if you will. From this class, we can create many human objects. When we create instances of this class we will pass values into these variables giving the object its data values, and we can then call the methods associated with the human class e.g Eat() or Breathe().

The attributes within the class declaration act as a template for us to create many unique instances.

As you can see, when you consider the data model for your system first, we can write a lot of code without even knowing what functionality will be present within it. This means that you can design an entire system without considering what the objects within that system might actually do at a functional level. 

In the next post we will consider more class examples and look at a powerful design tool known as UML (Unified Modelling Language) for defining the data model of a system.



Further Reading...

https://www.codeproject.com/Articles/22769/Introduction-to-Object-Oriented-Programming-Concep

https://www.webopedia.com/TERM/O/object_oriented_programming_OOP.html

Comments