[Improve Concept Docs]: Class Inheritance
This issue describes desired additions and improvements to the class inheritance concept docs..
The related concept exercise issue and specs can be found here,
If you have not yet contributed to concept documents, this issue will require some upfront reading to give you the needed background knowledge. Additionally, we recommend reading the existing about.md docs here, and an example of completed concept docs here.
â Getting started
Please please read the docs before starting. Posting PRs without reading these docs will be a lot more frustrating for you during the review cycle, and exhaust Exercism's maintainers' time.
General Contributing Docs:
- Contributing to Exercism | Exercism and GitHub | - Contributor Pull Request Guide
- What are those Weird Task Tags about?
- Exercism Formatting and Style Guide
- Exercism Markdown Specification
- Reputation
Documents on Language Tracks and Concepts:
đđŊ Desired Improvements and Changes
- [ ] Create/complete the missing
introduction.md,links.json, and.meta/config.jsonfiles for this concept. - [ ] Where code examples show the output of running a program, they should be formatted as REPL examples (see this concept for some examples of REPL formatting)
- [ ] Add more explanation or examples (or argument the existing one) of inheriting and then extending attributes and methods from a single parent class. This article has some good examples.
- [ ] Re-organize document to put the explanation and various uses of
super()into a section following the single inheritance section.- [ ] Clarify/Add a bit more on what
super()does, and why you might use it. This article has some good information. This article and this article have some good info, too. - [ ] Add example that illustrates the use of
super().__init__()in making a derived class. - [ ] Add example that shows the use of
super()in a derived class to call a parent method.
- [ ] Clarify/Add a bit more on what
- [ ] Provide more explanation for multiple inheritance, and some background on its controversy. (This article has some good sections explaining multiple inheritance and its issues).
- [ ] Provide a practical example of multiple inheritance with extended attributes and methods in the child class. This article might have some good examples, as well as this one
- [ ] Provide a practical example of multiple inheritance problems in action, as a set up to the diamond inheritance problem. This article might have some examples that help.
- [ ] Clarify the diamond problem explanation, and talk a little about Python's MRO and mention its C3 algorithm for multiple inheritance resolution. This is an old but good blogpost about MRO.
- [ ] Add how
super()can help with the diamond problem, and howsuper()affects the MRO in multiple inheritance. This section of the Real Python article onsuper()can help, as can this article. - [ ] Clarify what a
mixinis (a class created solely to add specific and isolated functionality to one or more base classes) and what it can do generally. This SO post, This article and this article can help.- you want to provide a lot of optional features for a class
- you want to provide a specific set of features in a lot of different classes
- [ ] Clarify that
Mixinsare often used to combat "gotchas" that come with multiple inheritance. this article has some good information for that. - [ ] Talk about the Python convention of ending a
mixinclass name with "Mixin" - [ ] Show a practical example of a
mixinclass and its use in one or more child classes.
đ Original Specifications
Below are the original specifications from the Concept issue. Please use these as a guide in addition to the change list above.
đ¯ Goal
This concept is meant to teach an understanding/use of class-inheritance in Python.
đĄ Learning objectives
- more fully understand the uses (and possible abuses) of
classesin Python - understanding and use of
single inheritancein Python - understanding and use of
multiple inheritancein Python- the diamond inheritance problem
- Pythons MRO (method resolution order)
- pros and cos of
mixins() to isolatemultiple inheritanceissues
- when and when not to use
super()to call a parentclassconstructor or method
đĢ Out of scope
Concepts and Subjects that are Out of Scope
-
class-compositionas an explicit topic (it is ok to use limited composition as needed in example code) -
dataclasses -
decoratorsoutside of@property,@staticmethod, and@classmethod(the student should already be exposed to these in the prerequisite exercise) -
generators -
coroutines -
descriptors(these will get their own exercise) - using a
classas a decorator - performance considerations
đ¤ Concepts
Concepts and Related Concepts this Concept Covers
-
classes -
inheritanceinOOP -
single inheritance -
multiple inheritance -
minxins -
super()
âŠī¸ Prerequisites
These are the concepts/concept exercises the student should be familiar with before taking on/learning this concept.
Prereqs
-
basics -
booleans -
classes -
class-customization -
comparisons -
decorators -
dicts -
functions -
higher-order-functions -
iteration -
lists -
numbers -
sequences -
sets -
strings -
tuples
đ Resources to Refer to (in addition to the ones linked in the task list)
Resources
- classes (Python tutorial)
- Real Python: Object-Oriented Programming in Python 3
- Real Python: Inheritance and Composition: A Python OOP Guide
- Towards DataScience: Understand Inheritance in Python -- (this is not a good resource for hints or links, since it requires an account signup)
- Multiple Inheritance in Python
- Multiple Inheritance is Hard (Ned Batchelder)
- Python.org: MRO in Python 2.3+
- Dig into Python super() and MRO
- Multiple inheritance and mixin classes in Python
- Making Python classes more modular using mixins
- Write composable, reusable Python classes using Mixinsl)
- Mixins in Python and Ruby Compared
- Python Data Model - Python Docs
đ Files to Be Updated or Created
File Detail for this Exercise
|
Please see the following for more details on these files: concepts
|
đļ Implementation Notes
- Example code should only use syntax & concepts introduced within these docs or one of the prerequisite concept exercises or documents. Where possible, please use REPL formatting, unless you are demonstrating pseudo code or a long code block. Please do not use syntax not previously covered in prerequisite topics or exercises. Please also follow PEP8 guidelines.
- Our markdown and JSON files are checked against prettier . We recommend setting prettier up locally and running it prior to submitting your PR to avoid any CI errors.
đ Next Steps & Getting Help
-
If you'd like to work on this issue, comment saying "I'd like to work on this"(there is no real need to wait for a response, just go ahead, we'll assign you and put a[claimed]label on the issue). - If you have any questions while implementing, please post the questions as comments in here, or contact one of the maintainers on our Slack channel.