forked from iluwatar/java-design-patterns
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DragonFacet.java
37 lines (32 loc) · 986 Bytes
/
DragonFacet.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package com.iluwatar.facet.dragon;
import com.iluwatar.facet.Attack;
import lombok.extern.slf4j.Slf4j;
/**
* The facet class which acts as an interface/wrapper for {@link Dragon}.
* It only allows access to the methods with names beginning
* with 'faceted', and also checks in receiveAttack() what
* the type of attack is, so that it can filter some illegal
* values.
*/
@Slf4j
public class DragonFacet {
private Dragon dragon;
public DragonFacet(Dragon dragon) {
this.dragon = dragon;
}
public int getHealth() {
return dragon.facetedGetHealth();
}
/**
* This performs a check of the attack, and for certain illegal values
* (namely FLAME_THROWER and SWORD), the attack will not even alert
* the dragon.
*
* @param attack The attack which is attempted against dragon
*/
public void receiveAttack(Attack attack) {
if (attack == Attack.WATER_PISTOL || attack == Attack.ARROW) {
dragon.facetedReceiveAttack(attack);
}
}
}