diff --git a/chaining/index.html b/chaining/index.html index d5d208f..975b028 100644 --- a/chaining/index.html +++ b/chaining/index.html @@ -1,49 +1,50 @@ -
-- The chaining pattern is an extremely useful way to perform continuous method calls on an object in JavaScript. -
- -- This pattern is widely used in many different libraries and frameworks for JavaScript. -
- - -Starting with a value of 5, Chained methods: add(2), multiply(5), subtract(7) -> Result should be 28
- -{{vm.result}}
-+ The chaining pattern is an extremely useful way to perform continuous method calls on an object in JavaScript. +
+ ++ This pattern is widely used in many different libraries and frameworks for JavaScript. +
+ + + +Starting with a value of 5, Chained methods: add(2), multiply(5), subtract(7) -> Result should be 28
+ +{{vm.result}}
+With the modularity of the pattern, we're able to run N visitors against our data, giving us a lot of future extensibility for our system.
- +
+ + The UML Diagram is above +
diff --git a/visitor/js/controllers.js b/visitor/js/controllers.js index 5950411..1992a85 100644 --- a/visitor/js/controllers.js +++ b/visitor/js/controllers.js @@ -2,51 +2,63 @@ 'use strict'; var Product = function(name, price, discount, sale_price){ - var self = this; + if (this instanceof Product) { + this.accept = function(visitor){ + visitor.visit(this); + }; - this.accept = function(visitor){ - visitor.visit(self); - }; + this.setDiscount = function(dis){ + discount = dis; + }; - this.getName = function(){ - return name; - }; - this.getPrice = function(){ - return price; - } - - this.setDiscount = function(dis){ - discount = dis; - }; + this.getDiscount = function(){ + return discount; + }; - this.getDiscount = function(){ - return discount; - }; + this.getDiscountPercentStr = function(){ + if(discount){ + return (discount * 100) + "%"; + } + } - this.getDiscountPercentStr = function(){ - if(discount){ - return (discount * 100) + "%"; + this.getDiscountAmount = function(){ + if(discount){ + return (price * this.getDiscount()).toFixed(2); + } } - } - this.getDiscountAmount = function(){ - if(discount){ - return (price * self.getDiscount()).toFixed(2); + this.getSalePrice = function(){ + if(discount){ + return (price * (1 - this.getDiscount())).toFixed(2); + } } - } + this.getName = function(){ + return name; + }; - this.getSalePrice = function(){ - if(discount){ - return (price * (1 - self.getDiscount())).toFixed(2); + this.getPrice = function(){ + return price; } + } + else { + return new Product(name,price,discount, sale_price); + } + + } var Discount = function(){ - this.visit = function(prod){ - prod.setDiscount(0.10); + if(this instanceof Discount) { + this.visit = function (prod) { + prod.setDiscount(0.10); + } + } + else { + return new Discount(); } + } var controllerId = "mainCtrl"; diff --git a/visitor/umldiagram.gif b/visitor/umldiagram.gif new file mode 100644 index 0000000..00f369c Binary files /dev/null and b/visitor/umldiagram.gif differ