forked from prmr/DesignBook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbstractMove.java
42 lines (37 loc) · 1.09 KB
/
AbstractMove.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
38
39
40
41
42
/*******************************************************************************
* Companion code for the book "Introduction to Software Design with Java"
* by Martin P. Robillard.
*
* Copyright (C) 2019 by Martin P. Robillard
*
* This code is licensed under a Creative Commons
* Attribution-NonCommercial-NoDerivatives 4.0 International License.
*
* See http://creativecommons.org/licenses/by-nc-nd/4.0/
*******************************************************************************/
package chapter7;
/**
* Root class for all moves that require a reference
* to the GameModel. Method perform() fulfills the role
* of the Template Method in an application of the Template
* Method design pattern.
*/
public abstract class AbstractMove implements Move
{
protected final GameModel aModel;
protected AbstractMove(GameModel pModel)
{
aModel = pModel;
}
public final void perform()
{
aModel.push(this);
execute();
log();
}
protected abstract void execute();
private void log()
{
System.out.println(getClass().getName());
}
}