What do you think about dependency injecting the FTPDriver itself so that the IO (establishing connection) isn't in the constructor? Example:
class FTPClient: def __init__(self, driver): self._driver = driver @classmethod def from_connection(cls, host, port): driver = FTPDriver(host, port) return cls(driver) ...
This allows one to install a TestDriver for testing FTPClient. and bubbles up IO to an outer layer which uncle bob is big on (blog.cleancoder.com/uncle-bob/2012...), but we get to do it in one class because Python supports classmethods.
TestDriver
FTPClient
It's an excellent practice. I left it out so the examples were more concrete and demonstrated the principles as simply as possible.
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
What do you think about dependency injecting the FTPDriver itself so that the IO (establishing connection) isn't in the constructor? Example:
This allows one to install a
TestDriver
for testingFTPClient
. and bubbles up IO to an outer layer which uncle bob is big on (blog.cleancoder.com/uncle-bob/2012...), but we get to do it in one class because Python supports classmethods.It's an excellent practice. I left it out so the examples were more concrete and demonstrated the principles as simply as possible.