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

File tree

16 files changed

+32
-4
lines changed

16 files changed

+32
-4
lines changed

spatial-partition/README.md

Lines changed: 4 additions & 0 deletions
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.
Loading

special-case/README.md

Lines changed: 4 additions & 0 deletions
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.
Loading

specification/README.md

Lines changed: 4 additions & 0 deletions
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.
57 KB
Loading

state/README.md

Lines changed: 4 additions & 0 deletions
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.

state/etc/state-flowchart.png

85.5 KB
Loading

step-builder/README.md

Lines changed: 4 additions & 4 deletions
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
Loading

0 commit comments

Comments
 (0)