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.
Having hard time understanding OOP
Jun 7 2025, 12:01 AM
Quote
0.0134sec
0.34
6 queries
GZIP Disabled