{ } // new method with slightly modified behavior // no need for synchronising with changes to existing usages export function doSomethingV2(arg1, arg2, arg3) { // duplicated logic and tests (or not) } app.get('/doSomething', doSomething) // publish a new route with a new name app.get('/doSomethingV2', doSomethingV2) Modification non compatible? => créer nouvelle méthode temporairement Et pourquoi pas au niveau public ici REST Quand plus personne utilise l’ancienne version, supprimer
usage class WelcomeEmailer { sendWelcomeEmail(email, name) { checkEmailNotSentAlreadyTo(email) // specific to current lib let emailContent = "to: " + email + "\n\n" + "Hi " + name + "\n\n" + "welcome to our new platform!" // specific to current lib send(emailContent) logger.log("email sent to " + email) } } // existing lib export function send(emailContent: string) { } Déplacer le code spécifique vers un nouvel objet EmailAdapter // new lib export function sendEmail(to, from, content: string) { }
sendWelcomeEmail(email) { checkEmailNotSentAlreadyTo(email) let content = "Hi " + name + "\n" + "\n" + "welcome to our new platform!" this.emailAdapter.send(email, content) logger.log("email sent to " + email) } } Injecter la strategie d’EmailAdapter voulue
ifs class SomethingMoreComplex { constructor(private newFeature) {} youNameIt(arg1) { if (this.newFeature) { doNewThing_1() } // logic ... if (this.newFeature) { doNewThing_2() } // logic... } } // approach using branch by abstraction class SomethingMoreComplexInjection { // instead of injecting the feature flag, inject the strategy/command object constructor(private strategy: ICoolFeature) {} youNameIt(arg1) { this.strategy.doNewThing_1() // logic ... this.strategy.doNewThing_2() // logic... } } // booting the application : only one if necessary let coolFeature = newFeature? new CoolFeature() : new OldFeature() const toto = new SomethingMoreComplexInjection(coolFeature) Use branch by abstraction
non bloquant 2. Nouveau code gérant les deux modes avec le feature flag OFF 3. Script de remplissage du delta bloquant + feature flag ON 4. Suppression ancien code + feature flag (+ colonne / table?) En plusieurs étapes …. Si vraiment on a besoin d’une haute dispo