3 ms·
Won't `getThingStrategy()` do something like `if PermissionController.get().get(MyPerm.class): doA() else: doB()` ?
by anamexis 6y ago
Won't `getThingStrategy()` do something like `if PermissionController.get().get(MyPerm.class): doA() else: doB()` ?
- rlayton2 6y agoYes, but you move the logic for deciding which branch to take to an underlying function. It pollutes the parent function less, but results in more overall functions for places to hide. Also, if the logic gets more complicated than just an if statement (if Permision... and date < cutoffdate: etc) you don't further pollute the parent function.
- fennecfoxen 6y agoNaah, but at least that would make the decision simple and clear (if condition return doA else return doB). Better would be for whatever ThingFactory or getThingService instantiates the Thing to make the decision, and compute it up front. If-else statements in application logic tangle the concepts of "what should be done and why?" with "let me do this Way 1" and "let me do this Way 2". Ideally a typical service (or model or similar) shouldn't be aware that "feature flags" as a concept exist, and this should be regarded as inimical to their encapsulation. It should just know that it delegates a decision to Way N.
- vanviegen 6y agoThat sounds a lot like enterprisy Java programming. I'm not always thrilled to work with the results of that. :-)