design_model(15)Strategy

1.Policy pattern: The policy container does not know the details of the internal policy, because the container does not implement the same interface as the internal policy, that is, the container and the internal policy is simply a combination relationship, the container only extracts the behavior of the internal policy, and carries out a unified implementation.

2.Example

public interface Client {
    public abstract void test() ;
}

public class Big   implements  Client{

	@Override
	public void test() {
		System.out.println("3Fold ");}}Public class Min implements Client{@OverridePublic void test () {System.out.println ("10 percent off");}}Public class Strategy {Private Client client;Public void tesT () {Client.test ();}Public Strategy (Client client) {Super ();This.client = client;}}Public class Test {Public static void main (String[] args) {Strategy stratege =New Strategy (New Big ());Stratege.test ();}}

 

Leave a Reply

Your email address will not be published. Required fields are marked *