code reorg: less inheritance, more delegation/composition #2782
Labels
No Label
0.2.0
0.3.0
0.4.0
0.5.0
0.5.1
0.6.0
0.6.1
0.7.0
0.8.0
0.9.0
1.0.0
1.1.0
1.10.0
1.10.1
1.10.2
1.10a2
1.11.0
1.12.0
1.12.1
1.13.0
1.14.0
1.15.0
1.15.1
1.2.0
1.3.0
1.4.1
1.5.0
1.6.0
1.6.1
1.7.0
1.7.1
1.7β
1.8.0
1.8.1
1.8.2
1.8.3
1.8β
1.9.0
1.9.0-s3branch
1.9.0a1
1.9.0a2
1.9.0b1
1.9.1
1.9.2
1.9.2a1
LeastAuthority.com automation
blocker
cannot reproduce
cloud-branch
code
code-dirnodes
code-encoding
code-frontend
code-frontend-cli
code-frontend-ftp-sftp
code-frontend-magic-folder
code-frontend-web
code-mutable
code-network
code-nodeadmin
code-peerselection
code-storage
contrib
critical
defect
dev-infrastructure
documentation
duplicate
enhancement
fixed
invalid
major
minor
n/a
normal
operational
packaging
somebody else's problem
supercritical
task
trivial
unknown
was already fixed
website
wontfix
worksforme
No Milestone
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Reference: tahoe-lafs/trac-2024-07-25#2782
Loading…
Reference in New Issue
No description provided.
Delete Branch "%!s(<nil>)"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
In the comments on PR270, meejah pointed out that
Client.*init*
is doing a lot of work, and that it might be better to build these nodes with a function (rather than a class constructor) that is given the supporting objects (like an IntroducerClient, StorageServer, and !Tub), instead of creating those things itself. Glyph recently pointed me at an enlightening presentation known as "The Talk" from PyCon2013, that encourages composition over inheritance, which ties in.I'm not exactly sure what this would look like, but we could start by either merging Node and Client into a single class, or passing Node in as an argument to the Client constructor. Then we might make a client-creating function that builds Storage Servers and Introducer Clients first, then passes them as arguments into the Client constructor.
The basic pattern for doing this refactoring would look like:
*init*
method becomes and arg*init*
to some factory-methodSo 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 becauseNode
only really has a couple dependencies in the above model: a tempdir and a tub. So, these would have to be passed intoClient
too so thatsuper()
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 acreate_node
factory-method.So a start would be:
create_client
factory-method, takingbasedir
andtub
self.create_tub
and (most of)init_tempdir
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 acreate_client()
factory method.