Obsługa logiki biznesowej
Logika biznesowa często rozlewa się po dużych klasach, wymieszana z obsługą stanu i kodem bazy danych. Trudno wtedy zobaczyć, jakie decyzje podejmuje kod, a jeszcze trudniej go przetestować. Nauczysz się innego podejścia: możliwe stany i żądania opisujesz jawnymi typami, a każdą decyzję zapisujesz jako małą funkcję, która przyjmuje żądanie i bieżący stan, a zwraca to, co się wydarzyło.
Wiele przykładów korzysta z tego samego koszyka zakupowego, więc łatwo porównać style. Zacznij od pierwszego artykułu: krok po kroku odchudza klasyczny agregat, czyli klasę trzymającą razem dane i reguły. Pozostałe dotyczą tego, co zrobić, gdy to samo żądanie przyjdzie dwa razy, jak zapisać dwie powiązane zmiany w jednej transakcji, jak walidować dane wejściowe i jak zgłaszać niepowodzenia: rzucić wyjątek, zwrócić błąd czy zapisać je jako fakt.
Kod jest w C#, F#, Javie i TypeScripcie. Wybierz swój język, idee przenoszą się na pozostałe.

Slim your aggregates with Event Sourcing!
2022-08-31In the traditional approach, what we get is what we store. Our write model is too often used directly as our read model, because the typical set of functionality in a…
How to effectively compose your business logic
2022-07-20Let’s say that we’d like to implement Shopping Cart. We have the following requirements: The customer may only add a product to the shopping cart after opening it. When…
Idempotent Command Handling
2024-11-15“Is your command handling idempotent?” Sounds like a douchebag question to ask. Actually, that’s not a question but a statement that we want to sound smart. Maybe a…
How to handle multiple commands in the same transaction
2023-03-12Let’s say that we’re starting a new project. It’s a small tool for internal needs, maybe even some sort of shadow IT project. It may also be the project that won’t have…
This is not your uncle's Java! Modelling with Java 22 records pattern matching in practice
2024-05-04I like learning new things. It stimulates my creativity, helps me gain diverse perspectives, and helps me be humble. When you’re a notorious debutant, you learn to…
How events can help in making the state-based approach efficient
2022-11-13In my last few articles, I showed the power of functional composition. That’s a foundation for effective modelling of your business logic. It allows for having more…
Prototyping, an underestimated design skill
2023-08-25Coding is an underestimated part of the design. When we think about the design, we immediately fall to whiteboard diagrams, sticky notes, or endless discussions. That’s…
Throw, Result, or neither?
2026-07-20There is one question I keep getting about my event-sourced code: why don’t I use ? It usually comes after someone sees a decision throwing an exception. They would put…
My journey from Aggregates to Functional Composition
2023-09-08I was recently asked what drove me to mostly use immutable data and methods rather than the Aggregate Pattern in my samples and videos. I decided that it might be worth…
Union types in C#
2022-07-27In the article “How to effectively compose your business logic”, I explained how explicit types definition can help in making our codebase closer to the business domain…
Writing and testing business logic in F#
2022-10-23My road to functional programming was pretty long. I started with structural programming in C++ and then rebranded into an Object-Oriented approach with Java and C#. At…
How to validate business logic
2023-01-15Fox Mulder got advice: “trust no one”. I’m claiming that each software developer should define their level of paranoia. The thing that we should never trust is the…