DEV Community

Uchenna Edeoga
Uchenna Edeoga

Posted on

UNDERSTANDING OBJECT AND CLASS CONCEPT IN OOP FOR BEGINNERS

Understanding Objects and Class in OOP for Beginners
As a beginner, you have probably come across the word class, objects or perhaps you don’t seem to understand what Object-oriented Programming is and cannot understand the concept. I’ll try to establish a connection between these concepts with real-life things you can relate to as a beginner.
So when you hear the word Object, what comes to your mind? A mug, A chair, perhaps a Laptop, this in the real world is called an object, basically, anything that has a shape, or size. No what’s an object in programming?
Objects in programming is a way of representing the concept of real-world to a computer, so if you want to describe a Mug to a computer you’d say:
• It is a concrete object
• It has a shape
• It has a size
• It has a volume which liquid can contain.
These are all known to be the attributes of the object ‘mug’
So imagine every time you want to talk about the mug, you go around and describe it with its attributes instead of just using the word Mug, pretty time consuming right? We can make a computer remember all these details by grouping the attribute under the name mug this is known as ABSTRACTION in Object-Oriented programming. It refers to a way of representing general attributes of a concept, it serves to hide the complex mechanism of an object and leaving only the information we need to interact with it Another example is a forest, a forest has so many elements, trees, water, animals and so on, but all these ecosystem is referred to as forest. This is exactly what happens in Object-oriented Programming, instead of making the computer to remember all these attributes when we want to use them, they are grouped under a general concept to be easily used whenever we need them in our programming and for our computer to remember them(the attributes) easily for us. This is exactly why the use of objects in programming and one of the currently used methods.

An object is defined by the attributes it possesses. A mobile phone is an object that has attributes, there all different categories of a phone, but all possess common attributes. Asides having a Screen, a mobile phone has a touchpad, a camera, the volume button and so on. Despite all the categories they all fit into a blueprint in our minds, with this blueprint you can be able to manufacture any kind of mobile phone. In OOP this is referred to as a CLASS. A class is like a blueprint that is used to produce as many objects as possible.
Another example of a class in the real world is an architectural design plan for an Estate, this plan is a blueprint to produce let's say 500 houses or objects in this case. As long as this blueprint is used, you can produce as many objects as possible.
So how do classes help us create objects?
Using the Mobile device class, the computer works as a manufacturer, now let's say we want to make a Mobile phone, we need detailed plan, blueprint or a class with attributes needed for a mobile phone to be produced
NAME: MOBILE PHONE

ATTRIBUTES
Screen
Battery
Camera
Charging Port

Now while these describe the Mobile Phone, it doesn’t tell how the mobile phone behaves or works, each object has a behavior called a METHOD which describes the way the object behaves, our plan now has to be expanded to include the METHOD(behavior) of the object, in this case, Mobile Phone.

ATTRIBUTES      METHODS
Screen          for navigating your phone
    Battery         To Power the Phone
    Camera                To take Pictures and Videos
    Charging Port              Plug to power source.

Now that the Plan or class has been done we can now produce the Object (Mobile Phone). Every new phone made from this plan is known as the INSTANCE of that class/Plan. So every new object of a class is called the INSTANCE of that class.
You can use this Plan to create any kind of Mobile Phone, some phones screen are larger and expensive, and some have higher camera pixel quality and so on.

  ATTRIBUTES    VALUE
Screen          16” INCH
Battery         400MAH
   Camera           45PX
   Charging Port        USB Charging Port

With the list of values for our attributes, you can now see the same ones (defined in our plan) can have different values. Each list of values is specific to a single object, or in programming, an instance. This means you’ve got a lot of flexibility. The same plan can provide lots of different individual mobile phones, just like a house blueprint allows you to make a whole neighborhood of houses.

Top comments (0)