While working on #8 and refactoring the Disque\Connection\Manager, I realized that, no, we cannot just set a connection object instead of a class name, because we need to create a new connection for each node separately.
We have in my opinion two options:
Leave it as it is now - Manager gets a class name that conforms to the ConnectionInterface and creates its own connections as needed
Or the Manager gets a ConnectionBuilder (name may change) and every time it needs a new connection, it asks the builder for one.
The status quo has these advantages:
It's already there and it works.
It's simple - just set a class name and go.
Refactoring into a ConnectionBuilder has these advantages:
We can use type hinting instead of the "condition + exception" combo: Set a ConnectionBuilder instead of a class name, and further methods would require a ConnectionInterface
The Manager is already doing too much. ConnectionBuilder could make the Manager simpler by taking over all the steps needed for the actual connection:
Manager::buildConnection() - the instantiation of a new connection object
Manager::doConnect() - the actual connection
Manager::getNodeConnection() - the initial HELLO
(There are multiple steps, that's why I suggest the name Builder instead of Factory)
The Manager's role would then be to manage node connections as a group, choose the best node, disconnect the inactive ones etc. That's a complicated enough task, even without having to handhold single connections.
This is more an internal refactoring, not much would change for the library user (unless they want to use a different connection object).
While working on #8 and refactoring the
Disque\Connection\Manager
, I realized that, no, we cannot just set a connection object instead of a class name, because we need to create a new connection for each node separately.We have in my opinion two options:
Manager
gets a class name that conforms to theConnectionInterface
and creates its own connections as neededManager
gets aConnectionBuilder
(name may change) and every time it needs a new connection, it asks the builder for one.The status quo has these advantages:
Refactoring into a
ConnectionBuilder
has these advantages:ConnectionBuilder
instead of a class name, and further methods would require aConnectionInterface
Manager
is already doing too much.ConnectionBuilder
could make theManager
simpler by taking over all the steps needed for the actual connection:Manager::buildConnection()
- the instantiation of a new connection objectManager::doConnect()
- the actual connectionManager::getNodeConnection()
- the initialHELLO
(There are multiple steps, that's why I suggest the name
Builder
instead ofFactory
)The
Manager
's role would then be to manage node connections as a group, choose the best node, disconnect the inactive ones etc. That's a complicated enough task, even without having to handhold single connections.This is more an internal refactoring, not much would change for the library user (unless they want to use a different connection object).
How does it sound to you?