Mütevazı Nesneler ve Görünüm Sınırı
Görünüm kodunu yalın ve test edilebilir tutmak için Mütevazı Nesne desenini uygulayın; tüm kararları sunum sınırındaki test edilebilir sunuculara taşıyın.
Mütevazı Nesneler ve Görünüm Sınırı, CoddyKit'te ücretsiz bir Clean Architecture & Design Patterns in Practice dersidir. Bu, 4 dersinin 4. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Clean Architecture & Design Patterns in Practice öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Clean Architecture & Design Patterns in Practice kursu toplamda 4 dersten oluşur.
Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.
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.
Sıkça Sorulan Sorular
“Mütevazı Nesneler ve Görünüm Sınırı” dersi ücretsiz mi?
Evet — “Mütevazı Nesneler ve Görünüm Sınırı” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Clean Architecture & Design Patterns in Practice kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Clean Architecture & Design Patterns in Practice kursu toplamda 4 dersten oluşur.
“Mütevazı Nesneler ve Görünüm Sınırı” dersinde ne öğreneceğim?
Görünüm kodunu yalın ve test edilebilir tutmak için Mütevazı Nesne desenini uygulayın; tüm kararları sunum sınırındaki test edilebilir sunuculara taşıyın. Clean Architecture & Design Patterns in Practice ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.
Clean Architecture & Design Patterns in Practice öğrenmeye başlamak için deneyim gerekli mi?
Önceden deneyim gerekmez. CoddyKit'te Clean Architecture & Design Patterns in Practice, başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 4. dersidir.
“Mütevazı Nesneler ve Görünüm Sınırı” dersi ne kadar sürer?
Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.
Bu Clean Architecture & Design Patterns in Practice dersinde kod yazıp çalıştırabilir miyim?
Evet. Her Clean Architecture & Design Patterns in Practice dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.
Bu kursun tüm dersleri
- Sunumlayıcılar ve Görünüm Modelleri
- Web Çerçevelerine Uyum Sağlama
- Sunum Katmanını Sınama
- Mütevazı Nesneler ve Görünüm Sınırı