package com.jmj.pattern.strategy;
public interface Strategy {
void show();
}
package com.jmj.pattern.strategy;
public class StrategyA implements Strategy{
@Override
public void show() {
System.out.println("买一送一");
}
}
package com.jmj.pattern.strategy;
public class StrategyB implements Strategy{
@Override
public void show() {
System.out.println("买两百减五十");
}
}
package com.jmj.pattern.strategy;
public class StrategyC implements Strategy{
@Override
public void show() {
System.out.println("满1000加一元");
}
}
package com.jmj.pattern.strategy;
public class SalesMan {
private Strategy strategy;
public SalesMan(Strategy strategy) {
this.strategy = strategy;
}
public void salesManshow(){
strategy.show();
}
}
package com.jmj.pattern.strategy;
public class Client {
public static void main(String[] args) {
SalesMan salesMan = new SalesMan(new StrategyA());
salesMan.salesManshow();
}
}