diff --git a/abstract-document/README.md b/abstract-document/README.md index 1dd521c73..56f8e775c 100644 --- a/abstract-document/README.md +++ b/abstract-document/README.md @@ -33,6 +33,11 @@ Wikipedia says > 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. +Class diagram + +![Abstract Document class diagram](./etc/abstract-document.png "Abstract Document class diagram") + + ## Programmatic Example of Abstract Document Pattern in Java 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 { return children(Property.PARTS.toString(), Part::new); } } + +public class Part extends AbstractDocument implements HasType, HasModel, HasPrice { + + public Part(Map properties) { + super(properties); + } +} ``` Now we are ready to introduce the `Car`. @@ -179,10 +191,6 @@ The program output: 07:21:57.395 [main] INFO com.iluwatar.abstractdocument.App -- door/Lambo/300 ``` -## Abstract Document Pattern Class Diagram - -![Abstract Document](./etc/abstract-document.png "Abstract Document Traits and Domain") - ## When to Use the Abstract Document Pattern in Java 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: