In my project I have two chunk of code which I would like to separate to make one part a library. Yesterday, when I was trying to separate it I notice that there is a very strong connection between my new library and my application layer which is caused by Enum type. Of course I could simply change that Enum into the primary type of int, or a String and by this enabling myself to define those values within the application layer, but by doing it I would get rid of the type-check mechanism which I would like to have. Is there any other way to achieve it without loosing the type checking mechanism of Java/Android?
And the issue:
Application Layer
Enum Id {…} // how to generalize the type?
Library Layer
SomeClass.someMethod(Id myResource) {…}
Don’t use an enum in your library. Use an interface, that the application will have to implement the way it wants to (by using an enum, for example).
The interface should contain the methods that are needed by the library. Without a more concrete example, it’s hard to provide a more concrete answer.
For example:
And in the application: