mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-10-14 12:16:46 +00:00
docs: diagrams for transaction script, twin, and type object
This commit is contained in:
1 parent
21914f9c88
commit
6195d5e1e8
6 files changed
+13
-1
No files matched your search
@@ -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
|
||||
|
||||

|
||||
|
||||
## 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 |
Reference in new issue
Block a user