Skip to main content

Mediator 중재자


Mediator

객체들 간의 의사소통을 하나 이상의 중재자들이 중재한다.

구성은
Mediator <-> Colleague


예를 들어, 어떤 폼에 버튼과 텍스트 박스가 있을 경우,
버튼이 직접 텍스트 박스를 접근하지 않고, 폼에 작업 요청을 하는 것이다. 버튼에 이벤트가 발생하면, 이를 폼에 전달하여, 폼에서 처리하도록 하는 것이다.


각 객체의 상태에 따라 서로의 상태를 바꾸게 되는데 이 작업을 각 객체들이 대상 객체를 직접 참조하여 상태를 파악하거나 상태를 변경되게 되면, 밀결합이 된다. 그리고 소스 코드가 아주 복잡해지고, 수정 작업이 매우 까다로워진다. 달리 말해, 일부 기능 수정에 따른 타 기능 영향(side effect)이 급격하게 증가하게 된다. 당연히 유지보수 비용은 늘어난다.

이 때, 중재자라는 놈을 이들 사이에 주입한다.
그리고 이들 간의 요청을 중재자에 요청을 하고, 중재자는 모든 객체의 상태를 알아내어서, 조치를 취한다.

구현 방법
1. 관련 colleague들이 하나의 mediator와만 동작한다면, mediator인터페이스는 필요없다.

2. 감시자 패턴을 이용하여, 구현할 수 있다.
  colleague에서 상태 변화가 일어날 시, 이를 중재자에 통보하고, 중재자는 처리 방법에 따라 다른 colleague에 이 변경을 전달한다.

3. mediaor 클래스 내에 특화된 통지(notification) 인터페이스를 정의하여, colleague 들이 직접 서로 통신(위임 방식)하게 할 수 있다.

Comments

Popular posts from this blog

Linux Resources Monitoring

dstat Requirements:python Dstat is a versatile replacement for iostat, vmstat and ifstat http://linux.softpedia.com/get/System/Diagnostics/Dstat-1401.shtml  - download the source file  - tar -xvjf dstate-0.7.2.tar.bz2  - cd dstate-0.7.2  - sudo make install 사용법 dstat -cdngys --top-io-adv --top-bio-adv 창넓이가 크면 dstat -cdngys --top-io --top-bio dstat 기본옵션은 -cdngy 2. pktstat requirements: libpcap-devel, ncurses-devel pktstat man page 사용법:sudo pktstat -i eth0 -T -l 실행결과 interface: eth0    total: 43.9Mb (3s) cur: 12.3M (78%) min: 12.3M max: 15.8M avg: 14.5M bps    bps    %      b desc   1.4k   0%   4.3k arp  591.8   0%   1.2k ip proto 88 55.101.66.3 <-> igrp-routers  91.3k   0%  91.3k tcp a100236:4478 <-> console:ssh  42.6k   0% 216.4k tcp a100390:mailprox <-> console:ssh   1.1k   0%   ...

nginx로 다중 포트 설정 및 다중 react app 설정

nginx에 다중 포트 설정하기 react로 여러 webapp를 개발하고, 동일한 서버에 실행시킬 필요가 있다. 이때 간단히 nginx에서 다중포트로 여러 webapp를 동일한 서버에서 실행시킬 수 있다. /etc/nginx/sites-available/에 default 파일이 있다. 보통 port 80로 설정되어 있다. 이 파일을 복사해서 sub로 명명한다.   아래와 같이 포트 8080으로 정하고, react app를 build한 디렉터리를 root <dir>로 지정하고, $> sudo service nginx restart 하면 된다. $>sudo systemctl status nginx.service 로 nginx 상태 확인이 가능하면, $> netstat -ano | grep 8080 으로 8080 포트가 살아있는 또는 외부PC에서  $>telnet ip 8080으로 telnet 접속이 되는지 확인하면 된다. 종종 Nginx 500 Interval Server Error가 발생하는데, 이는 1) root <dir>에서 <dir> 주소가 정확하지 않거나, 2) 파일 권한이 없거나이다. chmod 755 <dir>하면 대부분 해결될 것이다. 그럼 오늘도 유익한 하루 되시길..   

SQLITE Result Codes

#define SQLITE_OK 0 /* Successful result */ /* beginning-of-error-codes */ #define SQLITE_ERROR 1 /* SQL error or missing database */ #define SQLITE_INTERNAL 2 /* Internal logic error in SQLite */ #define SQLITE_PERM 3 /* Access permission denied */ #define SQLITE_ABORT 4 /* Callback routine requested an abort */ #define SQLITE_BUSY 5 /* The database file is locked */ #define SQLITE_LOCKED 6 /* A table in the database is locked */ #define SQLITE_NOMEM 7 /* A malloc() failed */ #define SQLITE_READONLY 8 /* Attempt to write a readonly database */ #define SQLITE_INTERRUPT 9 /* Operation terminated by sqlite3_interrupt()*/ #define SQLITE_IOERR 10 /* Some kind of disk I/O error occurred */ #define SQLITE_CORRUPT 11 /* The database disk image is malformed */ #define SQLITE_NOTFOUND 12 /* NOT USED. Table or record not found */ #define SQLITE_FULL 13 /* Insertion failed because data...