Сообщения

Сообщения за февраль, 2025

Strategy Design Pattern

package org.example; public interface Strategy { void actionCommand (); } package org.example; public class AggressiveStrategy implements Strategy { @Override public void actionCommand () { System. out .println( "Aggressive strategy. Find and kill opponent." ); } } package org.example; public class DefensiveStrategy implements Strategy { @Override public void actionCommand () { System. out .println( "Defensive strategy. Protect self and teammates." ); } } package org.example; public class Player { Strategy strategy ; String type ; public Player (String type) { this . type = type; } public void setStrategy (Strategy strategy) { this . strategy = strategy; } public void action () { System. out .println( "Player: " + this . type ); strategy .actionCommand(); } }   Another example: package org.example.example2; public interface PaymentStrategy { void...