Skip to content

Commit cd224ea

Browse files
committed
docs: add diagrams for spatial partition, special case, specification, state, step builder, strangler, strategy, subclass sandbox
1 parent 8e82390 commit cd224ea

16 files changed

+32
-4
lines changed

Diff for: spatial-partition/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ Wikipedia says
3939
>
4040
> For example, in ray tracing, space partitioning helps quickly determine the objects a ray might intersect by narrowing down the search space, leading to faster rendering times. Similarly, in game development, Quadtrees can efficiently manage 2D game environments by segmenting the space into smaller regions, facilitating quicker collision detection and rendering.
4141
42+
Flowchart
43+
44+
![Spatial Partition flowchart](./etc/spatial-partition-flowchart.png)
45+
4246
## Programmatic Example of Spatial Partition Pattern in Java
4347

4448
The Spatial Partition design pattern in Java is a strategic approach for handling multiple objects in expansive game worlds or detailed simulation environments, boosting query efficiency and operational speed. It allows us to efficiently manage these objects and perform operations like collision detection or range queries. The pattern works by dividing the space into smaller, manageable regions, and each object is associated with the region it belongs to. This way, we can limit our operations to a specific region, instead of checking every object against every other object.
52.7 KB
Loading

Diff for: special-case/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ In [Patterns of Enterprise Application Architecture](https://amzn.to/3WfKBPR) Ma
3737

3838
> If you’ll pardon the unresistable pun, I see [Null Object](https://java-design-patterns.com/patterns/null-object/) as special case of Special Case.
3939
40+
Sequnce diagram
41+
42+
![Special Case sequence diagram](./etc/special-case-sequence-diagram.png)
43+
4044
## Programmatic Example of Special Case Pattern in Java
4145

4246
The Special Case Pattern is a software design pattern that is used to handle a specific, often uncommon, case separately from the general case in the code. This pattern is useful when a class has behavior that requires conditional logic based on its state. Instead of cluttering the class with conditional logic, we can encapsulate the special behavior in a subclass.

Diff for: special-case/etc/special-case-sequence-diagram.png

48.9 KB
Loading

Diff for: specification/README.md

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

3838
> In computer programming, the specification pattern is a particular software design pattern, whereby business rules can be recombined by chaining the business rules together using boolean logic.
3939
40+
Flowchart
41+
42+
![Specification Pattern flowchart](./etc/specification-flowchart.png)
43+
4044
## Programmatic Example of Specification Pattern in Java
4145

4246
Let's consider a creature pool example. We have a collection of creatures with specific properties. These properties might belong to a predefined, limited set (represented by enums like `Size`, `Movement`, and `Color`) or they might be continuous values (e.g., the mass of a `Creature`). In cases with continuous values, it's better to use a "parameterized specification," where the property value is provided as an argument when the `Creature` is instantiated, allowing for greater flexibility. Additionally, predefined and/or parameterized properties can be combined using boolean logic, offering almost limitless selection possibilities (this is known as a "composite specification," explained further below). The advantages and disadvantages of each approach are detailed in the table at the end of this document.

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

57 KB
Loading

Diff for: state/README.md

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

3939
> The state pattern is a behavioral software design pattern that allows an object to alter its behavior when its internal state changes. This pattern is close to the concept of finite-state machines. The state pattern can be interpreted as a strategy pattern, which is able to switch a strategy through invocations of methods defined in the pattern's interface.
4040
41+
Flowchart
42+
43+
![State flowchart](./etc/state-flowchart.png)
44+
4145
## Programmatic Example of State Pattern in Java
4246

4347
In our programmatic example there is a mammoth with alternating moods.

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

85.5 KB
Loading

Diff for: step-builder/README.md

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

3636
> The Step Builder pattern is a variation of the Builder design pattern, designed to provide a flexible solution for constructing complex objects step-by-step. This pattern is particularly useful when an object requires multiple initialization steps, which can be done incrementally to ensure clarity and flexibility in the creation process.
3737
38+
Sequence diagram
39+
40+
![Step Builder sequence diagram](./etc/step-builder-sequence-diagram.png)
41+
3842
## Programmatic Example of Step Builder Pattern in Java
3943

4044
The Step Builder pattern in Java is an extension of the Builder pattern that guides the user through the creation of an object in a step-by-step manner. This pattern improves the user experience by only showing the next step methods available, and not showing the build method until it's the right time to build the object.
@@ -162,10 +166,6 @@ Console output:
162166
12:58:13.889 [main] INFO com.iluwatar.stepbuilder.App -- This is a Rogue named Desmond armed with a with nothing.
163167
```
164168

165-
## Detailed Explanation of Step Builder Pattern with Real-World Examples
166-
167-
![Step Builder](./etc/step-builder.png "Step Builder")
168-
169169
## When to Use the Step Builder Pattern in Java
170170

171171
The Step Builder pattern in Java is used

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

57.7 KB
Loading

Diff for: strangler/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ Wikipedia says
3232

3333
> The Strangler Design Pattern involves incrementally migrating a legacy system by gradually replacing it with a new system. It wraps old code with new code, redirecting or logging uses of the old code to ensure a seamless transition. This pattern is named after the strangler fig plant, which grows around a host tree and eventually replaces it entirely. It's particularly useful for modernizing monolithic applications and transitioning them to microservices architecture with minimal risk and disruption.
3434
35+
Flowchart
36+
37+
![Strangler flowchart](./etc/strangler-flowchart.png)
38+
3539
## Programmatic Example of Strangler Pattern in Java
3640

3741
The Strangler design pattern in Java is a software design pattern that incrementally migrates a legacy system by gradually replacing specific pieces of functionality with new applications and services. As features from the legacy system are replaced, the new system eventually replaces all the old system's features, strangling the old system and allowing you to decommission it.

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

65.4 KB
Loading

Diff for: strategy/README.md

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

3535
> In computer programming, the strategy pattern (also known as the policy pattern) is a behavioral software design pattern that enables selecting an algorithm at runtime.
3636
37+
Flowchart
38+
39+
![Strategy flowchart](./etc/strategy-flowchart.png)
40+
3741
## Programmatic Example of Strategy Pattern in Java
3842

3943
Slaying dragons is a dangerous job. With experience, it becomes easier. Veteran dragonslayers have developed different fighting strategies against different types of dragons.

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

95.3 KB
Loading

Diff for: subclass-sandbox/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ In plain words
3535

3636
> A base class defines an abstract sandbox method and several provided operations. Marking them protected makes it clear that they are for use by derived classes. Each derived sandboxed subclass implements the sandbox method using the provided operations.
3737
38+
Flowchart
39+
40+
![Subclass Sandbox flowchart](./etc/subclass-sandbox-flowchart.png)
41+
3842
## Programmatic Example of Subclass Sandbox Pattern in Java
3943

4044
Using the Subclass Sandbox pattern, developers can create distinct functionalities within Java applications, enhancing game development and software design.

Diff for: subclass-sandbox/etc/subclass-sandbox-flowchart.png

50.2 KB
Loading

0 commit comments

Comments
 (0)