Skip to content

Design Pattern

nuvolo-Ankit edited this page Oct 5, 2018 · 1 revision

Mutating JSON structure (Design pattern)

Bad Design

# viewhelper.js

mr_init.appId = $state.params.appId;
mr_init.viewId = $state.params.viewId;

Standard Design pattern

# ms.js

MobiusRecord.prototype.setAppId = function (v) { ... }
MobiusRecord.prototype.setViewId = function (v) { ... }


# viewhelper.js 

mr_init.setAppId($state.params.appId);
mr_init.setViewId($state.params.viewId);
  • Instead of mutating object, prepare proper Getter and Setter.
  • It will help us to maintain a formatted and organised data structure throughout the app
  • Also helps us to maintain data abstraction and none of class would be able to know keys name.
  • It's easy to handle filed while doing mutation via following approach

Clone this wiki locally