[tahoe-lafs-trac-stream] [Tahoe-LAFS] #2782: code reorg: less inheritance, more delegation/composition
Tahoe-LAFS
trac at tahoe-lafs.org
Wed Apr 27 21:42:49 UTC 2016
#2782: code reorg: less inheritance, more delegation/composition
------------------------+-----------------------
Reporter: warner | Owner:
Type: task | Status: new
Priority: minor | Milestone: undecided
Component: code | Version: 1.11.0
Resolution: | Keywords:
Launchpad Bug: |
------------------------+-----------------------
Comment (by meejah):
The basic pattern for doing this refactoring would look like:
- anything remotely complex that's created in an `__init__` method
becomes and arg
- the "make complex thing" work moves from `__init__` to some factory-
method
- repeat recursively ;)
So the last thing is the hard part, especially to avoid a "massive
refactor everything" type of branch/PR. I think the first step would be to
simply look at dependencies. I don't feel I know enough about `Node` /
`Client` to know if merging them is appropriate etc. It's fine to leave
them as a subclasses for now I think -- especially because `Node` only
really has a couple dependencies in the above model: a tempdir and a tub.
So, these would have to be passed into `Client` too so that `super()` can
get called properly.
It should also be possible to "start slow" and move things out one or two
dependencies at a time. From a quick grep it doesn't look like `Node()` is
ever constructed by itself, so we should be able to move its dependencies
into args-to-Client without making a `create_node` factory-method.
So a start would be:
- introduce a `create_client` factory-method, taking `basedir` and `tub`
- change Node's constructor to get rid of `self.create_tub` and (most of)
`init_tempdir`
- move (most of) `Node.create_tub` to a factory method (or even just make
it @staticmethod?)
This would probably give a good idea of how this would look/work, and
would even probably be land-able without anything else changing...From
there, it would be a "small matter of programming" to do something similar
for `Client`'s dependencies, and a `create_client()` factory method.
--
Ticket URL: <https://tahoe-lafs.org/trac/tahoe-lafs/ticket/2782#comment:1>
Tahoe-LAFS <https://Tahoe-LAFS.org>
secure decentralized storage
More information about the tahoe-lafs-trac-stream
mailing list