zoukankan      html  css  js  c++  java
  • js: abstractFactory

    function Employee(name) {
    	this.name = name;
    	this.say = function() {
    		log.add("I am employee " + name);
    	}
    }
    
    function EmployeeFactory() {
    	this.create = function(name) {
    		return new Employee();
    	}
    }
    
    function Vendor(name) {
    	this.name = name;
    	this.say = function() {
    		log.add("I am vendor " + name);
    	}
    }
    
    function VendorFactory() {
    	this.create = function(name) {
    		return new Vendor(name);
    	}
    }
    
    
    var log = (function() {
    	var log = "";
    	return {
    		add: function(msg) { log += msg + "
    "},
    		show: function() { 
    			console.log(log);
    			log = "";
    		}
    	};
    
    }());
    
    
    function run() {
    	var persons = [];
    	var employeeFactory = new EmployeeFacotry();
    	var vendorFactory = new VendorFactory();
    
    	persons.push(employeeFactory.create("manx"));
    	persons.push(employeeFactory.create("bob"));
    	persons.push(vendorFactory.create("jack"));
    	persons.push(vendorFactory.create("smith"));
    
    	for (obj of persons) {
    		obj.say();
    	}
    
    	log.show();
    
    }
    
    run();
    

      

  • 相关阅读:
    关于开发BugRaid的想法(2)
    杭州.net俱乐部第一次见面会情况
    关于Bug管理的过程
    关于开发BugRaid的想法(1)
    变态的VS2005 SP1
    vs2003 sp1 download url
    proxy software
    敏捷开发
    Enterprise Library文档
    ETL
  • 原文地址:https://www.cnblogs.com/ax-null/p/6804016.html
Copyright © 2011-2022 走看看