콘웨이 법칙
시스템을 설계하는 조직은 필연적으로 해당 조직의 커뮤니케이션 구조를 복제한 설계물을 만들게 된다
단일 모듈은 변경의 이유가 하나, 오직 하나뿐이어야 한다.
하나의 모듈은 하나의, 오직 하나의 사용자 또는 이해관계자에 대해서만 책임져야 한다.
하나의 모듈은 하나의, 오직 하나의 액터에 대해서만 책임져야 한다.
class Employee {
// 회계팀, CFO 보고용
calculatePay(){
...
regularHours();
...
}
// 인사팀, COO 보고용
reportHours(){
...
regularHours();
...
}
// DBA, CTO 보고용
save(){
}
}
class Employee {
constructor({name, duty}){
this.name=name;
this.duty=duty; //duty의 타입이 string->int(type)
}
// 회계팀, CFO 보고용
calculatePay(){
}
// 인사팀, COO 보고용
reportHours(){
//수정
}
// DBA, CTO 보고용
save(){
//수정
}
}
class PayCalculator {
constructor({employee}){
this.employee=new EmployeeData(employee);
}
}
class HourReporter {
constructor({employee}){
this.employee=new EmployeeData(employee);
}
}
class EmployeeSaver {
constructor({employee}){
this.employee=new EmployeeData(employee);
}
}
class EmployeeData(){
constructor({name, duty}){
this.name=name;
this.duty=duty;
}
}
/* Complex parts */
class CPU {
public void freeze() { ... }
public void jump(long position) { ... }
public void execute() { ... }
}
class Memory {
public void load(long position, byte[] data) {
...
}
}
class HardDrive {
public byte[] read(long lba, int size) {
...
}
}
/* Façade */
class Computer {
public void startComputer() {
CPU cpu = new CPU();
Memory memory = new Memory();
HardDrive hardDrive = new HardDrive();
cpu.freeze();
memory.load(BOOT_ADDRESS, hardDrive.read(BOOT_SECTOR, SECTOR_SIZE));
cpu.jump(BOOT_ADDRESS);
cpu.execute();
}
}
/* Client */
class You {
public static void main(String[] args) throws ParseException {
Computer facade = /* grab a facade instance */;
facade.startComputer();
}
}