Clean Architecture & Design Patterns in Practice · 강의

겸손한 객체와 뷰의 경계

겸손한 객체 패턴을 적용하여 뷰 코드를 간결하고 테스트 가능하게 유지하고, 모든 결정을 프레젠테이션 경계의 테스트 가능한 프레젠터로 옮기세요.

레슨 4/413개 단계

겸손한 객체와 뷰의 경계은(는) CoddyKit의 무료 Clean Architecture & Design Patterns in Practice 강의입니다. 이것은 4개 중 4번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Clean Architecture & Design Patterns in Practice 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Clean Architecture & Design Patterns in Practice 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

The Hardest Code to Test

UI code is notoriously hard to test: it touches frameworks, screens, and event loops.

The Humble Object pattern solves this by splitting behavior so that the hard-to-test part becomes humble — nearly logic-free.

The Pattern in One Idea

Separate code into two parts across a boundary:

  • A humble part: thin, dumb, hard to test (the view).
  • A testable part: holds all the logic (the presenter).

Almost all behavior moves to the testable side.

Applying It to the View

The view becomes humble: it only displays already-formatted data and forwards user events.

It contains no formatting decisions, no conditionals about what to show — just assignment of fields to widgets.

The View Interface

Define what the presenter can ask the view to display.

interface OrderView {
    void showTotal(String formattedTotal);
    void showError(String message);
}

The Testable Presenter

The presenter does all the work and pushes finished strings to the humble view.

class OrderPresenter {
    private final OrderView view;
    OrderPresenter(OrderView view) { this.view = view; }
    void present(double total) {
        if (total < 0) { view.showError("Invalid total"); return; }
        view.showTotal("$" + String.format("%.2f", total));
    }
}

Why This Is Testable

Because the presenter talks to a view interface, a test supplies a fake view and asserts what was shown — no framework required.

class FakeView implements OrderView {
    String shown;
    public void showTotal(String t) { shown = t; }
    public void showError(String m) { shown = m; }
}

A Runnable Example

The presenter formats; the humble view simply records what it was told.

public class Main {
  interface View { void show(String s); }
  static class Presenter {
    final View v;
    Presenter(View v){ this.v=v; }
    void present(double total){ v.show(total<0 ? "Invalid" : "$"+String.format("%.2f", total)); }
  }
  static class FakeView implements View { String last; public void show(String s){ last=s; } }
  public static void main(String[] a){
    FakeView fv = new FakeView();
    new Presenter(fv).present(12.5);
    System.out.println("View shows: " + fv.last);
  }
}

The Boundary Is the Key

The humble object pattern always centers on a boundary interface. Logic lives on the testable side of that boundary; the framework lives on the humble side.

This is exactly how Clean Architecture keeps frameworks at arm length.

Where Else It Applies

  • Database access: a humble gateway, testable logic above it.
  • Hardware or sensors: humble drivers, testable controllers.
  • Web handlers: humble controllers delegating to interactors.

Anywhere the framework boundary is hard to test.

Keeping the View Truly Humble

Resist sneaking logic back into the view. The moment a view starts deciding what to format or whether to show something, it stops being humble and becomes untestable again.

Guidelines

  • Define a view interface the presenter drives.
  • Put all formatting and branching in the presenter.
  • Let the view only assign values and emit events.
  • Test the presenter with a fake view.

Quick Check

Test your understanding of the Humble Object pattern.

Recap

You learned the Humble Object pattern for the view boundary.

  • Split into a humble view and a testable presenter.
  • All logic lives on the testable side of a boundary interface.
  • This keeps frameworks out of your tests and your core.
무료로 시작

AI 튜터와 함께 Clean Architecture & Design Patterns in Practice을(를) 배우세요 — 무료

브라우저에서 실제 코드를 작성하고 실행하며, 24/7 AI 튜터로부터 즉각적인 도움을 받고, 웹이나 앱에서 중단한 부분부터 계속 학습하세요.

코스
12
레슨
48

자주 묻는 질문

“겸손한 객체와 뷰의 경계” 강의는 무료인가요?

네 — “겸손한 객체와 뷰의 경계” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Clean Architecture & Design Patterns in Practice 강의 전체를 잠금 해제할 수 있습니다. Clean Architecture & Design Patterns in Practice 강의에는 총 4개의 강의가 포함되어 있습니다.

“겸손한 객체와 뷰의 경계”에서 뭘 배우나요?

겸손한 객체 패턴을 적용하여 뷰 코드를 간결하고 테스트 가능하게 유지하고, 모든 결정을 프레젠테이션 경계의 테스트 가능한 프레젠터로 옮기세요. 브라우저에서 직접 실행하는 실습 코드로 Clean Architecture & Design Patterns in Practice을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Clean Architecture & Design Patterns in Practice을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Clean Architecture & Design Patterns in Practice은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 4번째 강의입니다.

“겸손한 객체와 뷰의 경계” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Clean Architecture & Design Patterns in Practice 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Clean Architecture & Design Patterns in Practice 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 프레젠터와 뷰 모델
  2. 웹 프레임워크에 적용하기
  3. 프레젠테이션 계층 테스트
  4. 겸손한 객체와 뷰의 경계
← Clean Architecture & Design Patterns in Practice(으)로 돌아가기