DEV Community

Cover image for OOP? START HERE
Sele
Sele

Posted on

OOP? START HERE

Some time or another you must have come across the term object-oriented programming. It is the most popular programming paradigm in software engineering. Object oriented programming is a programming paradigm that is heavily based on the concepts of classes and objects, where these objects can contain data and procedures. It allows us to structure our applications into entities called classes. We can also define OOP as a paradigm that allows us to represent real world entities as object and classes. For some history OOP started in around 1962 with a programming language called SIMULA. It was mainly used for simulations, but it wasn’t until the introduction of c++ that OOP became main stream in software engineering.
OOP is strongly based on the concept on object and classes. So, what are classes and objects. Basically, a class is simply the blueprint that defines the structure of how an instance of an object will be. When we say blue print it consist of data (variables and fields) and procedure(methods) pertaining to that entity. An object therefore is simply the instance of a class which will then take up all the attribute of the class in question. Let’s take a simple example

    public class Person
    {
        public string Name { get; set; }
        public string Job { get; set; }
        public string Height { get; set; }
        public string Weight { get; set; }
        public string Walking()
        {
            return "I am Walking";
        }
        public string Sleeping()
        {
            return "I am sleeping";
        }

}
Enter fullscreen mode Exit fullscreen mode

The source code above is a class called person with some field attributes and methods

static void Main(string[] args)
        {
            //create an instance of that class
            Person person = new Person();
            //instantiate the values in that class
            person.Job = "Banker";
            person.Name = "Jacob";
            person.Height = "5,3";
            person.Weight = "65kg";
            //Display them on the screen
            Console.WriteLine(person.Weight);
            Console.WriteLine(person.Height);
            Console.WriteLine(person.Job);
            Console.WriteLine(person.Name);
            Console.WriteLine(person.Sleeping());
            Console.WriteLine(person.Walking());
        }
Enter fullscreen mode Exit fullscreen mode

We created an instance of the class Person and gave the fields values. The ‘person’ is an object. We can now instantiate those fields with values or run the methods. So from the example we can see that the object 'person' has all the attributes of the class Person. The Person class defined the blueprint and the instance of that class which is 'person' had all the properties of class Person. So that’s is the basic relationship with classes and objects
Today we talked about the basics of OOP (object-oriented programming), but note this is just the start. OOP is a wide concept; in subsequent articles I will explain more like the pillars of OOP and object-oriented design, but for now let us stop here. We created a class and we created an instance of that class. We were able to explain how the class and the object are related. There will be more articles coming from this topic. Please like, comment and follow for more.

Discussion (0)