Every day a couple of new javascript modules are created and published around the world and we need to think long term. Let's say today I need to use an ORM module to go smooth and fast. But tomorrow I may face a deprecated module or may find a better one to switch or even may need to create my own.
For example, the team have decided to use Sequelizejs
on top of the Sqlite to provide the models:
const User = sequelize.define('user', {
username: Sequelize.STRING
});
User.create({
username: 'melbourne'
});
Then, a new type of database like Realm
was introduced and they planned to switch:
class User {}
User.schema = {
name: 'User',
properties: {
username: {type: 'string'}
}
};
let realm = new Realm({schema: [User]});
realm.write(() => {
realm.create('User', {
username: 'melbourne'
});
});
So, this can lead to refactoring the entire application and the team needs an interface to present in front and ignore code rewriting. As a result, switching will be easy and changing the bindings will not affect the entire code.
class User {
//...
define(name, dataTypes) {
ThirdParty.define(name, dataTypes);
}
create(data) {
ThirdParty.create(data);
}
//...
}
Regarding the example, what would be the good design pattern in javascript? How to bind an interface on top of third-party modules to develop the future-proofed and scalable apps?