I have a protocol stack implementation, where each layer receives the below layer in the constructor in order to communicate with them, like:
ApplicationLayer app =
new ApplicationLayer(
new DataLinkLayer(
new PhysicalLayer()
));
What I need here it’s to control the classes of the instatiated objects, in order to to change the layers type just by changing a file (not a .java one, something like .xml). One of the possible usages it’s to implement logger layers between each layer, like:
ApplicationLayer app =
new ApplicationLayer(
new AppLogLayer(
new DataLinkLayer(
new DataLinkLogLayer(
new PhysicalLayer()
))));
With that, my source code keeps the same in production (where we don’t need log) and in development (where I need logging), just by changing an external (to the .jar) file.
Is there any framework to do that? Preferentially with Eclipse integration.
Sounds like you want a dependency injection/inversion of control library. Spring and Guice are the canonical examples, although for something this simple you might just spin your own.