Welcome Guest ( Log In | Register )

Outline · [ Standard ] · Linear+

 Having hard time understanding OOP

views
     
silkworm
post Jun 7 2025, 12:01 AM

Enthusiast
Group Icon
Elite
965 posts

Joined: Jan 2003
From: Kajang


Think of raw construction materials, like wood, sand or rocks. Used as-is, we can maybe whip up a basic shelter like a hut.

Take some sand, cement, water and pour it into a rectangular mould. We've Encapsulated those materials into a standard unit, a brick.

The shape and size of the brick is independent from the material it is made of. The brick is an Abstraction. Now we can make straight, tall walls for a house.

Perhaps the sand brick is too weak to build over a certain height, or looks ugly. Mix in some stone, or use clay, but keep the same mould dimensions. The new bricks Inherit the dimensions of the original brick but have different properties such as strength, or may be more expensive (or cheaper).

Because the dimensions of the brick are the same we can use the bricks interchangeably to achieve the desired strength, aesthetics, or cost target for our wall. They exhibit Polymorphism.

Now, recall the usual programming 101 material such as variables, functions, if-else statements, for-loops, whiles or do-whiles, etc. Those are the raw materials that we use as programmers.

silkworm
post Jul 18 2025, 12:25 PM

Enthusiast
Group Icon
Elite
965 posts

Joined: Jan 2003
From: Kajang


QUOTE(otai_g @ Jul 18 2025, 11:27 AM)
the simple example to easy understand.

proton car.

car is class and proton is object.
*
Almost. You could say that, "A red Proton Saga with half a tank of petrol, 79000 km on the odometer, half-worn GoodYear tyres, going at 90km/h on the PLUS highway", is an object of the Car class.

This post has been edited by silkworm: Jul 18 2025, 05:29 PM

 

Change to:
| Lo-Fi Version
0.0134sec    0.34    6 queries    GZIP Disabled
Time is now: 16th December 2025 - 11:42 AM