Added a few words for clarity (#31744)

Changes made to the third paragraph under OO concepts.
pull/28948/head^2
Eric Hodges 2019-04-03 02:10:45 -07:00 committed by The Coding Aviator
parent 5f723096c5
commit c6945de3db
1 changed files with 1 additions and 1 deletions

View File

@ -21,7 +21,7 @@ These are collectively known as the "four pillars" of OOP.
In procedural programming, we simply create variables and change them when required. However in OO programming, we can literally simulate real world objects. Encapsulation is achieved by creating a specific class for an entity, for example dog. Objects of this class are then created, which are nothing but instances of the class. Each object has its own attribute values.
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.
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 an enemy. We can create a base class called person, and give it attributes like name, age, gender, etc. A person's behaviour can be walk and jump. A player and an 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). 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.