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
- backend stuffUI
- frontend stuff
I can think of two approaches:
APPROACH 1:
CORE
module will exposeEngine
class,UI
will exposeUserInterface
class.UserInterface
will need anEngine
in its constructor. Creation of both objects will take place in the third module calledLAUNCHER
.APPROACH 2:
CORE
module will exposeEngine
class,UI
will exposeUserInterface
class. The difference is both modules with expose those classes ONLY toPRELAUNCHER
module that will create objects and pass them to theLAUNCHER
module 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?