Skip to main content
2 of 3
deleted 17 characters in body

Design of a modular application

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:

  1. CORE - backend stuff
  2. 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. Creation 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.

MY THOUGHTS:

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?