mirror of
https://github.com/tiennm99/java-design-patterns.git
synced 2026-08-20 06:23:48 +00:00
docs: update abstract document
This commit is contained in:
+27
-20
@@ -77,7 +77,8 @@ public abstract class AbstractDocument implements Document {
|
|||||||
.flatMap(Collection::stream)
|
.flatMap(Collection::stream)
|
||||||
.map(constructor);
|
.map(constructor);
|
||||||
}
|
}
|
||||||
...
|
|
||||||
|
// Other properties and methods...
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -132,30 +133,36 @@ public class Car extends AbstractDocument implements HasModel, HasPrice, HasPart
|
|||||||
And finally here's how we construct and use the `Car` in a full example.
|
And finally here's how we construct and use the `Car` in a full example.
|
||||||
|
|
||||||
```java
|
```java
|
||||||
LOGGER.info("Constructing parts and car");
|
public static void main(String[] args) {
|
||||||
|
LOGGER.info("Constructing parts and car");
|
||||||
|
|
||||||
var wheelProperties = Map.of(
|
var wheelProperties = Map.of(
|
||||||
Property.TYPE.toString(), "wheel",
|
Property.TYPE.toString(), "wheel",
|
||||||
Property.MODEL.toString(), "15C",
|
Property.MODEL.toString(), "15C",
|
||||||
Property.PRICE.toString(), 100L);
|
Property.PRICE.toString(), 100L);
|
||||||
|
|
||||||
var doorProperties = Map.of(
|
var doorProperties = Map.of(
|
||||||
Property.TYPE.toString(), "door",
|
Property.TYPE.toString(), "door",
|
||||||
Property.MODEL.toString(), "Lambo",
|
Property.MODEL.toString(), "Lambo",
|
||||||
Property.PRICE.toString(), 300L);
|
Property.PRICE.toString(), 300L);
|
||||||
|
|
||||||
var carProperties = Map.of(
|
var carProperties = Map.of(
|
||||||
Property.MODEL.toString(), "300SL",
|
Property.MODEL.toString(), "300SL",
|
||||||
Property.PRICE.toString(), 10000L,
|
Property.PRICE.toString(), 10000L,
|
||||||
Property.PARTS.toString(), List.of(wheelProperties, doorProperties));
|
Property.PARTS.toString(), List.of(wheelProperties, doorProperties));
|
||||||
|
|
||||||
var car = new Car(carProperties);
|
var car = new Car(carProperties);
|
||||||
|
|
||||||
LOGGER.info("Here is our car:");
|
LOGGER.info("Here is our car:");
|
||||||
LOGGER.info("-> model: {}", car.getModel().orElseThrow());
|
LOGGER.info("-> model: {}", car.getModel().orElseThrow());
|
||||||
LOGGER.info("-> price: {}", car.getPrice().orElseThrow());
|
LOGGER.info("-> price: {}", car.getPrice().orElseThrow());
|
||||||
LOGGER.info("-> parts: ");
|
LOGGER.info("-> parts: ");
|
||||||
car.getParts().forEach(p -> LOGGER.info("\t{}/{}/{}", p.getType().orElse(null), p.getModel().orElse(null), p.getPrice().orElse(null)));
|
car.getParts().forEach(p -> LOGGER.info("\t{}/{}/{}",
|
||||||
|
p.getType().orElse(null),
|
||||||
|
p.getModel().orElse(null),
|
||||||
|
p.getPrice().orElse(null))
|
||||||
|
);
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
The program output:
|
The program output:
|
||||||
|
|||||||
Reference in New Issue
Block a user