Skip to content

Commit 7c3ba8a

Browse files
authored
Merge branch 'iluwatar:master' into master
2 parents 1fa515f + 44f6ab3 commit 7c3ba8a

File tree

249 files changed

+1781
-94
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

249 files changed

+1781
-94
lines changed

Diff for: .all-contributorsrc

+9
Original file line numberDiff line numberDiff line change
@@ -3484,6 +3484,15 @@
34843484
"contributions": [
34853485
"code"
34863486
]
3487+
},
3488+
{
3489+
"login": "Suchismita-Deb",
3490+
"name": "Suchismita Deb",
3491+
"avatar_url": "https://avatars.githubusercontent.com/u/68535074?v=4",
3492+
"profile": "https://github.com/Suchismita-Deb",
3493+
"contributions": [
3494+
"code"
3495+
]
34873496
}
34883497
],
34893498
"contributorsPerLine": 6,

Diff for: README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=iluwatar_java-design-patterns&metric=coverage)](https://sonarcloud.io/dashboard?id=iluwatar_java-design-patterns)
77
[![Join the chat at https://gitter.im/iluwatar/java-design-patterns](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/iluwatar/java-design-patterns?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
88
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
9-
[![All Contributors](https://img.shields.io/badge/all_contributors-382-orange.svg?style=flat-square)](#contributors-)
9+
[![All Contributors](https://img.shields.io/badge/all_contributors-383-orange.svg?style=flat-square)](#contributors-)
1010
<!-- ALL-CONTRIBUTORS-BADGE:END -->
1111

1212
<br/>
@@ -569,6 +569,7 @@ This project is licensed under the terms of the MIT license.
569569
<td align="center" valign="top" width="16.66%"><a href="https://github.com/johnklint81"><img src="https://avatars.githubusercontent.com/u/70539458?v=4?s=100" width="100px;" alt="John Klint"/><br /><sub><b>John Klint</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=johnklint81" title="Code">💻</a></td>
570570
<td align="center" valign="top" width="16.66%"><a href="https://github.com/sanurah"><img src="https://avatars.githubusercontent.com/u/16178588?v=4?s=100" width="100px;" alt="Sanura Hettiarachchi"/><br /><sub><b>Sanura Hettiarachchi</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=sanurah" title="Code">💻</a></td>
571571
<td align="center" valign="top" width="16.66%"><a href="https://github.com/2897robo"><img src="https://avatars.githubusercontent.com/u/31699375?v=4?s=100" width="100px;" alt="Kim Gi Uk"/><br /><sub><b>Kim Gi Uk</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=2897robo" title="Code">💻</a></td>
572+
<td align="center" valign="top" width="16.66%"><a href="https://github.com/Suchismita-Deb"><img src="https://avatars.githubusercontent.com/u/68535074?v=4?s=100" width="100px;" alt="Suchismita Deb"/><br /><sub><b>Suchismita Deb</b></sub></a><br /><a href="https://github.com/iluwatar/java-design-patterns/commits?author=Suchismita-Deb" title="Code">💻</a></td>
572573
</tr>
573574
</tbody>
574575
</table>

Diff for: adapter/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ Wikipedia says
3535

3636
> In software engineering, the adapter pattern is a software design pattern that allows the interface of an existing class to be used as another interface. It is often used to make existing classes work with others without modifying their source code.
3737
38+
Sequence diagram
39+
40+
![Adapter sequence diagram](./etc/adapter-sequence-diagram.png "Adapter sequence diagram")
41+
3842
## Programmatic Example of Adapter Pattern in Java
3943

4044
The Adapter Pattern example in Java shows how a class with an incompatible interface can be adapted to work with another class.

Diff for: adapter/etc/adapter-sequence-diagram.png

27 KB
Loading

Diff for: ambassador/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ Microsoft documentation states
3333

3434
> An ambassador service can be thought of as an out-of-process proxy which is co-located with the client. This pattern can be useful for offloading common client connectivity tasks such as monitoring, logging, routing, security (such as TLS), and resiliency patterns in a language agnostic way. It is often used with legacy applications, or other applications that are difficult to modify, in order to extend their networking capabilities. It can also enable a specialized team to implement those features.
3535
36+
Sequence diagram
37+
38+
![Ambassador sequence diagram](./etc/ambassador-sequence-diagram.png "Ambassador sequence diagram")
39+
3640
## Programmatic Example of Ambassador Pattern in Java
3741

3842
In this example of the Ambassador Pattern in Java, we demonstrate how to implement latency checks, logging, and retry mechanisms to improve system reliability.

Diff for: ambassador/etc/ambassador-sequence-diagram.png

27.9 KB
Loading

Diff for: anti-corruption-layer/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ In plain words
4444

4545
> Implement a façade or adapter layer between different subsystems that don't share the same semantics. This layer translates requests that one subsystem makes to the other subsystem. Use this pattern to ensure that an application's design is not limited by dependencies on outside subsystems. This pattern was first described by Eric Evans in Domain-Driven Design.
4646
47+
Sequence diagram
48+
49+
![Anti-Corruption Layer sequence diagram](./etc/anti-corruption-layer-sequence-diagram.png "Anti-Corruption Layer sequence diagram")
50+
4751
## Programmatic Example of Anti-Corruption Layer Pattern in Java
4852

4953
The ACL design pattern in Java provides an intermediary layer that translates data formats, ensuring that integration between different systems does not lead to data corruption.
Loading

Diff for: arrange-act-assert/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ WikiWikiWeb says
3838

3939
> Arrange/Act/Assert is a pattern for arranging and formatting code in UnitTest methods.
4040
41+
Flowchart
42+
43+
![Arrange/Act/Assert flowchart](./etc/arrange-act-assert-flowchart.png "Arrange/Act/Assert flowchart")
44+
4145
## Programmatic Example of Arrange/Act/Assert Pattern in Java
4246

4347
We need to write comprehensive and clear unit test suite for a class. Using the Arrange/Act/Assert pattern in Java testing ensures clarity.
33.1 KB
Loading

Diff for: async-method-invocation/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ Wikipedia says
3636

3737
> In multithreaded computer programming, asynchronous method invocation (AMI), also known as asynchronous method calls or the asynchronous pattern is a design pattern in which the call site is not blocked while waiting for the called code to finish. Instead, the calling thread is notified when the reply arrives. Polling for a reply is an undesired option.
3838
39+
Sequence diagram
40+
41+
![Async Method Invocation sequence diagram](./etc/async-method-invocation-sequence-diagram.png "Async Method Invocation sequence diagram")
42+
3943
## Programmatic Example of Async Method Invocation Pattern in Java
4044

4145
Consider a scenario where multiple tasks need to be executed simultaneously. Using the Async Method Invocation pattern, you can initiate these tasks without waiting for each to complete, thus optimizing resource usage and reducing latency.
Loading

Diff for: balking/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ Wikipedia says
2929

3030
> The balking pattern is a software design pattern that only executes an action on an object when the object is in a particular state. For example, if an object reads ZIP files and a calling method invokes a get method on the object when the ZIP file is not open, the object would "balk" at the request.
3131
32+
Flowchart
33+
34+
![Balking flowchart](./etc/balking-flowchart.png)
35+
3236
## Programmatic Example of Balking Pattern in Java
3337

3438
This example demonstrates the Balking Pattern in a multithreaded Java application, highlighting state management and concurrency control. The Balking Pattern is exemplified by a washing machine's start button that initiates washing only if the machine is idle. This ensures state management and prevents concurrent issues.

Diff for: balking/etc/balking-flowchart.png

47.9 KB
Loading

Diff for: bloc/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ The Bloc pattern manages the state of an object and allows for dynamically notif
3535

3636
> While not a formalized "Gang of Four" design pattern, Bloc is widely used in state-driven applications. It centralizes state management and propagates state changes to registered observers, following principles of separation of concerns.
3737
38+
### Sequence diagram
39+
40+
![Bloc sequence diagram](./etc/bloc-sequence-diagram.png)
41+
3842
---
3943

4044
## Programmatic Example of the Bloc Pattern in Java

Diff for: bloc/etc/bloc-sequence-diagram.png

29.2 KB
Loading

Diff for: bridge/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ Wikipedia says
3636

3737
> The bridge pattern is a design pattern used in software engineering that is meant to "decouple an abstraction from its implementation so that the two can vary independently"
3838
39+
Sequence diagram
40+
41+
![Bridge sequence diagram](./etc/bridge-sequence-diagram.png)
42+
3943
## Programmatic Example of Bridge Pattern in Java
4044

4145
Imagine you have a weapon that can have various enchantments, and you need to combine different weapons with different enchantments. How would you handle this? Would you create multiple copies of each weapon, each with a different enchantment, or would you create separate enchantments and apply them to the weapon as needed? The Bridge pattern enables you to do the latter.
@@ -203,10 +207,6 @@ The hammer is unwielded.
203207
The item's glow fades.
204208
```
205209

206-
## Bridge Pattern Class Diagram
207-
208-
![Bridge](./etc/bridge.urm.png "Bridge class diagram")
209-
210210
## When to Use the Bridge Pattern in Java
211211

212212
Consider using the Bridge pattern when:

Diff for: bridge/etc/bridge-sequence-diagram.png

26.2 KB
Loading

Diff for: builder/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ public Hero(Profession profession,String name,HairType hairType,HairColor hairCo
4040

4141
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.
4242

43+
Sequence diagram
44+
45+
![Builder sequence diagram](./etc/builder-sequence-diagram.png)
46+
4347
## Programmatic Example of Builder Pattern in Java
4448

4549
In this Java Builder pattern example, we construct different types of `Hero` objects with varying attributes.
@@ -146,10 +150,6 @@ Program output:
146150
16:28:06.060 [main] INFO com.iluwatar.builder.App -- This is a thief named Desmond with bald head and wielding a bow.
147151
```
148152

149-
## Builder Pattern Class Diagram
150-
151-
![Builder](./etc/builder.urm.png "Builder class diagram")
152-
153153
## When to Use the Builder Pattern in Java
154154

155155
Use the Builder pattern when

Diff for: builder/etc/builder-sequence-diagram.png

51.1 KB
Loading

Diff for: business-delegate/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ Wikipedia says
3636

3737
> 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.
3838
39+
Sequence diagram
40+
41+
![Business Delegate sequence diagram](./etc/business-delegate-sequence-diagram.png)
42+
3943
## Programmatic Example of Business Delegate Pattern in Java
4044

4145
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.
145149
21:15:33.794 [main] INFO com.iluwatar.business.delegate.YouTubeService - YouTubeService is now processing
146150
```
147151

148-
## Business Delegate Pattern Class Diagram
149-
150-
![Business Delegate](./etc/business-delegate.urm.png "Business Delegate")
151-
152152
## When to Use the Business Delegate Pattern in Java
153153

154154
Use the Business Delegate pattern when
57.5 KB
Loading

Diff for: bytecode/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ In plain words
3131

3232
> 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.
3333
34+
Sequence diagram
35+
36+
![Bytecode sequence diagram](./etc/bytecode-sequence-diagram.png)
37+
3438
## Programmatic Example of Bytecode Pattern in Java
3539

3640
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.

Diff for: bytecode/etc/bytecode-sequence-diagram.png

23 KB
Loading

Diff for: caching/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ Wikipedia says
3434

3535
> 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.
3636
37+
Flowchart
38+
39+
![Caching flowchart](./etc/caching-flowchart.png)
40+
3741
## Programmatic Example of Caching Pattern in Java
3842

3943
In this programmatic example, we demonstrate different Java caching strategies, including write-through, write-around, and write-behind, using a user account management system.

Diff for: caching/etc/caching-flowchart.png

44.4 KB
Loading

Diff for: callback/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ Wikipedia says
3737

3838
> 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.
3939
40+
Sequence diagram
41+
42+
![Callback sequence diagram](./etc/callback-sequence-diagram.png)
43+
4044
## Programmatic Example of Callback Pattern in Java
4145

4246
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.

Diff for: callback/etc/callback-sequence-diagram.png

40.6 KB
Loading

Diff for: chain-of-responsibility/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ Wikipedia says
3535

3636
> 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.
3737
38+
Flowchart
39+
40+
![Chain of Responsibility flowchart](./etc/chain-of-responsibility-flowchart.png)
41+
3842
## Programmatic Example of Chain of Responsibility Pattern
3943

4044
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"
159163
Orc soldier handling request "collect tax"
160164
```
161165

162-
## Chain of Responsibility Pattern Class Diagram
163-
164-
![Chain of Responsibility](./etc/chain-of-responsibility.urm.png "Chain of Responsibility class diagram")
165-
166166
## When to Use the Chain of Responsibility Pattern in Java
167167

168168
Use Chain of Responsibility when
Loading

Diff for: circuit-breaker/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ Wikipedia says
3333

3434
> Circuit breaker is a design pattern used in modern software development. It is used to detect failures and encapsulates the logic of preventing a failure from constantly recurring, during maintenance, temporary external system failure or unexpected system difficulties.
3535
36+
Flowchart
37+
38+
![Circuit Breaker flowchart](./etc/circuit-breaker-flowchart.png)
39+
3640
## Programmatic Example of Circuit Breaker Pattern in Java
3741

3842
This Java example demonstrates how the Circuit Breaker pattern can manage remote service failures and maintain system stability.

Diff for: circuit-breaker/etc/circuit-breaker-flowchart.png

139 KB
Loading

0 commit comments

Comments
 (0)