DHB coupling #99
Loading…
x
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
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?
I have architectural suggestions for DHB, which would improve its maintainability, readability and ease of use (especially for newer projects).
DHB is coupled to other components:
It would be better if one could just instantiate a device handlers without worrying about all these other objects (there is a default FDIR for example). I started development with a DummyDeviceHandler. I did not need a the health table, power switchers, confirm failures and a raw data receiver but I just implemented them eventually.
Now I am trying to get a device handler running on linux to be able to test local pools of 2 OSes and I have the same exact problem: Components are missing (coupling!). In my opinion this is okay for objects like DeviceComIF and CookieIF which are just passed in the CTOR, but for objects like the Health Helper I don't even get a proper warning, I have to step through initialize() to find out it was a missing health table.
I suggest that the first 4 components are decoupled from DHB as a first step. This is easier for Health Table, which are only accessed via the helper interface ( with the little architectural question whether their active state is checked in the helper class or inside the device handler. I'd say that it would be better if this is handled in the DHB) The first 2 maybe should be packaged inside a helper(e.g. PowerHelper?) as well as the third one (e.g. DeviceHandlerHelper, wich handles raw traffic/wiretapping?).
Doing that has other benefits: Unit testing the components of DHB becomes easier/possible. For components like the helpers, this is already possible using mocks und their public interface, but if the logic is spread over a lot of functions which are private as they should be, unit testing them (and thus making refactoring more safe and easy) becomes difficult or impossible.
Performing all of those steps will propably also decrease the LOC of the main module and increase its readability. Of course, the logic will be spread over multiple files, but the logic of a certain domain (like power handling) will be packaged neatly inside a helper module. This might also decrease the number of instance variables (currently 20+ I think) or at the very least transform them into private variables which are passed to the helper, if the helper has to set a state of its owner.
UPDATE:
What do you think about setting optional ctor arguments in separate setter functions?
Something like this:
If these objects are not set, their default values will put the DHB in a state which does not use the functionalities.
If HK destination is not set, the static framework ID defaultHkDestination will be set, which can be specified in the factory. That way, it is possible to set the HK destination of all device handlers to a default service (for periodic handling), and set the destination for individual device handlers to another HK destination, if that is needed.
Also, excerpt of the changed initialize() function to make raw receiver and PowerSwitch optional
of course, there are more checks inside the code now which ensure that power switcher won't be called if it is not set.
DHB is not hard coupled with the following anymore:
If any of those are not intiated a error is printed to the sif:
HealthTable (required through HealthHelper)
DeviceComIF (A ObjectId to a valid SystemObject is required)
CookieIF (A pointer to valid CookieIF is required in the constructor of DHB. Nullptr checks are implemented)
I consider this solved with the current state.