You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## Release V.1.0.0
The following marks the point at which the website becomes fully
viewable and usable, complete with all listed features and fixes. This
milestone designates the official release, which will be supported by a
subsequent package for maintanance and version control for the future.
Fixes:
---
* Permalink keeping a (.html) at the end of its domain link, which has
now been removed. Default to ( permalink: pretty ) .
#102
* Parent / grandParent rooting for certain articles
#106
* Issue Template changes
#101
Adds:
---
* Base content for the Main Topic areas First referenced on the page
such as:
IDE
Language
Framework
Engine
Concepts
Version Controls
* Article Describtions (Now shows a small text to the user when the
HyperLink is shared to social media or any alternative)
#99
* Content Written for OOP, Polymorphisism. Thank you for the
contribution(s) @JDSherbert .
Copy file name to clipboardExpand all lines: _config.yml
+1Lines changed: 1 addition & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,7 @@
1
1
title: Programming Handbook
2
2
description: An open-source platform for sharing and preserving programming knowledge. Discover code snippets, best practices, and resources, all continuously updated by a thriving community of developers. Join us to collaborate and enhance your coding skills in one comprehensive space.
description: "Warning: The following page is currently under construction, find more about the details in future patches, or if you choose to add in the article see info on the bottom of the page."
4
+
description: "An article dicussing Inheritance."
5
5
nav_order: 1
6
6
parent: Concepts
7
7
has_children: false
@@ -10,9 +10,141 @@ has_children: false
10
10
{{ page.title }}
11
11
======================
12
12
13
-
{% include under_construction.html %}
13
+
Inheritance is a fundamental concept in object-oriented programming (OOP) that allows a new class to inherit properties and behaviors (methods) from an existing class. This mechanism promotes code reusability, organizational structure, and the ability to create a hierarchical relationship between classes.
14
14
15
+
## Key Concepts
15
16
16
-
<br>
17
+
### Base Class (Parent or Superclass):
18
+
The class whose properties and methods are inherited by another class.
19
+
Example: Animal might be a base class.
17
20
18
-
<br>
21
+
### Derived Class (Child or Subclass):
22
+
The class that inherits from the base class.
23
+
Example: Dog might be a derived class that inherits from Animal.
24
+
25
+
### Access Specifiers:
26
+
Define the accessibility of the members of a class. Common access specifiers include:
27
+
#### - public: Accessible from any other class.
28
+
#### - protected: Accessible within its own class and by derived classes.
29
+
#### - private: Accessible only within the class itself.
30
+
31
+
### Override:
32
+
The derived class can provide a specific implementation of a method that is already defined in its base class.
33
+
34
+
### Extend:
35
+
The derived class can add new methods and properties in addition to those inherited from the base class.
36
+
Example in Python
37
+
Here's an example of inheritance in Python:
38
+
39
+
{: .code }
40
+
```cpp
41
+
#include<iostream>
42
+
usingnamespacestd;
43
+
44
+
classAnimal
45
+
{
46
+
47
+
// "Public" means any class can access these functions.
48
+
public:
49
+
50
+
Animal(string name)
51
+
: Name(name)
52
+
{
53
+
}
54
+
55
+
// "Virtual" functions can be "overridden" in child classes.
56
+
virtual void Speak()
57
+
{
58
+
cout << Name << " makes a sound" << endl;
59
+
}
60
+
61
+
// "Protected" means that any derived class can access these properties.
62
+
// It cannot be accessed outside of this class or its children.
63
+
protected:
64
+
65
+
string Name;
66
+
67
+
};
68
+
69
+
class Dog : public Animal
70
+
{
71
+
72
+
public:
73
+
74
+
Dog(string name)
75
+
: Animal(name)
76
+
{
77
+
}
78
+
79
+
// "Override" will try to use this implementation of that function.
80
+
virtual void Speak()
81
+
{
82
+
cout << Name << " barks" << endl;
83
+
} override;
84
+
85
+
};
86
+
87
+
class Cat : public Animal
88
+
{
89
+
90
+
public:
91
+
92
+
Cat(string name)
93
+
: Animal(name)
94
+
{
95
+
}
96
+
97
+
// "Override" will try to use this implementation of that function.
98
+
virtual void Speak()
99
+
{
100
+
cout << name << " meows" << endl;
101
+
} override;
102
+
103
+
};
104
+
105
+
int main()
106
+
{
107
+
Dog dog("Buddy");
108
+
Cat cat("Whiskers");
109
+
110
+
dog.Speak(); // Output: Buddy barks
111
+
cat.Speak(); // Output: Whiskers meows
112
+
113
+
return 69;
114
+
}
115
+
```
116
+
117
+
## Benefits of Inheritance
118
+
119
+
### Code Reusability:
120
+
Common functionality can be written once in the base class and reused by derived classes.
121
+
122
+
### Hierarchical Classification:
123
+
Allows the creation of a natural class hierarchy, making the code more logical and easier to understand.
124
+
125
+
### Extensibility:
126
+
New functionality can be added with minimal changes to existing code.
127
+
128
+
### Maintainability:
129
+
Simplifies code maintenance by reducing redundancy.
130
+
131
+
## Considerations and Best Practices
132
+
133
+
### Avoid Deep Inheritance Hierarchies:
134
+
Deep hierarchies can make the code difficult to understand and maintain. Prefer composition over inheritance when appropriate.
135
+
136
+
### Use Inheritance for "Is-A" Relationships:
137
+
Ensure that the derived class is a specialized version of the base class. For example, a Dog is an Animal.
138
+
139
+
### Leverage Polymorphism:
140
+
Use polymorphism to write more general and flexible code that can work with objects of the base class or any of its derived classes.
141
+
You can read more about [Polymorphism](https://github.com/JDSherbert/Programming_HandBook/blob/main/docs/Concepts/Polymorphism/Polymorphism.md) here.
142
+
143
+
### Override Methods Carefully:
144
+
When overriding methods, ensure that the new implementation is consistent with the expected behavior defined in the base class.
145
+
By understanding and applying the concept of inheritance correctly, you can create more efficient, maintainable, and organized code.
0 commit comments