lundi 29 juin 2020

Strategy Pattern and context class

Reading about the strategy design pattern, was thinking if it is possible to have two context.

Looking forward for opinions if the below code-design utilises the Strategy design pattern.

Or strategy design pattern forces us to have only one context meaning that the design below is incorrect.

public interface Algorithm {}
public class FirstAlgorithm implements Algorithm {}
public class SecondAlgorithm implements Algorithm {}


public interface Cryptography {}

public class DecryptionContext implements Cryptography {
    public DecryptionContext(Algorithm algorithm) {
        this.algorithm = algorithm;
    }
}

public class EncryptionContext implements Cryptography {
public EncryptionContext(Algorithm algorithm) {
        this.algorithm = algorithm;
    }

}

Aucun commentaire:

Enregistrer un commentaire