Abstract Factory

Definition:


Provide the interface for creating families of related or dependent objects without specifying their concrete classes.


For eg:


function Employee (name){
  
   this.name = name;
   this.say = function (){


                 log.add("I am employee "+ name);


   };
}


function EmployeeFactory(){


    this.create  = function(name){
        return new Employee(name);
    };


}


var log = (function (){

  var log = "";
         return {
             add: function (msg){ log += msg+ "\n"}
             show : function (){console.log(log); log = ""}
   }


})();


function run(){


    var persons = [];
    var EmployeeFactory  = new EmployeeFactory();


   persons.push(Employee.create("Ms Dhoni"));
   persons.push(Employee.create("Sachin"));


   for(var i=0; len = persons.length; i<len ; i++){
  
       persons[i].say();


   }
   log.show();
}




run();

Comments

Popular posts from this blog