I am working on a C# based application in which I have a utility interface with an internal back end that creates some objects and registers them internally in the application.
So the code looks like the following:
public interface Utility {
public SomeObject CreateSomeObject(String id);
}
Only the Utility interface is visible outside my assembly, the concrete back end class is internal.
I am really stuck on finding a proper name for the creation methods which should tell the user that the wanted object will be created and registered.
Any suggestions?
EDIT I already thought about naming my methods CreateAndRegisterSomeObject() but some objects have really long names which makes some method names very very long
Thanks in advance,
I don’t really like the idea that your method is doing so much ie both create and register, but if it must then I would approach it by using generics most likely.
This would allow you to cater for multiple classes that have the same construction pattern without putting verbose plumbing code, ie having to create methods containing the name of every single object you need to create and register. Let the generics do the heavy lifting for you.
Your objects would have to implement some interfaces such as
Then you would could implement your Utility class in something along the following lines:
A different approach
I would also like to point out the pattern you are trying to use
CreateAndRegisteris a problem already solved slightly differently with Inversion of Control frameworks (e.g. ninject, unity amongst others)They allow you to register and associate a given type to a lifetime that the object has. If you want to register types as singletons for example, the IoC framework can do that for you, then when you Resolve you will get an instance of the type you want respecting the lifetime that it has been configured to. You could want for example, a new instance when every time you resolve the type, or a only a new instance per thread, or to have the same instance always returned when you resolve.
In any case, good luck!