MVC - Model View Controller
- 모델 : 데이터 및 비즈니스 로직
- View : 사용자에게 데이터 표시
- 컨트롤러 : 사용자 입력을 처리하고 모델을 업데이트하며 뷰와 상호 작용
// Model
class Task {
constructor(description) {
this.description = description;
this.completed = false;
}
}
// View
function renderTask(task) {
console.log(`${task.description} - ${task.completed ? 'Completed' : 'Not Completed'}`);
}
// Controller
class TaskController {
constructor(task, view) {
this.task = task;
this.view = view;
}
completeTask() {
this.task.completed = true;
this.view.render(this.task);
}
}
// Usage
const task = new Task('Complete JavaScript Example');
const view = { render : renderTask };
const controller = new TaskController(task, view);
controller.completeTask();