Skip to content

Commit 770a85e

Browse files
committed
docs: update abstract document readme
1 parent 02ae009 commit 770a85e

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

abstract-document/README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ Wikipedia says
3333

3434
> 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.
3535
36+
Class diagram
37+
38+
![Abstract Document class diagram](./etc/abstract-document.png "Abstract Document class diagram")
39+
40+
3641
## Programmatic Example of Abstract Document Pattern in Java
3742

3843
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.
@@ -119,6 +124,13 @@ public interface HasParts extends Document {
119124
return children(Property.PARTS.toString(), Part::new);
120125
}
121126
}
127+
128+
public class Part extends AbstractDocument implements HasType, HasModel, HasPrice {
129+
130+
public Part(Map<String, Object> properties) {
131+
super(properties);
132+
}
133+
}
122134
```
123135

124136
Now we are ready to introduce the `Car`.
@@ -179,10 +191,6 @@ The program output:
179191
07:21:57.395 [main] INFO com.iluwatar.abstractdocument.App -- door/Lambo/300
180192
```
181193
182-
## Abstract Document Pattern Class Diagram
183-
184-
![Abstract Document](./etc/abstract-document.png "Abstract Document Traits and Domain")
185-
186194
## When to Use the Abstract Document Pattern in Java
187195
188196
The Abstract Document design pattern is especially beneficial in scenarios requiring management of different document types in Java 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:

0 commit comments

Comments
 (0)