What is this?
The template Method is a behavioural design pattern that defines the skeleton of an algorithm in the superclass but lets subclasses override specific steps of the algorithm without changing its structure.
In a simple game, different types of characters move around on a grid fighting each other. When one character moves into the square occupied by another they attack that character and inflict damage based on random chance (e.g. a dice roll).
Use a Template Strategy to model a solution to this problem. The code has been started for you inside the Character
class.
Decorator is a structural design pattern that lets you attach new behaviors to objects by placing these objects inside special wrapper objects that contain the behaviors.
component.operation()
)addBehaviour()
to be performed before and/or after forwarding a request)public interface Component {
void doOperationA();
void doOperationB();
}
public class ConcreteComponent implements Component {
@Override
void doOperationA();
@Override
void doOperationB();
}
public abstract class Decorator implements Component {
private ConcreteComponent cc;
}
public class ConcreteDecoratorX extends Decorator {}
This exercise continues on from Exercise A.
Suppose a requirements change was introduce that necessitated support for different sorts of armour.
There are no restrictions on the number of pieces of armour a character can wear and that the "order" in which armour is worn affects how it works. You may need to make a small change to the existing code.