/**
* Copyright (C) 2022 by Martin Robillard. See https://codesample.info/about.html
*/
package e2.chapter7;
/**
* Skeleton of a class that encapsulates the move of a
* card between two piles in Solitaire. Sample concrete
* class that extends an abstract class and plays a role
* in the Template Method design pattern.
*/
public class CardMove extends AbstractMove {
/**
* In practice this would also need to accept the source
* and destination piles.
*
* @param pModel The game model on which the move is performed.
*/
public CardMove(GameModel pModel) {
super(pModel);
}
@Override
public void undo() {
/* Undo the move */
}
@Override
protected void execute() {
/* Execute the move */
}
}
Declaring the class final
ensures that it cannot be subclassed.
Chapter 7, insight #15
If there is no scenario for overriding a method, consider declaring it final
. Similarly, if there is no specific reason for a class to be extensible using inheritance, consider declaring it final
.
Declaring the class final
ensures that it cannot be subclassed.
Chapter 7, insight #15
If there is no scenario for overriding a method, consider declaring it final
. Similarly, if there is no specific reason for a class to be extensible using inheritance, consider declaring it final
.