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

This commit is contained in:
Ilkka Seppälä
2025-04-12 09:35:40 +03:00
parent 21914f9c88
commit 6195d5e1e8
6 changed files with 13 additions and 1 deletions
+4
View File
@@ -34,6 +34,10 @@ Wikipedia says
> The Transaction Script design pattern is a straightforward way to organize business logic in applications, particularly suitable for scenarios where each request from the presentation layer can be handled by a single procedure. This pattern is often used in simple applications or in systems where rapid development and ease of understanding are crucial. Each transaction script is responsible for a particular task, such as processing an order or calculating a result, and typically interacts directly with the database.
Flowchart
![Transaction Script Pattern Flowchart](./etc/transaction-script-flowchart.png)
## Programmatic Example of Transaction Script Pattern in Java
Our Transaction Script pattern in Java example is about booking hotel rooms.
Binary file not shown.

After

Width:  |  Height:  |  Size: 60 KiB

+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

+5 -1
View File
@@ -32,12 +32,16 @@ Real-world example
In plain words
> Explore how the Java Type Object pattern enables dynamic creation and management of flexible and extensible sets of related classes, ideal for Java developers seeking modularity without modifying existing codebase.
> Type Object pattern enables dynamic creation and management of flexible and extensible sets of related classes, ideal for Java developers seeking modularity without modifying existing codebase.
gameprogrammingpatterns.com says
> Define a type object class and a typed object class. Each type object instance represents a different logical type. Each typed object stores a reference to the type object that describes its type.
Flowchart
![Type Object Pattern Flowchart](./etc/type-object-flowchart.png)
## Programmatic Example of Type Object Pattern in Java
The Type Object pattern is a design pattern that allows for the creation of flexible and reusable objects by creating a class with a field that represents the 'type' of the object. This design pattern proves invaluable for scenarios where anticipated Java types are undefined upfront, or when modifications or additions are required, ensuring efficient Java development without frequent recompilations.
Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB