-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Aquí hay algunas sugerencias para que su código pueda cumplir con los principios SOLID.
// Interfaz para la generación del código secreto
public interface CodeGenerator {
String getSecretCode();
}
// Clase que implementa la interfaz CodeGenerator
public class GameFunctions implements CodeGenerator {
// Implementación de getSecretCode() de la interfaz CodeGenerator
// ...
}
// Interfaz para la lógica del juego
public interface GameAlgorithm {
void wellPiecesAlgo(String secretCode, String inputCode);
void misPiecesAlgo(String secretCode, String inputCode);
}
// Clase que implementa la interfaz GameAlgorithm
public class MastermindAlgorithm implements GameAlgorithm {
// Implementación de wellPiecesAlgo() y misPiecesAlgo() de la interfaz GameAlgorithm
// ...
}
// Clase GameController que sigue los principios SOLID
public class GameController {
private CodeGenerator codeGenerator;
private GameAlgorithm gameAlgorithm;
private int rounds;
public GameController(CodeGenerator codeGenerator, GameAlgorithm gameAlgorithm, int rounds) {
this.codeGenerator = codeGenerator;
this.gameAlgorithm = gameAlgorithm;
this.rounds = rounds;
}
public String getSecretCode() {
return this.codeGenerator.getSecretCode();
}
public int getRounds() {
return this.rounds;
}
public void initialize() {
// Lógica de inicialización (si es necesaria)
// ...
}
}