티스토리 뷰


  • 호출을 캡슐화 한다.
  • 어떤 때 쓰면 좋을까 ? ( 내생각 )
    • 프로그램이 처리 댈 때 매 요청 마다 검증이 필요할때
    • 혹은 요청을 가공할 때
    • 혹은 요청을 되돌리거나, 요청에 대한 기록을 할 때 ..
    • 혹은 요청에 일괄 실행이나 특정 부분까지만 실행 하도록 할때 !




   var employee = function(){};
    employee.prototype = {
        call : function(){
            alert('can i help you?');
        },
        orderup : function() {
            alert('did you choose the menu? ');
        }
    }

    var employeeCall = function(emp) {
        this.employee = emp;
    };

    employeeCall.prototype.execute = function(){
        this.employee.call();
    }

    var orderMenu = function(emp){
        this.employee = emp;
    };

    orderMenu.prototype.execute = function(){
        this.employee.orderup();
    };
    //execute
    //cust

    var outBackCommand = function(){
        this.menu = [];
    };

    outBackCommand.prototype = {
        addCommand : function(menu) {
            this.menu[this.menu.length] = menu;
        },
        runCommand : function(){
            for(var i=0; i< this.menu.length ; i++) {
                this.menu[i].execute();
            }
        }
    };
    // Run. 
    var ob = new outBackCommand();
    var emp = new employee();
    ob.addCommand(new employeeCall(emp));
    ob.addCommand(new orderMenu(emp));
    ob.runCommand();

댓글
D-DAY
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함