Skip to content

Return a singleton instead of null when trying to create multiple factories #150

@xico42

Description

@xico42

The current code returns null when a factory was already instantiated. I can see some major problems with this approach:

  1. It is not intuitive for the developer
  2. This violates the method contract as specified in the @return docblock annotation tag. The annotation specifies that the return type is an instance of SplitFactoryInterface

My suggestion would be: Instead of tracking the instantiation of the factories by using a flag (KEY_FACTORY_TRACKER) we would keep a reference to the instantiated object in the container, so that whenever an user of the SDK tries to create multiple factories, we simply return the last created factory

Another approach would be to create a new static method called singleton to make this behavior more explicit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions