@@ -19,7 +19,7 @@ Decouple an abstraction from its implementation so that the two can vary indepen
19
19
20
20
## Explanation
21
21
22
- Real world example
22
+ Real- world example
23
23
24
24
> Consider you have a weapon with different enchantments, and you are supposed to allow mixing
25
25
> different weapons with different enchantments. What would you do? Create multiple copies of each
@@ -161,27 +161,36 @@ public class SoulEatingEnchantment implements Enchantment {
161
161
Here are both hierarchies in action:
162
162
163
163
``` java
164
+ LOGGER . info(" The knight receives an enchanted sword." );
164
165
var enchantedSword = new Sword (new SoulEatingEnchantment ());
165
166
enchantedSword. wield();
166
167
enchantedSword. swing();
167
168
enchantedSword. unwield();
168
- // The sword is wielded.
169
- // The item spreads bloodlust.
170
- // The sword is swinged.
171
- // The item eats the soul of enemies.
172
- // The sword is unwielded.
173
- // Bloodlust slowly disappears.
174
169
170
+ LOGGER . info(" The valkyrie receives an enchanted hammer." );
175
171
var hammer = new Hammer (new FlyingEnchantment ());
176
172
hammer. wield();
177
173
hammer. swing();
178
174
hammer. unwield();
179
- // The hammer is wielded.
180
- // The item begins to glow faintly.
181
- // The hammer is swinged.
182
- // The item flies and strikes the enemies finally returning to owner's hand.
183
- // The hammer is unwielded.
184
- // The item's glow fades.
175
+ ```
176
+
177
+ Here's the console output.
178
+
179
+ ```
180
+ The knight receives an enchanted sword.
181
+ The sword is wielded.
182
+ The item spreads bloodlust.
183
+ The sword is swung.
184
+ The item eats the soul of enemies.
185
+ The sword is unwielded.
186
+ Bloodlust slowly disappears.
187
+ The valkyrie receives an enchanted hammer.
188
+ The hammer is wielded.
189
+ The item begins to glow faintly.
190
+ The hammer is swung.
191
+ The item flies and strikes the enemies finally returning to owner's hand.
192
+ The hammer is unwielded.
193
+ The item's glow fades.
185
194
```
186
195
187
196
## Class diagram
0 commit comments