docs: builder, business-delegate, bytecode, caching, callback, chain diagrams

This commit is contained in:
Ilkka Seppälä
2025-04-06 09:00:19 +03:00
parent 25f7bc6fea
commit d5a46be3c5
12 changed files with 25 additions and 12 deletions
+4 -4
View File
@@ -40,6 +40,10 @@ public Hero(Profession profession,String name,HairType hairType,HairColor hairCo
As you can see, the number of constructor parameters can quickly become overwhelming, making it difficult to understand their arrangement. Additionally, this list of parameters might continue to grow if you decide to add more options in the future. This is known as the telescoping constructor antipattern.
Sequence diagram
![Builder sequence diagram](./etc/builder-sequence-diagram.png)
## Programmatic Example of Builder Pattern in Java
In this Java Builder pattern example, we construct different types of `Hero` objects with varying attributes.
@@ -146,10 +150,6 @@ Program output:
16:28:06.060 [main] INFO com.iluwatar.builder.App -- This is a thief named Desmond with bald head and wielding a bow.
```
## Builder Pattern Class Diagram
![Builder](./etc/builder.urm.png "Builder class diagram")
## When to Use the Builder Pattern in Java
Use the Builder pattern when
Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

+4 -4
View File
@@ -36,6 +36,10 @@ Wikipedia says
> Business Delegate is a Java EE design pattern. This pattern is directing to reduce the coupling in between business services and the connected presentation tier, and to hide the implementation details of services (including lookup and accessibility of EJB architecture). Business Delegates acts as an adaptor to invoke business objects from the presentation tier.
Sequence diagram
![Business Delegate sequence diagram](./etc/business-delegate-sequence-diagram.png)
## Programmatic Example of Business Delegate Pattern in Java
The following Java code demonstrates how to implement the Business Delegate pattern. This pattern is particularly useful in applications requiring loose coupling and efficient service interaction.
@@ -145,10 +149,6 @@ Here is the console output.
21:15:33.794 [main] INFO com.iluwatar.business.delegate.YouTubeService - YouTubeService is now processing
```
## Business Delegate Pattern Class Diagram
![Business Delegate](./etc/business-delegate.urm.png "Business Delegate")
## When to Use the Business Delegate Pattern in Java
Use the Business Delegate pattern when
Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

+4
View File
@@ -31,6 +31,10 @@ In plain words
> An instruction set defines the low-level operations that can be performed. A series of instructions is encoded as a sequence of bytes. A virtual machine executes these instructions one at a time, using a stack for intermediate values. By combining instructions, complex high-level behavior can be defined.
Sequence diagram
![Bytecode sequence diagram](./etc/bytecode-sequence-diagram.png)
## Programmatic Example of Bytecode Pattern in Java
In this programmatic example, we show how the Bytecode pattern in Java can simplify the execution of complex virtual machine instructions through a well-defined set of operations. This real-world example demonstrates how the Bytecode design pattern in Java can streamline game programming by allowing wizards' behavior to be easily adjusted through bytecode instructions.
Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

+4
View File
@@ -34,6 +34,10 @@ Wikipedia says
> In computing, a cache is a hardware or software component that stores data so that future requests for that data can be served faster; the data stored in a cache might be the result of an earlier computation or a copy of data stored elsewhere. A cache hit occurs when the requested data can be found in a cache, while a cache miss occurs when it cannot. Cache hits are served by reading data from the cache, which is faster than recomputing a result or reading from a slower data store; thus, the more requests that can be served from the cache, the faster the system performs.
Flowchart
![Caching flowchart](./etc/caching-flowchart.png)
## Programmatic Example of Caching Pattern in Java
In this programmatic example, we demonstrate different Java caching strategies, including write-through, write-around, and write-behind, using a user account management system.
Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

+5
View File
@@ -37,6 +37,11 @@ Wikipedia says
> In computer programming, a callback, also known as a "call-after" function, is any executable code that is passed as an argument to other code; that other code is expected to call back (execute) the argument at a given time.
Sequence diagram
![Callback sequence diagram](./etc/callback-sequence-diagram.png)
## Programmatic Example of Callback Pattern in Java
We need to be notified after the executing task has finished. We pass a callback method for the executor and wait for it to call back on us.
Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

+4 -4
View File
@@ -35,6 +35,10 @@ Wikipedia says
> In object-oriented design, the chain-of-responsibility pattern is a design pattern consisting of a source of command objects and a series of processing objects. Each processing object contains logic that defines the types of command objects that it can handle; the rest are passed to the next processing object in the chain.
Flowchart
![Chain of Responsibility flowchart](./etc/chain-of-responsibility-flowchart.png)
## Programmatic Example of Chain of Responsibility Pattern
In this Java example, the Orc King gives orders which are processed by a chain of command representing the Chain of Responsibility pattern. Learn how to implement this design pattern in Java with the following code snippet.
@@ -159,10 +163,6 @@ Orc officer handling request "torture prisoner"
Orc soldier handling request "collect tax"
```
## Chain of Responsibility Pattern Class Diagram
![Chain of Responsibility](./etc/chain-of-responsibility.urm.png "Chain of Responsibility class diagram")
## When to Use the Chain of Responsibility Pattern in Java
Use Chain of Responsibility when
Binary file not shown.

After

Width:  |  Height:  |  Size: 124 KiB