Replies: 1 comment
-
Hey @mrbazzan, I converted this to a discussion so we can better chat about this topic. A great question and thanks for reaching out! What you've shown here is roughly the idea I meant to convey, yes. It's a contrived example, but for thoroughness I would probably do something like this: class Shell:
def __init__(self, size):
self.size = size
class Snail:
def __init__(self, name, shell):
self.name = name
self.shell = shell
@property
def shell_size(self):
return self.shell.size
Snail("Hafsoh", Shell(3)) And later on, if you find that |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Thanks for this great work.
In chapter 8.2.2 (Substitutability), you gave the following example,
practices-of-the-python-pro/ch08/gastropods.py
Lines 1 to 22 in 98bd0a1
and further noted the following words:
Is this code below along the lines of what you were thinking?
Instead of making
Snail
inherit fromSlug
, the shellbehavior should be composed into the snail class, and there
shouldn't be any need for inheritance.
Beta Was this translation helpful? Give feedback.
All reactions