mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-05-19 01:26:35 +00:00
docs: fix line endings
This commit is contained in:
@@ -10,15 +10,11 @@ tag:
|
||||
|
||||
## Intent
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
## Explanation
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
Real world example
|
||||
|
||||
@@ -30,16 +26,11 @@ In plain words
|
||||
|
||||
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.
|
||||
> 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.
|
||||
|
||||
**Programmatic Example**
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
```java
|
||||
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
|
||||
static looking interface to our `Car` class.
|
||||
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.
|
||||
|
||||
```java
|
||||
public enum Property {
|
||||
@@ -179,9 +169,7 @@ And finally here's how we construct and use the `Car` in a full example.
|
||||
|
||||
## Applicability
|
||||
|
||||
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:
|
||||
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:
|
||||
|
||||
* 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.
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
## Consequences
|
||||
|
||||
|
||||
Reference in New Issue
Block a user