0

I have an abstract class that's following the singleton pattern, then I have a few concrete classes that extend it:

UML Diagram

At startup, based on the current system, I'm setting a concrete instance as the instance of the singleton like this:

LicenseFactory.setInstance(new SystemALicenseFactory())

With that, at any point in the code, I can consume the abstract method like this: LicenseFactory.getInstance().isUserValid()

Because my concrete classes aren't creating a product, I'm not sure whether I can call this the Abstract Factory pattern or something else. Is it common to use a pattern like this, and is there anything I should have done better?

2
  • LicenseFactory is a Service Locator.
    – jaco0646
    Commented Mar 15, 2022 at 15:34
  • 1
    @jaco0646 thank you for the Service Locator link. I realise that I'm having the same design problem as the article suggests, and I've decided to replace this with dependency injection instead.
    – jackson915
    Commented Mar 30, 2022 at 0:19

0