feat: reorganize workbook into 3 tracks (core, engineering-2026, ecosystems)
This commit is contained in:
1 parent
82677455b2
commit
2e002b6176
64 files changed
+2295
-196
No files matched your search
@@ -0,0 +1,18 @@
|
||||
# 09 — Idiomatyczne Wzorce Projektowe w Ruście
|
||||
|
||||
Zamiast kopiować 1:1 wzorce z Javy/C++, Rust promuje wzorce wykorzystujące system typów i ownership:
|
||||
* **Newtype** — osobny typ dla identyfikatorów (zapobiega pomyleniu `UserId` z `OrderId`).
|
||||
* **Builder** — bezpieczna konstrukcja obiektów z wieloma opcjami.
|
||||
* **Typestate** — stany obiektu wymuszane na etapie kompilacji (`Draft` -> `Published`).
|
||||
* **Strategy** — wstrzykiwanie zachowania przez trait.
|
||||
|
||||
## Zadania (`src/lib.rs`)
|
||||
1. `UserId(u64)` i `OrderId(u64)` — wzorzec Newtype.
|
||||
2. `HttpRequestBuilder` — wzorzec Builder z metodami łańcuchowymi (`method`, `header`, `build`).
|
||||
3. `Document<Draft>` -> `publish()` -> `Document<Published>` — wzorzec Typestate (`PhantomData`).
|
||||
4. `DiscountStrategy` + `PercentageDiscount` + `apply_discount` — wzorzec Strategy.
|
||||
|
||||
## Uruchomienie testów
|
||||
```bash
|
||||
make test PKG=core09-design-patterns
|
||||
```
|
||||
Reference in new issue
Block a user