docs: add diagrams for spatial partition, special case, specification, state, step builder, strangler, strategy, subclass sandbox
@@ -39,6 +39,10 @@ Wikipedia says
|
||||
>
|
||||
> 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.
|
||||
|
||||
Flowchart
|
||||
|
||||

|
||||
|
||||
## Programmatic Example of Spatial Partition Pattern in Java
|
||||
|
||||
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.
|
||||
|
||||
|
After Width: | Height: | Size: 53 KiB |
@@ -37,6 +37,10 @@ In [Patterns of Enterprise Application Architecture](https://amzn.to/3WfKBPR) Ma
|
||||
|
||||
> 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.
|
||||
|
||||
Sequnce diagram
|
||||
|
||||

|
||||
|
||||
## Programmatic Example of Special Case Pattern in Java
|
||||
|
||||
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.
|
||||
|
||||
|
After Width: | Height: | Size: 49 KiB |
@@ -37,6 +37,10 @@ Wikipedia says
|
||||
|
||||
> 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.
|
||||
|
||||
Flowchart
|
||||
|
||||

|
||||
|
||||
## Programmatic Example of Specification Pattern in Java
|
||||
|
||||
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.
|
||||
|
||||
|
After Width: | Height: | Size: 57 KiB |
@@ -38,6 +38,10 @@ Wikipedia says
|
||||
|
||||
> 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.
|
||||
|
||||
Flowchart
|
||||
|
||||

|
||||
|
||||
## Programmatic Example of State Pattern in Java
|
||||
|
||||
In our programmatic example there is a mammoth with alternating moods.
|
||||
|
||||
|
After Width: | Height: | Size: 86 KiB |
@@ -35,6 +35,10 @@ Wikipedia says
|
||||
|
||||
> 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.
|
||||
|
||||
Sequence diagram
|
||||
|
||||

|
||||
|
||||
## Programmatic Example of Step Builder Pattern in Java
|
||||
|
||||
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:
|
||||
12:58:13.889 [main] INFO com.iluwatar.stepbuilder.App -- This is a Rogue named Desmond armed with a with nothing.
|
||||
```
|
||||
|
||||
## Detailed Explanation of Step Builder Pattern with Real-World Examples
|
||||
|
||||

|
||||
|
||||
## When to Use the Step Builder Pattern in Java
|
||||
|
||||
The Step Builder pattern in Java is used
|
||||
|
||||
|
After Width: | Height: | Size: 58 KiB |
@@ -32,6 +32,10 @@ Wikipedia says
|
||||
|
||||
> 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.
|
||||
|
||||
Flowchart
|
||||
|
||||

|
||||
|
||||
## Programmatic Example of Strangler Pattern in Java
|
||||
|
||||
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.
|
||||
|
||||
|
After Width: | Height: | Size: 65 KiB |
@@ -34,6 +34,10 @@ Wikipedia says
|
||||
|
||||
> 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.
|
||||
|
||||
Flowchart
|
||||
|
||||

|
||||
|
||||
## Programmatic Example of Strategy Pattern in Java
|
||||
|
||||
Slaying dragons is a dangerous job. With experience, it becomes easier. Veteran dragonslayers have developed different fighting strategies against different types of dragons.
|
||||
|
||||
|
After Width: | Height: | Size: 95 KiB |
@@ -35,6 +35,10 @@ In plain words
|
||||
|
||||
> 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.
|
||||
|
||||
Flowchart
|
||||
|
||||

|
||||
|
||||
## Programmatic Example of Subclass Sandbox Pattern in Java
|
||||
|
||||
Using the Subclass Sandbox pattern, developers can create distinct functionalities within Java applications, enhancing game development and software design.
|
||||
|
||||
|
After Width: | Height: | Size: 50 KiB |