Concept: defines a series of algorithms that encapsulate each algorithm and can be used to replace each other, and the policy pattern makes the algorithm independent of the client application that uses it.
The interface abstraction is a method.
oo Design principles : 1. Interface-oriented Programming 2. Package changes 3. Multi-use combination, less inheritance
1 Public classPractice14 {2 3 Public Static voidMain (string[] args) {4 //TODO auto-generated Method Stub5 //to point to a subclass object with a reference to the parent class6Bird d=NewBigbird ("Little white");7D.SETF (NewFly ());8 d.fly ();9Bird d1=NewBigbird ("Little Black");TenD1.SETF (Newnofly ()); One d1.fly (); A } - } - //Interface the Interfaceflytype{ - voidfly (); - } - + classFlyImplementsflytype{ - Public voidFly () { +System.out.println ("I Can Fly"); A } at } - classNoflyImplementsflytype{ - Public voidFly () { -System.out.println ("I Can't Fly"); - } - } in //Abstract class - Abstract classbird{ to PrivateString name; + PrivateFlytype F;//Combination - PublicBird (String name) { the This. name=name; * } $ PublicFlytype getf () {Panax Notoginseng returnF; - } the Public voidsetf (Flytype f) { + This. F =F; A } the Public voidFly () { +System.out.println ("My name is called" +name); - f.fly (); $ } $ - } - the classBigbirdextendsbird{ - PublicBigbird (String name) {Wuyi Super(name); the } - } Wu classModelbirdextendsbird{ - PublicModelbird (String name) { About Super(name); $ } -}
Java object-oriented interface application--strategy mode