User Tools

Site Tools


notes:cprog:fall2021:projects:oop1

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
notes:cprog:fall2021:projects:oop1 [2021/11/04 02:32] – [References] ehauber1notes:cprog:fall2021:projects:oop1 [2021/11/05 04:01] (current) – [References] hhemler
Line 78: Line 78:
 Since the Child simply inherits the properties of the Parent, one Parent can have multiple Children. Since the Child simply inherits the properties of the Parent, one Parent can have multiple Children.
 Two Children of the same Parent will also have no direct relationship.  Two Children of the same Parent will also have no direct relationship. 
-Children can themselves have Children that inherit from them, creating large inheritance chains.+Children can themselves have Children that inherit from them, creating large inheritance chains.  
 +Children can also multi-inherit, taking on the attributes of multiple Parents
  
 Parent/Child inheritance chains are a beneficial way to add specifications to classes without changing the base class functions.  An example of this may be Animals->Dogs: An animal would have a size, age, living/death status, which are all properties that a dog could inherit, however, a dog could have it's own functions like fur length, temperament, so on and so forth.  This could be extended by creating a dog breed class.  Parent/Child inheritance chains are a beneficial way to add specifications to classes without changing the base class functions.  An example of this may be Animals->Dogs: An animal would have a size, age, living/death status, which are all properties that a dog could inherit, however, a dog could have it's own functions like fur length, temperament, so on and so forth.  This could be extended by creating a dog breed class. 
  
-Each Child belongs to one Parentand the Child needs to know the Parent to which it belongsThe construction of the Parent logically includes the construction of the Child+It’s also possible to inherit from a class that is itself derived from another class 
 +====A reflection on the concept of inheritance==== 
 +(among other things) 
 + 
 +It is easier to understand inheritance than it is most concepts in programmingbecause inheritance follows so closely to where it gets its name from. If you asked a non-computer programmer what a string is it would likely make them think of a string of fabric, whereas if you asked them what inheritance is they would probably think of a concept the same as how inheritance functions in C++. 
 + 
 +Something Interesting to note is that child class cannot access the private information relating to their parents, but can still have themFor example, if plant(as a parent class of tree) has a private int of age, then tree will also have a private value of age. This is because when inheritance is activated it calls upon the parent's constructor, which can access the parent's private values. 
 + 
 +When something has multiple parents it is called multiple inheritance. When there is more than one tier of inheritance (grandparents) it is called multilevel inheritance. When something has multiple children it is called hierarchical inheritance. When multiple of these occur it is called hybrid inheritance. 
 + 
 +Inheritance allows us to reuse classes by having other classes inherit their members. 
 + 
 +It is possible to make a class non-subclassable (sterile) in C++ with the "final" keyword. 
 + 
 +COOL BUG FACT: Inheritance was first created for the Simula programming languages
 =====Program===== =====Program=====
 Write a program that creates a parent-child class structure. It can be anything, so long as you genuinely implement it and it works. A few possible examples for inspiration: Write a program that creates a parent-child class structure. It can be anything, so long as you genuinely implement it and it works. A few possible examples for inspiration:
Line 97: Line 112:
   * https://www.learncpp.com/cpp-tutorial/basic-inheritance-in-c/   * https://www.learncpp.com/cpp-tutorial/basic-inheritance-in-c/
   * https://www.programiz.com/cpp-programming/public-protected-private-inheritance/   * https://www.programiz.com/cpp-programming/public-protected-private-inheritance/
-  * https://social.msdn.microsoft.com/Forums/sqlserver/en-US/8e65af25-8281-4352-8418-4bd2bf614ba5/smart-pointers-parent-child-relationships?forum=vcgener 
   * https://www.w3schools.com/cpp/cpp_inheritance.asp   * https://www.w3schools.com/cpp/cpp_inheritance.asp
   * https://www.tutorialspoint.com/cplusplus/cpp_inheritance.htm   * https://www.tutorialspoint.com/cplusplus/cpp_inheritance.htm
notes/cprog/fall2021/projects/oop1.1635993177.txt.gz · Last modified: 2021/11/04 02:32 by ehauber1