How can I define and implement an interface where one Module is using it for the implementation (lets say the View layer
) and another Module is calling it to get the result from the defined implementation (say the Backend Layer
)?
I want to keep seperation of concerns so that the Backend layer
does not care about how it is implemented, yet the View Layer
must always have an implementation even if there are different implementations of this module.
Say the interface is the following:
interface AreaProcessing{
/**
*
* @param point Pair<Double, Double> the point's <Longitude, Latitude>
* @param areaPointsList ArrayList<Pair<Double, Double>> as of <Longitude, Latitude>
* @return Boolean True, if the given point is inside the area, False otherwise.
*/
fun isPointInsideTheArea(
point: Pair<Double, Double>,
areaPointsList: ArrayList<Pair<Double, Double>>
): Boolean
More specifically, I have a module that is based on the specific implementation of the map engine say GoogleMapModule
. I want this module to implement the specific interface and then in the backend to call it without having any knowledge on the map module or the class that is being implemented within. So if I then decide to use another module, say BingMapModule
all I have to do is implement the interface ONLY in the new module without affecting the backend. Optionally, if there is no implementation for the specific interface then an exception could be thrown.
I am not sure if this doable with interfaces or with abstract class. That is why I am asking here.
I have read the following post here : If I call an interface method, will it get the method body from implementation class and execute?
Thanks in advance.