I am about to develop a ASP.NET MVC 4 project that will make use of maps. Our co
ID: 646657 • Letter: I
Question
I am about to develop a ASP.NET MVC 4 project that will make use of maps. Our company has it's own map API which is very basic at the moment, but is intended to be further developed in future to match some specific customer needs. The project will have a mobile/tablet interface in addition to it's web interface and needs to be developed now. So we have planned to start use the Google Maps v3 API.
I would like to encapsulate the API, so our applications don't have Google API specific calls. The same approach as if I would like to use som external API i C# and wanted to encapsulate it in order to be able to switch API in future without having to re-code the entire application.
But I haven't been able to find similar examples, so the following questions arise:
Is it a good and reasonable approach? Let me hear your pros and cons.
How would it be done in practice?
Explanation / Answer
Is it a good and reasonable approach? Let me hear your pros and cons.
Typically, I would advise against preemptively encapsulating a library or API - it's usually a bad case of YAGNI, as it complicates your design for dubious gains. Most of the time what happens is that the wrapper ends up being tied too closely to what it's encapsulating, so that even when you actually do end up switching to some other library or API, you have to change all the client code because the new one is too different and matches very badly to your wrapper.
In this case, it might be defendable as you have relatively concrete plans of switching the underlying API and already a second implementation, albeit an incomplete one. If you do it, I would very much recommend looking closely at at least one other complete map API (like Bing Maps) to ensure your API could work with it.
How would it be done in practice?
The best approach is probably indeed a facade: don't try to write a wrapper that exposes all the functionality of Google Maps. Instead, create an interface that contains only the map-related functionality your application needs and thus represents an abstraction layer. It will probably aggregate calls as well as translating them and contain some logic of its own.
Your chances of porting it to a different map provider without having to change the application code are much better than with a thin, fully-featured wrapper.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.