docs: diagrams for transaction script, twin, and type object

This commit is contained in:
Ilkka Seppälä committed 2025-04-12 09:35:40 +03:00
1 parent 21914f9c88
commit 6195d5e1e8
6 files changed
+13 -1

No files matched your search

+4
View File
@@ -31,6 +31,10 @@ Wikipedia says
> The Twin pattern is a software design pattern that allows developers to simulate multiple inheritance in languages that don't support it. Instead of creating a single class inheriting from multiple parents, two closely linked subclasses are created, each inheriting from one of the parents. These subclasses are mutually dependent, working together as a pair to achieve the desired functionality. This approach avoids the complications and inefficiencies often associated with multiple inheritance, while still allowing the reuse of functionalities from different classes.
Sequence diagram
![Twin Pattern Sequence Diagram](./etc/twin-sequence-diagram.png)
## Programmatic Example of Twin Pattern in Java
Consider a game where a ball needs to function as both a `GameItem` and a `Thread`. Instead of inheriting from both, we use the Twin pattern with two closely linked objects: `BallItem` and `BallThread`.
Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB