docs: fix line endings

This commit is contained in:
Ilkka Seppälä
2024-02-12 19:28:48 +02:00
parent 4277a54835
commit a258bcc1eb
3 changed files with 18 additions and 48 deletions
+7 -22
View File
@@ -10,15 +10,11 @@ tag:
## Intent ## Intent
The Abstract Document design pattern is a structural design pattern that aims to provide a consistent way to handle The Abstract Document design pattern is a structural design pattern that aims to provide a consistent way to handle hierarchical and tree-like data structures by defining a common interface for various document types. It separates the core document structure from specific data formats, enabling dynamic updates and simplified maintenance.
hierarchical and tree-like data structures by defining a common interface for various document types. It separates
the core document structure from specific data formats, enabling dynamic updates and simplified maintenance.
## Explanation ## Explanation
The Abstract Document pattern enables handling additional, non-static properties. This pattern The Abstract Document pattern enables handling additional, non-static properties. This pattern uses concept of traits to enable type safety and separate properties of different classes into set of interfaces.
uses concept of traits to enable type safety and separate properties of different classes into
set of interfaces.
Real world example Real world example
@@ -30,16 +26,11 @@ In plain words
Wikipedia says Wikipedia says
> An object-oriented structural design pattern for organizing objects in loosely typed key-value stores and exposing > An object-oriented structural design pattern for organizing objects in loosely typed key-value stores and exposing the data using typed views. The purpose of the pattern is to achieve a high degree of flexibility between components in a strongly typed language where new properties can be added to the object-tree on the fly, without losing the support of type-safety. The pattern makes use of traits to separate different properties of a class into different interfaces.
the data using typed views. The purpose of the pattern is to achieve a high degree of flexibility between components
in a strongly typed language where new properties can be added to the object-tree on the fly, without losing the
support of type-safety. The pattern makes use of traits to separate different properties of a class into different
interfaces.
**Programmatic Example** **Programmatic Example**
Let's first define the base classes `Document` and `AbstractDocument`. They basically make the object hold a property Let's first define the base classes `Document` and `AbstractDocument`. They basically make the object hold a property map and any amount of child objects.
map and any amount of child objects.
```java ```java
public interface Document { public interface Document {
@@ -84,8 +75,7 @@ public abstract class AbstractDocument implements Document {
... ...
} }
``` ```
Next we define an enum `Property` and a set of interfaces for type, price, model and parts. This allows us to create Next we define an enum `Property` and a set of interfaces for type, price, model and parts. This allows us to create static looking interface to our `Car` class.
static looking interface to our `Car` class.
```java ```java
public enum Property { public enum Property {
@@ -179,9 +169,7 @@ And finally here's how we construct and use the `Car` in a full example.
## Applicability ## Applicability
This pattern is particularly useful in scenarios where you have different types of documents that share some common This pattern is particularly useful in scenarios where you have different types of documents that share some common attributes or behaviors, but also have unique attributes or behaviors specific to their individual types. Here are some scenarios where the Abstract Document design pattern can be applicable:
attributes or behaviors, but also have unique attributes or behaviors specific to their individual types. Here are
some scenarios where the Abstract Document design pattern can be applicable:
* Content Management Systems (CMS): In a CMS, you might have various types of content such as articles, images, videos, etc. Each type of content could have shared attributes like creation date, author, and tags, while also having specific attributes like image dimensions for images or video duration for videos. * Content Management Systems (CMS): In a CMS, you might have various types of content such as articles, images, videos, etc. Each type of content could have shared attributes like creation date, author, and tags, while also having specific attributes like image dimensions for images or video duration for videos.
@@ -205,10 +193,7 @@ some scenarios where the Abstract Document design pattern can be applicable:
* Maintainability and flexibility are critical for the codebase. * Maintainability and flexibility are critical for the codebase.
The key idea behind the Abstract Document design pattern is to provide a flexible and extensible way to manage different The key idea behind the Abstract Document design pattern is to provide a flexible and extensible way to manage different types of documents or entities with shared and distinct attributes. By defining a common interface and implementing it across various document types, you can achieve a more organized and consistent approach to handling complex data structures.
types of documents or entities with shared and distinct attributes. By defining a common interface and implementing it
across various document types, you can achieve a more organized and consistent approach to handling complex data
structures.
## Consequences ## Consequences
+6 -15
View File
@@ -14,32 +14,25 @@ Kit
## Intent ## Intent
The Abstract Factory design pattern provides a way to create families of related objects without specifying their The Abstract Factory design pattern provides a way to create families of related objects without specifying their concrete classes. This allows for code that is independent of the specific classes of objects it uses, promoting flexibility and maintainability.
concrete classes. This allows for code that is independent of the specific classes of objects it uses, promoting
flexibility and maintainability.
## Explanation ## Explanation
Real-world example Real-world example
> To create a kingdom we need objects with a common theme. The elven kingdom needs an elven king, elven castle, and > To create a kingdom we need objects with a common theme. The elven kingdom needs an elven king, elven castle, and elven army whereas the orcish kingdom needs an orcish king, orcish castle, and orcish army. There is a dependency between the objects in the kingdom.
> elven army whereas the orcish kingdom needs an orcish king, orcish castle, and orcish army. There is a dependency
> between the objects in the kingdom.
In plain words In plain words
> A factory of factories; a factory that groups the individual but related/dependent factories together without > A factory of factories; a factory that groups the individual but related/dependent factories together without specifying their concrete classes.
> specifying their concrete classes.
Wikipedia says Wikipedia says
> The abstract factory pattern provides a way to encapsulate a group of individual factories that have a common theme > The abstract factory pattern provides a way to encapsulate a group of individual factories that have a common theme without specifying their concrete classes
> without specifying their concrete classes
**Programmatic Example** **Programmatic Example**
Translating the kingdom example above. First of all, we have some interfaces and implementation for the objects in the Translating the kingdom example above. First of all, we have some interfaces and implementation for the objects in the kingdom.
kingdom.
```java ```java
public interface Castle { public interface Castle {
@@ -148,9 +141,7 @@ This is the elven king!
This is the elven Army! This is the elven Army!
``` ```
Now, we can design a factory for our different kingdom factories. In this example, we created `FactoryMaker`, responsible for returning an instance of either `ElfKingdomFactory` or `OrcKingdomFactory`. Now, we can design a factory for our different kingdom factories. In this example, we created `FactoryMaker`, responsible for returning an instance of either `ElfKingdomFactory` or `OrcKingdomFactory`. The client can use `FactoryMaker` to create the desired concrete factory which, in turn, will produce different concrete objects (derived from `Army`, `King`, `Castle`). In this example, we also used an enum to parameterize which type of kingdom factory the client will ask for.
The client can use `FactoryMaker` to create the desired concrete factory which, in turn, will produce different concrete objects (derived from `Army`, `King`, `Castle`).
In this example, we also used an enum to parameterize which type of kingdom factory the client will ask for.
```java ```java
public static class FactoryMaker { public static class FactoryMaker {
+5 -11
View File
@@ -9,21 +9,17 @@ tag:
## Intent ## Intent
The Active Object design pattern provides a safe and reliable way to implement asynchronous behavior in concurrent The Active Object design pattern provides a safe and reliable way to implement asynchronous behavior in concurrent systems. It achieves this by encapsulating tasks within objects that have their own thread and message queue. This separation keeps the main thread responsive and avoids issues like direct thread manipulation or shared state access.
systems. It achieves this by encapsulating tasks within objects that have their own thread and message queue. This
separation keeps the main thread responsive and avoids issues like direct thread manipulation or shared state access.
## Explanation ## Explanation
The class that implements the active object pattern will contain a self-synchronization mechanism without using The class that implements the active object pattern will contain a self-synchronization mechanism without using 'synchronized' methods.
'synchronized' methods.
Real-world example Real-world example
>The Orcs are known for their wildness and untameable soul. It seems like they have their own thread of control based on previous behavior. >The Orcs are known for their wildness and untameable soul. It seems like they have their own thread of control based on previous behavior.
To implement a creature that has its own thread of control mechanism and expose its API only and not the execution To implement a creature that has its own thread of control mechanism and expose its API only and not the execution itself, we can use the Active Object pattern.
itself, we can use the Active Object pattern.
**Programmatic Example** **Programmatic Example**
@@ -84,8 +80,7 @@ public abstract class ActiveCreature{
} }
``` ```
We can see that any class that will extend the ActiveCreature class will have its own thread of control to invoke and We can see that any class that will extend the ActiveCreature class will have its own thread of control to invoke and execute methods.
execute methods.
For example, the Orc class: For example, the Orc class:
@@ -99,8 +94,7 @@ public class Orc extends ActiveCreature {
} }
``` ```
Now, we can create multiple creatures such as Orcs, tell them to eat and roam, and they will execute it on their own Now, we can create multiple creatures such as Orcs, tell them to eat and roam, and they will execute it on their own thread of control:
thread of control:
```java ```java
public static void main(String[] args) { public static void main(String[] args) {