I'm developing an application (Java) in a modular architecture. I have two approaches in mind and I'm not sure which one will be "better code" in case of maintenance and conventions.
I have two main modules that I want to wire them up:
- CORE
CORE- backend stuff - UI
UI- frontend stuff
and now I want to wire them up.
APPROACH #1
CORE module will expose Engine class, UI will expose UserInterface class.
UserInterface will need an Engine in its constructor. Creationcan think of both objects will take place in the third module called LAUNCHER.
APPROACH #2
CORE module will expose Engine class, UI will expose UserInterface class. The difference is both modules with expose those classes ONLY to PRELAUNCHER module that will create objects and pass them to the LAUNCHER module as interfaces.two approaches:
MY THOUGHTS:
APPROACH 1:
COREmodule will exposeEngineclass,UIwill exposeUserInterfaceclass.UserInterfacewill need anEnginein its constructor. Creation of both objects will take place in the third module calledLAUNCHER.APPROACH 2:
COREmodule will exposeEngineclass,UIwill exposeUserInterfaceclass. The difference is both modules with expose those classes ONLY toPRELAUNCHERmodule that will create objects and pass them to theLAUNCHERmodule as interfaces.
The second approach looks promising, because it won't allow any module create the instantion of UI/CORE module classes (as Java offers sealed interface - that means I can choose which class can implement it). That's kind of dependency injection - the needed items will be created in one place and passed as interfaces.
On the other hand - the approach introduces more code - one more module and at least two new interfaces.
Any ideas which one is better in terms of maintenance and conventions?