Design patterns·topic 8 of 10
The shape of the whole application
Zoomed all the way out, an application is a small number of regions and a rule about which way the arrows between them may point. These are the named shapes, and the differences between the ones people use interchangeably.
Read in order · tick what you already know
- 01
someone said three-tier and meant three folders, and someone else heard three machines.
Tier vs layer
- 02
the browser posted to a controller, which changed the model and picked a view, and the view read the model itself.
Model-view-controller
- 03
every request in the application arrives at one handler first, and that is where authentication and routing live.
Front controller
- 04
the view is an interface with setTitle and showError on it, and the presenter is what you actually unit test.
Model-view-presenter
- 05
the class that touches the framework has no logic in it, so the logic is testable without the framework.
Humble object
- 06
there is an object holding the state of the screen — what is selected, what is disabled — and it is not the domain object.
Presentation model
- 07
you changed a property on the viewmodel and the label updated, and no code you wrote connected the two.
Model-view-viewmodel
- 08
typing in the box changed the object and changing the object changed the box, and tracing which caused which was work.
Two-way data binding
- 09
the same use case runs from an HTTP handler, a message consumer and a test, and none of them is the primary one.
Hexagonal architecture
- 10
an import from the domain package to the database package failed the build, and the arrow only ever points inward.
Dependency rule
- 11
the domain model sits in the middle with no dependencies at all, and everything else wraps around it.
Onion architecture
- 12
entities, then use cases, then adapters, then frameworks — and nothing in an inner circle names anything outside it.
Clean architecture
- 13
there is one class per thing a user can do, with one public method, and its name is a verb.
Use case interactor
- 14
one change touched one folder, instead of the same change touching the controllers, services and repositories folders.
Package by feature
- 15
you opened the top-level folder and learned what the system does, rather than which framework it was written in.
Screaming architecture
- 16
someone added a feature by dropping in a package, and you did not change or redeploy the application to allow it.
Plugin architecture
- 17
the product is a small core that does almost nothing, and every feature anyone names is a plugin.
Microkernel architecture
- 18
each stage takes one thing and returns another, knows nothing about its neighbours, and you reordered two of them safely.
Pipes and filters
- 19
several independent components read from and write to one shared workspace, and no one of them owns the answer.
Blackboard pattern