I'm refactoring some legacy code, and have been stuck in a dilemma.
Some context regarding the code-base. It is a dashboard website to which can be configured to monitor some services. There are two modes in which it can be used.
- Static:
- Configurations for services that need to be monitored are stored in read-only datastores, ex: text, read-only DB.
- Onboarding services is done automatically during start-up
- The hyper-links to Dynamically onboard new services & edit exisiting services is closed off, and the controllers don't load the pages.
- Dynamic:
- Configurations for services that need to be monitored are stored in read-write datastore, ex: SQL, online-data-stores etc.
- Onboarding services is done manually post start-up in onboarding page.
- The hyper-links to Dynamically onboard new services & edit existing services is open and reachable.
I want to refactor the following.
interface Interface {
def getX()
def getY()
}
class StaticImpl implements Interface {
@implement def getX(): some impl
@implement def getY(): some impl
}
class DynamicImpl extends StaticImpl {
def putX(x): some impl ( not in interface )
def putY(y): some impl ( not in interface )
}
@Bean
Interface bean1 = if dynamic: DynamicImpl() else: StaticImpl()
@Bean
DynamicImpl bean2 = DynamicImpl()
bean1 is used for activities which can be called during static and dynamic mode
bean2 is used for activities which is called only during dynamic mode
I have two Ideas for now
- move putX, putY into the interface and keep empty implementation in StaticImpl i.e., they do nothing
- create new interface for putX, putY and make bean2 null during static mode.
I wanted know if these are good, or if there are any other way to refactor this.
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire