python icon indicating copy to clipboard operation
python copied to clipboard

[Improve Concept Docs]: Class Inheritance

Open BethanyG opened this issue 3 years ago â€ĸ 0 comments

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:

Documents on Language Tracks and Concepts:


🙏đŸŊ Desired Improvements and Changes

  • [ ] Create/complete the missing introduction.md, links.json, and .meta/config.json files 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.
  • [ ] 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 how super() affects the MRO in multiple inheritance. This section of the Real Python article on super() can help, as can this article.
  • [ ] Clarify what a mixin is (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 Mixins are 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 mixin class name with "Mixin"
  • [ ] Show a practical example of a mixin class 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 classes in Python
  • understanding and use of single inheritance in Python
  • understanding and use of multiple inheritance in Python
    • the diamond inheritance problem
    • Pythons MRO (method resolution order)
    • pros and cos of mixins () to isolate multiple inheritance issues
  • when and when not to use super() to call a parent class constructor or method

đŸšĢ Out of scope

Concepts and Subjects that are Out of Scope
  • class-composition as an explicit topic (it is ok to use limited composition as needed in example code)
  • dataclasses
  • decorators outside 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 class as a decorator
  • performance considerations

🤔 Concepts

Concepts and Related Concepts this Concept Covers
  • classes
  • inheritance in OOP
  • 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

📁 Files to Be Updated or Created

File Detail for this Exercise

Please see the following for more details on these files: concepts

  • links.json

    For more information, see concept links file

    • The same resources listed in this issue can be used as a starting point for the concepts/links.json file, if it doesn't already exist.
    • If there are particularly good/interesting information sources for this concept that extend or supplement the concept exercise material & the resources already listed -- please add them to the links.json document.
  • Concept about.md

    For more information, see Concept about.md

    • This file provides information about this concept for a student who has completed the corresponding concept exercise. It is intended as a reference for continued learning.
  • Concept introduction.md

    For more information, see Concept introduction.md

    • This can also be a summary/paraphrase of the about.md document listed above, and will provide a brief introduction of the concept for a student who has not yet completed the associated concept or practice exercises. It should contain a good summation of the concept, but not go into lots of detail.
  • Concept .meta/config.json Entries

    For more information, see Concept .meta/config.json

    • This file is likely already stubbed out. Remember to add a concept blurb of less than 350 characters. Please also add your GitHub username to the "authors" array, and any contributor GitHub usernames to the "contributors" array.

đŸŽļ 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

  1. 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).
  2. 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.

BethanyG avatar Jun 11 '22 23:06 BethanyG