Am I violating Open Closed Principle ?

public class ShadowBeast extends Actor {
private Map<Integer, Behaviour> activityPriorities = new TreeMap<>();

public ShadowBeast() {
super("Shadow Beast", 'b', 75);
activityPriorities.put(0, new AmbushBehaviour()); // Add behaviour with priority 0
activityPriorities.put(1, new ProwlBehaviour()); // Add behaviour with priority 1
}

/**
* Selects and returns an action for the ShadowBeast's turn.
* Iterates through its behaviours based on priority.
*
* @param actions Collection of possible Actions for this Actor
* @param map The map containing the Actor
* @return The Action to be performed, or DontDoAnythingAction
*/
@Override
public Action playTurn(ActionList actions, Action lastAction, GameMap map, Display display) {
for (Behaviour currentActivity : activityPriorities.values()) {
Action action = currentActivity.getAction(this, map);
if (action != null) {
return action;
}
}
// No suitable behaviour found
return new DontDoAnythingAction();
public class ShadowBeast extends Actor {
private Map<Integer, Behaviour> activityPriorities = new TreeMap<>();

public ShadowBeast() {
super("Shadow Beast", 'b', 75);
activityPriorities.put(0, new AmbushBehaviour()); // Add behaviour with priority 0
activityPriorities.put(1, new ProwlBehaviour()); // Add behaviour with priority 1
}

/**
* Selects and returns an action for the ShadowBeast's turn.
* Iterates through its behaviours based on priority.
*
* @param actions Collection of possible Actions for this Actor
* @param map The map containing the Actor
* @return The Action to be performed, or DontDoAnythingAction
*/
@Override
public Action playTurn(ActionList actions, Action lastAction, GameMap map, Display display) {
for (Behaviour currentActivity : activityPriorities.values()) {
Action action = currentActivity.getAction(this, map);
if (action != null) {
return action;
}
}
// No suitable behaviour found
return new DontDoAnythingAction();
Essentially, is it a violation of open closed principle if I am putting in new behaviours ?
1 Reply
JavaBot
JavaBot14h ago
This post has been reserved for your question.
Hey @flowi! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically marked as dormant after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

Did you find this page helpful?