Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Favour composition over inheritance for Stream #15

Open
lmmx opened this issue Mar 30, 2021 · 0 comments
Open

Favour composition over inheritance for Stream #15

lmmx opened this issue Mar 30, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@lmmx
Copy link
Owner

lmmx commented Mar 30, 2021

(Note: after review, this may end up indicating beeb’s interface is the one to edit)

Following the guide here: https://python-patterns.guide/gang-of-four/composition-over-inheritance/

  • The principle to “favour composition over inheritance” is apparently a desirable design pattern
  • The “decorator pattern” (a class which wraps around a pre-existing class to add functionality) was the memoised dynamic inheritance I disliked when considering how to subclass beeb’s Stream class but also leave it open to others
    • in fact “multiple inheritance” and “dynamic class building” are both listed as “dodges”!

Solution # 1: The Adapter Pattern
Solution # 2: The Bridge Pattern
Solution # 3: The Decorator Pattern
Solution # 4: Beyond the Gang of Four patterns
Dodge: “if” statements
Dodge: Multiple Inheritance
Dodge: Mixins
Dodge: Building classes dynamically’

I prefer the ‘bridge’ pattern, and suggest switching to that: supplying a handler class from which the other methods would acquire their action from (TODO: review)

  • The downside is that it isn’t wrapped up neatly, and would require the object to be created in advance. I want to just specify the broadcaster as a string, not have to import the broadcaster-specific class
@lmmx lmmx added the enhancement New feature or request label Mar 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant