mercredi 8 mars 2017

Javascript interfaces / loose coupling

In programming languages like PHP a lot of concrete implementation are put behind interfaces so it will be a lot easier to swap out concrete implementations since you are programming to an interface and not to a concretion.

In our project we are wanting to implement a date library called moment.js to handle dates for us but there is the concern of being coupled too hard to our code if we implement it in all our javascript.

To create something of an interface in javascript the methods and properties could be wrapped by our own library, this way we can more easily swap out the concrete date library we are using just in case.

I am wondering if there is some kind of pattern or standardized way for this in javascript. At first sight it was about just create a library for ourselves where we would put complex re-usable logic that still uses moment.js under the hood.

If we still use moment.js functionality here and there we are still tightly coupled to it though. If we do implement some kind of pattern where we can only talk to moment.js through an adapter or interface we are stuck implementing wrappers for the entire library which seems absurd.

How do javascript developers deal with this?

Aucun commentaire:

Enregistrer un commentaire