docs: diagrams for callback, circuit breaker, client session, collecting parameter, colletion pipeline, combinator, command, commander, component, composite entity, composite view, composite, context object, converter, crtp, currying

This commit is contained in:
Ilkka Seppälä
2025-04-06 11:31:49 +03:00
parent d5a46be3c5
commit 0509fabe8e
31 changed files with 60 additions and 1 deletions
-1
View File
@@ -41,7 +41,6 @@ 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.
+4
View File
@@ -33,6 +33,10 @@ Wikipedia says
> 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.
Flowchart
![Circuit Breaker flowchart](./etc/circuit-breaker-flowchart.png)
## Programmatic Example of Circuit Breaker Pattern in Java
This Java example demonstrates how the Circuit Breaker pattern can manage remote service failures and maintain system stability.
Binary file not shown.

After

Width:  |  Height:  |  Size: 139 KiB

+4
View File
@@ -33,6 +33,10 @@ Wikipedia says
> The client-server model on Wikipedia describes a system where client devices request services and resources from centralized servers. This model is crucial in web applications where client sessions are used to manage user-specific data across multiple requests. For example, when a bank customer accesses online banking services, their login credentials and session state are managed by the web server to maintain continuity of their interactions.
Sequence diagram
![Client Session sequence diagram](./etc/client-session-sequence-diagram.png)
## Programmatic Example of Client Session Pattern in Java
The Client Session design pattern is a behavioral design pattern that maintains a user's state and data across multiple requests within a web application, ensuring a continuous and personalized user experience. This pattern is commonly used in web applications where user-specific data needs to be managed across multiple requests.
Binary file not shown.

After

Width:  |  Height:  |  Size: 95 KiB

+4
View File
@@ -36,6 +36,10 @@ Wikipedia says
> In the Collecting Parameter idiom a collection (list, map, etc.) is passed repeatedly as a parameter to a method which adds items to the collection.
Flowchart
![Collecting Parameter flowchart](./etc/collecting-parameter-flowchart.png)
## Programmatic Example of Collecting Parameter Pattern in Java
Within a large corporate building, there exists a global printer queue that is a collection of all the printing jobs that are currently pending. Various floors contain different models of printers, each having a different printing policy. We must construct a program that can continually add appropriate printing jobs to a collection, which is called the collecting parameter.
Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

+4
View File
@@ -29,6 +29,10 @@ Wikipedia says
> In software engineering, a pipeline consists of a chain of processing elements (processes, threads, coroutines, functions, etc.), arranged so that the output of each element is the input of the next; the name is by analogy to a physical pipeline. Usually some amount of buffering is provided between consecutive elements. The information that flows in these pipelines is often a stream of records, bytes, or bits, and the elements of a pipeline may be called filters; this is also called the pipe(s) and filters design pattern. Connecting elements into a pipeline is analogous to function composition.
Flowchart
![Collection Pipeline flowchart](./etc/collection-pipeline-flowchart.png)
## Programmatic Example of Collection Pipeline Pattern in Java
The Collection Pipeline is a programming pattern where you organize some computation as a sequence of operations which compose by taking a collection as output of one operation and feeding it into the next.
Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

+4
View File
@@ -35,6 +35,10 @@ Wikipedia says
> A combinator is a higher-order function that uses only function application and earlier defined combinators to define a result from its arguments.
Flowchart
![Combinator flowchart](./etc/combinator-flowchart.png)
## Programmatic Example of Combinator Pattern in Java
In software design, combinatory logic is pivotal for creating reusable and modular code components. By leveraging higher-order functions, the Combinator pattern promotes code reuse and maintainability in Java applications.
Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

+4
View File
@@ -34,6 +34,10 @@ Wikipedia says
> In object-oriented programming, the command pattern is a behavioral design pattern in which an object is used to encapsulate all information needed to perform an action or trigger an event at a later time.
Sequence diagram
![Command sequence diagram](./etc/command-sequence-diagram.png)
## Programmatic Example of Command Pattern in Java
In the Command pattern, objects are used to encapsulate all information needed to perform an action or trigger an event at a later time. This pattern is particularly useful for implementing undo functionality in applications.
Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

+4
View File
@@ -33,6 +33,10 @@ In plain words
> The Commander pattern turns a request into a stand-alone object, allowing for the parameterization of commands, queueing of actions, and the implementation of undo operations.
Sequence diagram
![Commander sequence diagram](./etc/commander-sequence-diagram.png)
## Programmatic Example of Commander Pattern in Java
Managing transactions across different services in a distributed system, such as an e-commerce platform with separate `Payment` and `Shipping` microservices, requires careful coordination. Using the Commander pattern in Java for transaction coordination helps ensure data consistency and reliability, even when services experience partial failures.
Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

+4
View File
@@ -30,6 +30,10 @@ In plain words
> The component design pattern provides a single attribute to be accessible by numerous objects without requiring the existence of a relationship between the objects themselves.
Architecture diagram
![Component architecture diagram](./etc/component-architecture-diagram.png)
## Programmatic Example of Component Pattern in Java
The `App` class creates a demonstration of the use of the component pattern by creating two different objects which inherit a small collection of individual components that are modifiable.
Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

+4
View File
@@ -36,6 +36,10 @@ Wikipedia says
> Composite entity is a Java EE Software design pattern and it is used to model, represent, and manage a set of interrelated persistent objects rather than representing them as individual fine-grained entity beans, and also a composite entity bean represents a graph of objects.
Flowchart
![Composite Entity flowchart](./etc/composite-entity-flowchart.png)
## Programmatic Example of Composite Entity in Java
For a console, there may be many interfaces that need to be managed and controlled. Using the composite entity pattern, dependent objects such as messages and signals can be combined and controlled using a single object.
Binary file not shown.

After

Width:  |  Height:  |  Size: 38 KiB

+4
View File
@@ -29,6 +29,10 @@ Wikipedia says
> Composite views that are composed of multiple atomic subviews. Each component of the template may be included dynamically into the whole and the layout of the page may be managed independently of the content. This solution provides for the creation of a composite view based on the inclusion and substitution of modular dynamic and static template fragments. It promotes the reuse of atomic portions of the view by encouraging modular design.
Flowchart
![Composite View flowchart](./etc/composite-view-flowchart.png)
## Programmatic Example of Composite View Pattern in Java
A news site wants to display the current date and news to different users based on that user's preferences. The news site will substitute in different news feed components depending on the user's interest, defaulting to local news.
Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

+4
View File
@@ -34,6 +34,10 @@ Wikipedia says
> In software engineering, the composite pattern is a partitioning design pattern. The composite pattern describes that a group of objects is to be treated in the same way as a single instance of an object. The intent of a composite is to "compose" objects into tree structures to represent part-whole hierarchies. Implementing the composite pattern lets clients treat individual objects and compositions uniformly.
Flowchart
![Composite flowchart](./etc/composite-flowchart.png)
## Programmatic Example of Composite Pattern in Java
Every sentence is composed of words which are in turn composed of characters. Each of these objects are printable, and they can have something printed before or after them like sentence always ends with full stop and word always has space before it.
Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

+4
View File
@@ -36,6 +36,10 @@ In plain words
> Use a Context Object to encapsulate state in a protocol-independent way to be shared throughout your application.
Sequence diagram
![Context Object sequence diagram](./etc/context-object-sequence-diagram.png)
## Programmatic Example of Context Object in Java
In a multi-layered Java application, different layers such as A, B, and C extract specific information from a shared context. Passing each piece of information individually is inefficient. The Context Object pattern efficiently stores and passes this information, improving the overall performance and maintainability of the Java application.
Binary file not shown.

After

Width:  |  Height:  |  Size: 76 KiB

+4
View File
@@ -32,6 +32,10 @@ In plain words
> The Converter Pattern simplifies mapping instances of one class to instances of another class, ensuring consistent and clean data transformation.
Sequence diagram
![Converter sequence diagram](./etc/converter-sequence-diagram.png)
## Programmatic Example of Converter Pattern in Java
In applications, it's common for the database layer to have entities that need mapping to DTOs (Data Transfer Objects) for business logic. This mapping often involves many classes, necessitating a generic solution.
Binary file not shown.

After

Width:  |  Height:  |  Size: 99 KiB

@@ -40,6 +40,10 @@ Wikipedia says
> The curiously recurring template pattern (CRTP) is an idiom, originally in C++, in which a class X derives from a class template instantiation using X itself as a template argument.
Flowchart
![Curiously Recurring Template Pattern flowchart](./etc/crtp-flowchart.png)
## Programmatic example of CRTP in Java
For a mixed martial arts promotion that is planning an event, ensuring that the fights are organized between athletes of the same weight class is crucial. This prevents mismatches between fighters of significantly different sizes, such as a heavyweight facing off against a bantamweight.
Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

+4
View File
@@ -33,6 +33,10 @@ Wikipedia says
> In mathematics and computer science, currying is the technique of translating a function that takes multiple arguments into a sequence of families of functions, each taking a single argument.
Sequence diagram
![Currying sequence diagram](./etc/currying-sequence-diagram.png)
## Programmatic example of Currying Pattern in Java
Consider a librarian who wants to populate their library with books. The librarian wants functions which can create books corresponding to specific genres and authors. Currying makes this possible by writing a curried book builder function and utilising partial application.
Binary file not shown.

After

Width:  |  Height:  |  Size: 68 KiB