Hey Martin,
This sounds like a great idea. Classes should only require the dependencies they
actually need, partially because it makes unit testing much easier, as you point
out.
So if a large node object is being passed to classes that only use a small part
of that object, then it's definitely an architectural problem (it's been a very
long time since I delved into the codebase). The node option is basically
functioning as a static dependency.
If the solution is a publish-subscribe architecture, then one option you might
look at is Guava's EventBus, it is designed for exactly this purpose:
https://github.com/google/guava/wiki/EventBusExplained
Another way to avoid this kind of architectural problem is to use a dependency
injection framework like Guice (older but more widely used) or Daggar (newer 
and with faster startup time and better on mobile).
For anyone interested in avoiding this kind of software architecture mistake,
and many other mistakes, I highly recommend the book “Clean Code” by Robert C.
Martin. It's full of great ideas and best practices for architecting code (not
Java-specific, but most of the examples are Java).
Ian.





On Sat, May 7, 2016 5:10 AM, Martin Byrenheid [email protected] 
wrote:
Hello everyone,




I've spend some time thinking about how to make it easier to test Freenet's

different subsystems, especially without having to instantiate the whole

Freenet Node class for almost every test. One possibly helpful idea that came

to my mind is to decouple classes by using a publish-subscribe mechanism,

where each instance can subscribe to events (e.g. received a new announcement

request) and publish other events together with corresponding data (e.g. the

message and the neighbor node where the request came from). This way, many

subsystems could then trigger methods in other subsystems without having to

know them directly and also might not need a reference to the Node class

anymore, making them much easier to test.




I've integrated some examples within the NodeDispatcher-class and pushed it

into my Github repository [1]. Due to its rather high level of abstraction,

the publish-subscribe mechanism handles all attached data just as objects,

which is not nice regarding type safety. However, I haven't yet found a better

solution since I don't have much experience with Java and I first want to hear

your opinion about this approach.




Martin




[1]

https://github.com/yadevel/fred/commit/f4ce1b066ad673b995ea2a729ba21b2a7e932e5b

_______________________________________________

Devl mailing list

[email protected]

https://emu.freenetproject.org/cgi-bin/mailman/listinfo/devl



Ian Clarke
Founder, The Freenet Project
Email: [email protected]
_______________________________________________
Devl mailing list
[email protected]
https://emu.freenetproject.org/cgi-bin/mailman/listinfo/devl

Reply via email to