docs: add diagrams for event aggregator, event-based asynchronous, event queue, execute around, extension objects

This commit is contained in:
Ilkka Seppälä
2025-04-06 18:36:32 +03:00
parent 30d13083ae
commit aef4b37c9a
10 changed files with 20 additions and 8 deletions
+4 -4
View File
@@ -36,6 +36,10 @@ In Plain Words
> Event Aggregator is a design pattern that allows multiple event sources to communicate with event handlers through a central point, rather than having each event source communicate directly with each handler.
Sequence diagram
![Event Aggregator sequence diagram](./etc/event-aggregator-sequence-diagram.png)
## Programmatic Example of Event Aggregator Pattern in Java
Consider the following example where we use the Event Aggregator to handle multiple events.
@@ -161,10 +165,6 @@ The console output after running the example.
21:37:38.739 [main] INFO com.iluwatar.event.aggregator.KingJoffrey -- Received event from the King's Hand: Traitor detected
```
## Detailed Explanation of Event Aggregator Pattern with Real-World Examples
![Event Aggregator](./etc/classes.png "Event Aggregator")
## When to Use the Event Aggregator Pattern in Java
Use the Event Aggregator pattern when
Binary file not shown.

After

Width:  |  Height:  |  Size: 31 KiB

+4
View File
@@ -32,6 +32,10 @@ In Plain Words
> The Event-Based Asynchronous design pattern allows tasks to be executed in the background, notifying the main program via events when completed, thereby enhancing system efficiency and responsiveness without blocking ongoing operations.
Sequence diagram
![Event-Based Asynchronous sequence diagram](./etc/event-based-asynchronous-sequence-diagram.png)
## Programmatic Example of Event-Based Asynchronous Pattern in Java
Event-Based Asynchronous design pattern allows tasks to be executed in the background, notifying the main program via events when completed, thereby enhancing system efficiency and responsiveness without blocking ongoing operations.
Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

+4
View File
@@ -35,6 +35,10 @@ Wikipedia says
> Message queues (also known as event queues) implement an asynchronous communication pattern between two or more processes/threads whereby the sending and receiving party do not need to interact with the queue at the same time.
Sequence diagram
![Event Queue sequence diagram](./etc/event-queue-sequence-diagram.png)
## Programmatic Example of Event Queue Pattern in Java
This example demonstrates an application using an event queue system to handle audio playback asynchronously.
Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

+4
View File
@@ -39,6 +39,10 @@ In plain words
> Basically it's the pattern where you write a method to do things which are always required, e.g. resource allocation and clean-up, and make the caller pass in "what we want to do with the resource".
Flowchart
![Execute Around flowchart](./etc/execute-around-flowchart.png)
## Programmatic Example of Execute Around Pattern in Java
The Execute Around Pattern is a design pattern that is widely used in Java programming to manage resource allocation and deallocation. It ensures that important setup and cleanup operations are performed reliably around a core business operation. This pattern is particularly useful for resource management, such as handling files, databases, or network connections in Java applications.
Binary file not shown.

After

Width:  |  Height:  |  Size: 27 KiB

+4 -4
View File
@@ -33,6 +33,10 @@ Wikipedia says
> In object-oriented computer programming, an extension objects pattern is a design pattern added to an object after the original object was compiled. The modified object is often a class, a prototype or a type. Extension object patterns are features of some object-oriented programming languages. There is no syntactic difference between calling an extension method and calling a method declared in the type definition.
Sequence diagram
![Extension Objects sequence diagram](./etc/extension-objects-sequence-diagram.png)
## Programmatic Example of Extension Objects Pattern in Java
The Extension Objects pattern allows for the flexible extension of an object's behavior without modifying its structure, by attaching additional objects that can dynamically add new functionality.
@@ -143,10 +147,6 @@ This produces the following console output.
This example demonstrates how the Extension Objects pattern allows for the flexible extension of an object's behavior without modifying its structure.
## Detailed Explanation of Extension Objects Pattern with Real-World Examples
![Extension_objects](./etc/extension_obj.png "Extension objects")
## When to Use the Extension Objects Pattern in Java
This pattern is applicable in scenarios where an object's functionality needs to be extended at runtime, avoiding the complications of subclassing. It's particularly useful in systems where object capabilities need to be augmented post-deployment, or where the capabilities might vary significantly across instances.
Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB