Added details about abstraction (#30062)

This commit is contained in:
singhharshdeep
2019-04-03 05:10:08 -04:00
committed by The Coding Aviator
parent 8935f3ad15
commit a332cfb778

View File

@ -23,7 +23,7 @@ In procedural programming, we simply create variables and change them when requi
Another extremely useful concept is that of inheritance. The idea is that a class can inherit attributes and behaviour from a base class. For example, while creating a game, we have a player and enemy. We can create a base class called person, and give it attributes like name, age, gender, etc. Person's behaviour can be walk and jump. A player and enemy can then inherit these "qualities" from person, and can have added qualities like kill, score, eat, etc.
This helps in reusing code and making your code structure much cleaner. Data hiding is another cool feature. In OO, we have the notion of private and public attributes. Private attributes can be accessed and modified only by methods of that particular class, while public data can be modified from anywhere in the program (within scope obviously).
This helps in reusing code and making your code structure much cleaner. Data hiding is another cool feature. In OO, we have the notion of private and public attributes. Private attributes can be accessed and modified only by methods of that particular class, while public data can be modified from anywhere in the program (within scope obviously). The main goal of abstraction is to handle all the complexity and hiding unnecessary details from the user. A real life example of this can be that of a car: When we push the accelerator, the car starts to move. All the internal mechanics that are involved in the movement are irrelevant to us and are hence hidden.
OO programming represents problem as a real-life statement and thus helps us solve those problems in an effective way. An object in OO programming represents a real-life entity. A class represents a blueprint of a number of objects. An object can be considered as an instance of a class.
@ -36,4 +36,4 @@ See the image below. It represents a blueprint of a class named car. An instance
## What next?
Pick an OO language, and build a basic terminal based game to illustrate these concepts.
Suggested Read - https://sourcemaking.com/design-patterns-and-tips
Suggested Read - https://sourcemaking.com/design-patterns-and-tips