Skip to content

Commit 7e775f3

Browse files
authored
Merge branch 'master' into master
2 parents e704103 + f0611bc commit 7e775f3

File tree

1,118 files changed

+33358
-21044
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,118 files changed

+33358
-21044
lines changed

Diff for: .all-contributorsrc

+88-4
Original file line numberDiff line numberDiff line change
@@ -1548,7 +1548,8 @@
15481548
"avatar_url": "https://avatars.githubusercontent.com/u/17254162?v=4",
15491549
"profile": "https://www.linkedin.com/in/souzasamuel/",
15501550
"contributions": [
1551-
"code"
1551+
"code",
1552+
"doc"
15521553
]
15531554
},
15541555
{
@@ -2546,7 +2547,7 @@
25462547
"login": "tiennm99",
25472548
"name": "Tien Nguyen Minh",
25482549
"avatar_url": "https://avatars.githubusercontent.com/u/39063457?v=4",
2549-
"profile": "http://miti99.dev",
2550+
"profile": "https://github.com/tiennm99",
25502551
"contributions": [
25512552
"code",
25522553
"translation"
@@ -2992,7 +2993,8 @@
29922993
"avatar_url": "https://avatars.githubusercontent.com/u/44934142?v=4",
29932994
"profile": "https://github.com/luismateoh",
29942995
"contributions": [
2995-
"translation"
2996+
"translation",
2997+
"review"
29962998
]
29972999
},
29983000
{
@@ -3057,9 +3059,91 @@
30573059
"contributions": [
30583060
"code"
30593061
]
3062+
},
3063+
{
3064+
"login": "DavidMedinaO",
3065+
"name": "David Medina Orozco",
3066+
"avatar_url": "https://avatars.githubusercontent.com/u/53974843?v=4",
3067+
"profile": "https://github.com/DavidMedinaO",
3068+
"contributions": [
3069+
"translation",
3070+
"review"
3071+
]
3072+
},
3073+
{
3074+
"login": "Romo4ka-bot",
3075+
"name": "Roman Leontev",
3076+
"avatar_url": "https://avatars.githubusercontent.com/u/61774094?v=4",
3077+
"profile": "https://github.com/Romo4ka-bot",
3078+
"contributions": [
3079+
"code"
3080+
]
3081+
},
3082+
{
3083+
"login": "Ehspresso",
3084+
"name": "Riley",
3085+
"avatar_url": "https://avatars.githubusercontent.com/u/144370752?v=4",
3086+
"profile": "https://github.com/Ehspresso",
3087+
"contributions": [
3088+
"code"
3089+
]
3090+
},
3091+
{
3092+
"login": "k1w1dev",
3093+
"name": "k1w1dev",
3094+
"avatar_url": "https://avatars.githubusercontent.com/u/121696782?v=4",
3095+
"profile": "https://github.com/k1w1dev",
3096+
"contributions": [
3097+
"code"
3098+
]
3099+
},
3100+
{
3101+
"login": "dev-yugantar",
3102+
"name": "dev-yugantar",
3103+
"avatar_url": "https://avatars.githubusercontent.com/u/153066190?v=4",
3104+
"profile": "https://github.com/dev-yugantar",
3105+
"contributions": [
3106+
"code"
3107+
]
3108+
},
3109+
{
3110+
"login": "Adelechka",
3111+
"name": "Adelya",
3112+
"avatar_url": "https://avatars.githubusercontent.com/u/65678470?v=4",
3113+
"profile": "https://github.com/Adelechka",
3114+
"contributions": [
3115+
"code"
3116+
]
3117+
},
3118+
{
3119+
"login": "gatlanagaprasanna",
3120+
"name": "gatlanagaprasanna",
3121+
"avatar_url": "https://avatars.githubusercontent.com/u/154739216?v=4",
3122+
"profile": "https://github.com/gatlanagaprasanna",
3123+
"contributions": [
3124+
"doc"
3125+
]
3126+
},
3127+
{
3128+
"login": "Avinash2110",
3129+
"name": "Avinash Shukla",
3130+
"avatar_url": "https://avatars.githubusercontent.com/u/37360069?v=4",
3131+
"profile": "https://github.com/Avinash2110",
3132+
"contributions": [
3133+
"code"
3134+
]
3135+
},
3136+
{
3137+
"login": "Mayankchoudhary294",
3138+
"name": "Mayank Choudhary",
3139+
"avatar_url": "https://avatars.githubusercontent.com/u/97609699?v=4",
3140+
"profile": "https://github.com/Mayankchoudhary294",
3141+
"contributions": [
3142+
"code"
3143+
]
30603144
}
30613145
],
3062-
"contributorsPerLine": 7,
3146+
"contributorsPerLine": 6,
30633147
"projectName": "java-design-patterns",
30643148
"projectOwner": "iluwatar",
30653149
"repoType": "github",

Diff for: .gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,5 @@ build/
5757
#################### Java Design Patterns #######
5858
etc/Java Design Patterns.urm.puml
5959
serialized-entity/output.txt
60+
fish1.out
61+
fish2.out

Diff for: CONTRIBUTING.MD

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
This is great you have something to contribute!
1+
The project guidelines can be found in [Java Design Patterns developer wiki](https://github.com/iluwatar/java-design-patterns/wiki).
22

3-
Before going any further please read the [wiki](https://github.com/iluwatar/java-design-patterns/wiki)
4-
with conventions and rules we used for this project.
3+
A good place to start is: https://github.com/iluwatar/java-design-patterns/wiki/01.-How-to-contribute

Diff for: LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright © 2014-2021 Ilkka Seppälä
3+
Copyright 2014-2024 Ilkka Seppälä
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

Diff for: README.md

+478-464
Large diffs are not rendered by default.

Diff for: abstract-document/README.md

+58-43
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@ category: Structural
44
language: en
55
tag:
66
- Abstraction
7-
- Extensibility
87
- Decoupling
8+
- Dynamic typing
9+
- Encapsulation
10+
- Extensibility
11+
- Polymorphism
912
---
1013

1114
## Intent
@@ -16,9 +19,9 @@ The Abstract Document design pattern is a structural design pattern that aims to
1619

1720
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.
1821

19-
Real world example
22+
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+
> Imagine a library system where books can have different formats and attributes: physical books, eBooks, and audiobooks. Each format has unique properties, such as page count for physical books, file size for eBooks, and duration for audiobooks. The Abstract Document design pattern allows the library system to manage these diverse formats flexibly. By using this pattern, the system can store and retrieve properties dynamically, without needing a rigid structure for each book type, making it easier to add new formats or attributes in the future without significant changes to the codebase.
2225
2326
In plain words
2427

@@ -30,6 +33,8 @@ Wikipedia says
3033
3134
**Programmatic Example**
3235

36+
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.
37+
3338
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.
3439

3540
```java
@@ -72,7 +77,8 @@ public abstract class AbstractDocument implements Document {
7277
.flatMap(Collection::stream)
7378
.map(constructor);
7479
}
75-
...
80+
81+
// Other properties and methods...
7682
}
7783
```
7884

@@ -127,47 +133,53 @@ public class Car extends AbstractDocument implements HasModel, HasPrice, HasPart
127133
And finally here's how we construct and use the `Car` in a full example.
128134
129135
```java
136+
public static void main(String[] args) {
130137
LOGGER.info("Constructing parts and car");
131138
132-
var wheelProperties=Map.of(
133-
Property.TYPE.toString(),"wheel",
134-
Property.MODEL.toString(),"15C",
135-
Property.PRICE.toString(),100L);
136-
137-
var doorProperties=Map.of(
138-
Property.TYPE.toString(),"door",
139-
Property.MODEL.toString(),"Lambo",
140-
Property.PRICE.toString(),300L);
141-
142-
var carProperties=Map.of(
143-
Property.MODEL.toString(),"300SL",
144-
Property.PRICE.toString(),10000L,
145-
Property.PARTS.toString(),List.of(wheelProperties,doorProperties));
146-
147-
var car=new Car(carProperties);
148-
149-
LOGGER.info("Here is our car:");
150-
LOGGER.info("-> model: {}",car.getModel().orElseThrow());
151-
LOGGER.info("-> price: {}",car.getPrice().orElseThrow());
152-
LOGGER.info("-> parts: ");
153-
car.getParts().forEach(p->LOGGER.info("\t{}/{}/{}",
154-
p.getType().orElse(null),
155-
p.getModel().orElse(null),
156-
p.getPrice().orElse(null))
157-
);
158-
159-
// Constructing parts and car
160-
// Here is our car:
161-
// model: 300SL
162-
// price: 10000
163-
// parts:
164-
// wheel/15C/100
165-
// door/Lambo/300
139+
var wheelProperties = Map.of(
140+
Property.TYPE.toString(), "wheel",
141+
Property.MODEL.toString(), "15C",
142+
Property.PRICE.toString(), 100L);
143+
144+
var doorProperties = Map.of(
145+
Property.TYPE.toString(), "door",
146+
Property.MODEL.toString(), "Lambo",
147+
Property.PRICE.toString(), 300L);
148+
149+
var carProperties = Map.of(
150+
Property.MODEL.toString(), "300SL",
151+
Property.PRICE.toString(), 10000L,
152+
Property.PARTS.toString(), List.of(wheelProperties, doorProperties));
153+
154+
var car = new Car(carProperties);
155+
156+
LOGGER.info("Here is our car:");
157+
LOGGER.info("-> model: {}", car.getModel().orElseThrow());
158+
LOGGER.info("-> price: {}", car.getPrice().orElseThrow());
159+
LOGGER.info("-> parts: ");
160+
car.getParts().forEach(p -> LOGGER.info("\t{}/{}/{}",
161+
p.getType().orElse(null),
162+
p.getModel().orElse(null),
163+
p.getPrice().orElse(null))
164+
);
165+
}
166+
```
167+
168+
The program output:
169+
170+
```
171+
07:21:57.391 [main] INFO com.iluwatar.abstractdocument.App -- Constructing parts and car
172+
07:21:57.393 [main] INFO com.iluwatar.abstractdocument.App -- Here is our car:
173+
07:21:57.393 [main] INFO com.iluwatar.abstractdocument.App -- -> model: 300SL
174+
07:21:57.394 [main] INFO com.iluwatar.abstractdocument.App -- -> price: 10000
175+
07:21:57.394 [main] INFO com.iluwatar.abstractdocument.App -- -> parts:
176+
07:21:57.395 [main] INFO com.iluwatar.abstractdocument.App -- wheel/15C/100
177+
07:21:57.395 [main] INFO com.iluwatar.abstractdocument.App -- door/Lambo/300
166178
```
167179
168180
## Class diagram
169181
170-
![alt text](./etc/abstract-document.png "Abstract Document Traits and Domain")
182+
![Abstract Document](./etc/abstract-document.png "Abstract Document Traits and Domain")
171183
172184
## Applicability
173185
@@ -199,7 +211,7 @@ The key idea behind the Abstract Document design pattern is to provide a flexibl
199211

200212
## Consequences
201213

202-
Benefits
214+
Benefits:
203215

204216
* Flexibility: Accommodates varied document structures and properties.
205217

@@ -209,14 +221,17 @@ Benefits
209221

210222
* Reusability: Typed views enable code reuse for accessing specific attribute types.
211223

212-
Trade-offs
224+
Trade-offs:
213225

214226
* Complexity: Requires defining interfaces and views, adding implementation overhead.
215227

216228
* Performance: Might introduce slight performance overhead compared to direct data access.
217229

218230
## Credits
219231

220-
* [Wikipedia: Abstract Document Pattern](https://en.wikipedia.org/wiki/Abstract_Document_Pattern)
221-
* [Martin Fowler: Dealing with properties](http://martinfowler.com/apsupp/properties.pdf)
232+
* [Design Patterns: Elements of Reusable Object-Oriented Software](https://amzn.to/3w0pvKI)
233+
* [Java Design Patterns: A Hands-On Experience with Real-World Examples](https://amzn.to/3yhh525)
222234
* [Pattern-Oriented Software Architecture Volume 4: A Pattern Language for Distributed Computing (v. 4)](https://amzn.to/49zRP4R)
235+
* [Patterns of Enterprise Application Architecture](https://amzn.to/3WfKBPR)
236+
* [Abstract Document Pattern (Wikipedia)](https://en.wikipedia.org/wiki/Abstract_Document_Pattern)
237+
* [Dealing with Properties (Martin Fowler)](http://martinfowler.com/apsupp/properties.pdf)

0 commit comments

Comments
 (0)