[CONTROLLER-1390] The config module API does not make it clear what exactly needs to be returned by createInstance Created: 09/Jul/15  Updated: 19/Oct/17  Resolved: 05/Jul/17

Status: Resolved
Project: controller
Component/s: config
Affects Version/s: Lithium
Fix Version/s: None

Type: Bug
Reporter: Moiz Raja Assignee: Unassigned
Resolution: Won't Do Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Operating System: All
Platform: All


External issue ID: 3975

 Description   

The current API for createInstance is as follows,

java.lang.AutoCloseable createInstance();

The problem with this is that when a module provides services a developer may not return an appropriate implementation of the services it provides. The error can then only be detected at runtime.

One suggestion from rovarga is to change the API as follows,

<T extends InterfaceA & InterfaceB & AutoClosable> T createInstance();

which forces the developer to return an appropriate implementation.

This also clarifies how exactly a module is supposed to provide multiple services.



 Comments   
Comment by Moiz Raja [ 09/Jul/15 ]

Another one of my confusion stems from the fact that createInstance on the module actually is supposed to return an implementation of a service.

A simplification could be on the following lines.

interface ModuleX extends AutoCloseable {
FooService createFooService();
BarService createBarService();
}

class XModule extends AbstractXModule {

@Override
public ModuleX createInstance()

{ return new ModuleXImpl(); }

}

(or)

class ModuleXImpl implements ModuleX extends AbstractXModule {
@Override
public ModuleX createInstance()

{ return this; }

@Override
public FooService createFooService()

{ ... }

@Override
public BarService createBarService(){ ... }

}

Comment by Tom Pantelis [ 05/Jul/17 ]

The CSS is being deprecated so not worth addressing.

Generated at Wed Feb 07 19:55:25 UTC 2024 using Jira 8.20.10#820010-sha1:ace47f9899e9ee25d7157d59aa17ab06aee30d3d.