Skip to content

Commit f80cc46

Browse files
committed
docs: collecting parameter docs + formatting
1 parent ea7bc2a commit f80cc46

File tree

23 files changed

+1191
-794
lines changed

23 files changed

+1191
-794
lines changed

abstract-document/README.md

Lines changed: 76 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,43 @@
22
title: Abstract Document
33
category: Structural
44
language: en
5-
tag:
6-
- Abstraction
7-
- Extensibility
8-
- Decoupling
5+
tag:
6+
- Abstraction
7+
- Extensibility
8+
- Decoupling
99
---
1010

1111
## Intent
1212

13-
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.
13+
The Abstract Document design pattern is a structural design pattern that aims to provide a consistent way to handle
14+
hierarchical and tree-like data structures by defining a common interface for various document types. It separates the
15+
core document structure from specific data formats, enabling dynamic updates and simplified maintenance.
1416

1517
## Explanation
1618

17-
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.
19+
The Abstract Document pattern enables handling additional, non-static properties. This pattern uses concept of traits to
20+
enable type safety and separate properties of different classes into set of interfaces.
1821

1922
Real world example
2023

21-
> Consider a car that consists of multiple parts. However, we don't know if the specific car really has all the parts, or just some of them. Our cars are dynamic and extremely flexible.
24+
> Consider a car that consists of multiple parts. However, we don't know if the specific car really has all the parts,
25+
> or just some of them. Our cars are dynamic and extremely flexible.
2226
2327
In plain words
2428

2529
> Abstract Document pattern allows attaching properties to objects without them knowing about it.
2630
2731
Wikipedia says
2832

29-
> 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.
33+
> An object-oriented structural design pattern for organizing objects in loosely typed key-value stores and exposing the
34+
> data using typed views. The purpose of the pattern is to achieve a high degree of flexibility between components in a
35+
> strongly typed language where new properties can be added to the object-tree on the fly, without losing the support of
36+
> type-safety. The pattern makes use of traits to separate different properties of a class into different interfaces.
3037
3138
**Programmatic Example**
3239

33-
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.
40+
Let's first define the base classes `Document` and `AbstractDocument`. They basically make the object hold a property
41+
map and any amount of child objects.
3442

3543
```java
3644
public interface Document {
@@ -75,7 +83,9 @@ public abstract class AbstractDocument implements Document {
7583
...
7684
}
7785
```
78-
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.
86+
87+
Next we define an enum `Property` and a set of interfaces for type, price, model and parts. This allows us to create
88+
static looking interface to our `Car` class.
7989

8090
```java
8191
public enum Property {
@@ -96,6 +106,7 @@ public interface HasPrice extends Document {
96106
return Optional.ofNullable((Number) get(Property.PRICE.toString()));
97107
}
98108
}
109+
99110
public interface HasModel extends Document {
100111

101112
default Optional<String> getModel() {
@@ -127,40 +138,40 @@ And finally here's how we construct and use the `Car` in a full example.
127138
```java
128139
LOGGER.info("Constructing parts and car");
129140
130-
var wheelProperties = Map.of(
131-
Property.TYPE.toString(), "wheel",
132-
Property.MODEL.toString(), "15C",
133-
Property.PRICE.toString(), 100L);
141+
var wheelProperties=Map.of(
142+
Property.TYPE.toString(),"wheel",
143+
Property.MODEL.toString(),"15C",
144+
Property.PRICE.toString(),100L);
134145
135-
var doorProperties = Map.of(
136-
Property.TYPE.toString(), "door",
137-
Property.MODEL.toString(), "Lambo",
138-
Property.PRICE.toString(), 300L);
146+
var doorProperties=Map.of(
147+
Property.TYPE.toString(),"door",
148+
Property.MODEL.toString(),"Lambo",
149+
Property.PRICE.toString(),300L);
139150
140-
var carProperties = Map.of(
141-
Property.MODEL.toString(), "300SL",
142-
Property.PRICE.toString(), 10000L,
143-
Property.PARTS.toString(), List.of(wheelProperties, doorProperties));
151+
var carProperties=Map.of(
152+
Property.MODEL.toString(),"300SL",
153+
Property.PRICE.toString(),10000L,
154+
Property.PARTS.toString(),List.of(wheelProperties,doorProperties));
144155
145-
var car = new Car(carProperties);
156+
var car=new Car(carProperties);
146157
147158
LOGGER.info("Here is our car:");
148-
LOGGER.info("-> model: {}", car.getModel().orElseThrow());
149-
LOGGER.info("-> price: {}", car.getPrice().orElseThrow());
159+
LOGGER.info("-> model: {}",car.getModel().orElseThrow());
160+
LOGGER.info("-> price: {}",car.getPrice().orElseThrow());
150161
LOGGER.info("-> parts: ");
151-
car.getParts().forEach(p -> LOGGER.info("\t{}/{}/{}",
152-
p.getType().orElse(null),
153-
p.getModel().orElse(null),
154-
p.getPrice().orElse(null))
162+
car.getParts().forEach(p->LOGGER.info("\t{}/{}/{}",
163+
p.getType().orElse(null),
164+
p.getModel().orElse(null),
165+
p.getPrice().orElse(null))
155166
);
156167
157-
// Constructing parts and car
158-
// Here is our car:
159-
// model: 300SL
160-
// price: 10000
161-
// parts:
162-
// wheel/15C/100
163-
// door/Lambo/300
168+
// Constructing parts and car
169+
// Here is our car:
170+
// model: 300SL
171+
// price: 10000
172+
// parts:
173+
// wheel/15C/100
174+
// door/Lambo/300
164175
```
165176
166177
## Class diagram
@@ -169,21 +180,38 @@ And finally here's how we construct and use the `Car` in a full example.
169180
170181
## Applicability
171182
172-
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:
183+
This pattern is particularly useful in scenarios where you have different types of documents that share some common
184+
attributes or behaviors, but also have unique attributes or behaviors specific to their individual types. Here are some
185+
scenarios where the Abstract Document design pattern can be applicable:
173186
174-
* 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.
187+
* Content Management Systems (CMS): In a CMS, you might have various types of content such as articles, images, videos,
188+
etc. Each type of content could have shared attributes like creation date, author, and tags, while also having
189+
specific attributes like image dimensions for images or video duration for videos.
175190
176-
* File Systems: If you're designing a file system where different types of files need to be managed, such as documents, images, audio files, and directories, the Abstract Document pattern can help provide a consistent way to access attributes like file size, creation date, etc., while allowing for specific attributes like image resolution or audio duration.
191+
* File Systems: If you're designing a file system where different types of files need to be managed, such as documents,
192+
images, audio files, and directories, the Abstract Document pattern can help provide a consistent way to access
193+
attributes like file size, creation date, etc., while allowing for specific attributes like image resolution or audio
194+
duration.
177195

178-
* E-commerce Systems: An e-commerce platform might have different product types such as physical products, digital downloads, and subscriptions. Each type could share common attributes like name, price, and description, while having unique attributes like shipping weight for physical products or download link for digital products.
196+
* E-commerce Systems: An e-commerce platform might have different product types such as physical products, digital
197+
downloads, and subscriptions. Each type could share common attributes like name, price, and description, while having
198+
unique attributes like shipping weight for physical products or download link for digital products.
179199

180-
* Medical Records Systems: In healthcare, patient records might include various types of data such as demographics, medical history, test results, and prescriptions. The Abstract Document pattern can help manage shared attributes like patient ID and date of birth, while accommodating specialized attributes like test results or prescribed medications.
200+
* Medical Records Systems: In healthcare, patient records might include various types of data such as demographics,
201+
medical history, test results, and prescriptions. The Abstract Document pattern can help manage shared attributes like
202+
patient ID and date of birth, while accommodating specialized attributes like test results or prescribed medications.
181203

182-
* Configuration Management: When dealing with configuration settings for software applications, there can be different types of configuration elements, each with its own set of attributes. The Abstract Document pattern can be used to manage these configuration elements while ensuring a consistent way to access and manipulate their attributes.
204+
* Configuration Management: When dealing with configuration settings for software applications, there can be different
205+
types of configuration elements, each with its own set of attributes. The Abstract Document pattern can be used to
206+
manage these configuration elements while ensuring a consistent way to access and manipulate their attributes.
183207

184-
* Educational Platforms: Educational systems might have various types of learning materials such as text-based content, videos, quizzes, and assignments. Common attributes like title, author, and publication date can be shared, while unique attributes like video duration or assignment due dates can be specific to each type.
208+
* Educational Platforms: Educational systems might have various types of learning materials such as text-based content,
209+
videos, quizzes, and assignments. Common attributes like title, author, and publication date can be shared, while
210+
unique attributes like video duration or assignment due dates can be specific to each type.
185211

186-
* Project Management Tools: In project management applications, you could have different types of tasks like to-do items, milestones, and issues. The Abstract Document pattern could be used to handle general attributes like task name and assignee, while allowing for specific attributes like milestone date or issue priority.
212+
* Project Management Tools: In project management applications, you could have different types of tasks like to-do
213+
items, milestones, and issues. The Abstract Document pattern could be used to handle general attributes like task name
214+
and assignee, while allowing for specific attributes like milestone date or issue priority.
187215

188216
* Documents have diverse and evolving attribute structures.
189217

@@ -193,7 +221,10 @@ This pattern is particularly useful in scenarios where you have different types
193221

194222
* Maintainability and flexibility are critical for the codebase.
195223

196-
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.
224+
The key idea behind the Abstract Document design pattern is to provide a flexible and extensible way to manage different
225+
types of documents or entities with shared and distinct attributes. By defining a common interface and implementing it
226+
across various document types, you can achieve a more organized and consistent approach to handling complex data
227+
structures.
197228

198229
## Consequences
199230

0 commit comments

Comments
 (0)