Skip to content

Commit b9b6777

Browse files
committed
Update README.md
1 parent 2a5b8c9 commit b9b6777

File tree

5 files changed

+29
-24
lines changed

5 files changed

+29
-24
lines changed

private-class-data/README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ tags:
99
---
1010

1111
## Intent
12+
1213
Private Class Data design pattern seeks to reduce exposure of attributes by limiting their
1314
visibility. It reduces the number of class attributes by encapsulating them in single Data object.
1415

@@ -124,9 +125,11 @@ immutableStew.mix(); // Mixing the immutable stew we find: 2 potatoes, 4 carrot
124125
```
125126

126127
## Class diagram
128+
127129
![alt text](./etc/private-class-data.png "Private Class Data")
128130

129131
## Applicability
132+
130133
Use the Private Class Data pattern when
131134

132-
* You want to prevent write access to class data members
135+
* You want to prevent write access to class data members.

promise/README.md

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,38 +14,41 @@ CompletableFuture
1414

1515
## Intent
1616

17-
A Promise represents a proxy for a value not necessarily known when the promise is created. It allows you to associate
18-
dependent promises to an asynchronous action's eventual success value or failure reason. Promises are a way to write
19-
async code that still appears as though it is executing in a synchronous way.
17+
A Promise represents a proxy for a value not necessarily known when the promise is created. It
18+
allows you to associate dependent promises to an asynchronous action's eventual success value or
19+
failure reason. Promises are a way to write async code that still appears as though it is executing
20+
in a synchronous way.
2021

2122
## Explanation
2223

23-
The Promise object is used for asynchronous computations. A Promise represents an operation that hasn't completed yet,
24-
but is expected in the future.
24+
The Promise object is used for asynchronous computations. A Promise represents an operation that
25+
hasn't completed yet, but is expected in the future.
2526

2627
Promises provide a few advantages over callback objects:
27-
* Functional composition and error handling
28-
* Prevents callback hell and provides callback aggregation
28+
* Functional composition and error handling.
29+
* Prevents callback hell and provides callback aggregation.
2930

3031
Real world example
3132

32-
> We are developing a software solution that downloads files and calculates the number of lines and character
33-
frequencies in those files. Promise is an ideal solution to make the code concise and easy to understand.
33+
> We are developing a software solution that downloads files and calculates the number of lines and
34+
> character frequencies in those files. Promise is an ideal solution to make the code concise and
35+
> easy to understand.
3436
3537
In plain words
3638

3739
> Promise is a placeholder for an asynchronous operation that is ongoing.
3840
3941
Wikipedia says
4042

41-
> In computer science, future, promise, delay, and deferred refer to constructs used for synchronizing program
42-
execution in some concurrent programming languages. They describe an object that acts as a proxy for a result that is
43-
initially unknown, usually because the computation of its value is not yet complete.
43+
> In computer science, future, promise, delay, and deferred refer to constructs used for
44+
> synchronizing program execution in some concurrent programming languages. They describe an object
45+
> that acts as a proxy for a result that is initially unknown, usually because the computation of
46+
> its value is not yet complete.
4447
4548
**Programmatic Example**
4649

47-
In the example a file is downloaded and its line count is calculated. The calculated line count is then consumed and
48-
printed on console.
50+
In the example a file is downloaded and its line count is calculated. The calculated line count is
51+
then consumed and printed on console.
4952

5053
Let's first introduce a support class we need for implementation. Here's `PromiseSupport`.
5154

@@ -195,7 +198,7 @@ public class Promise<T> extends PromiseSupport<T> {
195198

196199
public <V> Promise<V> thenApply(Function<? super T, V> func) {
197200
Promise<V> dest = new Promise<>();
198-
fulfillmentAction = new TransformAction<V>(this, dest, func);
201+
fulfillmentAction = new TransformAction<>(this, dest, func);
199202
return dest;
200203
}
201204

@@ -246,8 +249,8 @@ public class Promise<T> extends PromiseSupport<T> {
246249
}
247250
```
248251

249-
Now we can show the full example in action. Here's how to download and count the number of lines in a file using
250-
`Promise`.
252+
Now we can show the full example in action. Here's how to download and count the number of lines in
253+
a file using `Promise`.
251254

252255
```java
253256
countLines().thenAccept(
@@ -280,8 +283,8 @@ Now we can show the full example in action. Here's how to download and count the
280283

281284
## Applicability
282285

283-
Promise pattern is applicable in concurrent programming when some work needs to be done asynchronously
284-
and:
286+
Promise pattern is applicable in concurrent programming when some work needs to be done
287+
asynchronously and:
285288

286289
* Code maintainability and readability suffers due to callback hell.
287290
* You need to compose promises and need better error handling for asynchronous tasks.

promise/src/main/java/com/iluwatar/promise/App.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private App() {
8181
* @throws InterruptedException if main thread is interrupted.
8282
* @throws ExecutionException if an execution error occurs.
8383
*/
84-
public static void main(String[] args) throws InterruptedException, ExecutionException {
84+
public static void main(String[] args) throws InterruptedException {
8585
var app = new App();
8686
try {
8787
app.promiseUsage();

promise/src/main/java/com/iluwatar/promise/Promise.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ public Promise<T> onError(Consumer<? super Throwable> exceptionHandler) {
141141
*/
142142
public <V> Promise<V> thenApply(Function<? super T, V> func) {
143143
Promise<V> dest = new Promise<>();
144-
fulfillmentAction = new TransformAction<V>(this, dest, func);
144+
fulfillmentAction = new TransformAction<>(this, dest, func);
145145
return dest;
146146
}
147147

promise/src/main/java/com/iluwatar/promise/PromiseSupport.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import java.util.concurrent.ExecutionException;
2727
import java.util.concurrent.Future;
2828
import java.util.concurrent.TimeUnit;
29-
import java.util.concurrent.TimeoutException;
3029
import org.slf4j.Logger;
3130
import org.slf4j.LoggerFactory;
3231

@@ -114,4 +113,4 @@ public T get(long timeout, TimeUnit unit) throws ExecutionException {
114113
}
115114
throw new ExecutionException(exception);
116115
}
117-
}
116+
}

0 commit comments

Comments
 (0)