mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-08-17 02:23:26 +00:00
docs: add diagrams for decorator, delegation, dependency injection, dirty flag, domain model, double buffer, double-checked locking, double dispatch, and dynamic proxy
This commit is contained in:
@@ -33,6 +33,10 @@ Wikipedia says
|
||||
|
||||
> In software engineering, double dispatch is a special form of multiple dispatch, and a mechanism that dispatches a function call to different concrete functions depending on the runtime types of two objects involved in the call. In most object-oriented systems, the concrete function that is called from a function call in the code depends on the dynamic type of a single object and therefore they are known as single dispatch calls, or simply virtual function calls.
|
||||
|
||||
Sequence diagram
|
||||
|
||||

|
||||
|
||||
## Programmatic Example of Double Dispatch Pattern in Java
|
||||
|
||||
The Double Dispatch pattern in Java is used to handle collisions between different types of game objects. Each game object is an instance of a class that extends the `GameObject` abstract class. The `GameObject` class has a `collision(GameObject)` method, which is overridden in each subclass to define the behavior when a collision occurs with another game object. Here is a simplified version of the `GameObject` class and its subclasses:
|
||||
@@ -113,10 +117,6 @@ Here is the program output:
|
||||
15:47:23.773 [main] INFO com.iluwatar.doubledispatch.App -- SpaceStationIss at [12,12,14,14] damaged=true onFire=false
|
||||
```
|
||||
|
||||
## Detailed Explanation of Double Dispatch Pattern with Real-World Examples
|
||||
|
||||

|
||||
|
||||
## When to Use the Double Dispatch Pattern in Java
|
||||
|
||||
* When the behavior of a method needs to vary not just based on the object it is called on, but also based on the type of the argument.
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 24 KiB |
Reference in New Issue
Block a user