Waveform.java
/*** Book: Thinking in Java * Features: Fully decoupled, policy design mode * here the Apply.process () method can accept any type of processor, apply it to an object, and then print the result * File: apply.java* Time: April 2, 2015 16:50:55* Author: Cutter_point*/package Lesson9interfaces.filters;public class Waveform {private Static long counter;//default initialized to 0private final long id = counter++;//First assigns a value to the ID 0public String toString () {return "waveform" + ID; }}
Filter.java
/*** Book: Thinking in Java * Features: Fully decoupled, policy design mode * here the Apply.process () method can accept any type of processor, apply it to an object, and then print the result * File: filter.java* Time: April 2, 2015 20:03:00* Author: Cutter_point*/package Lesson9interfaces.filters;public class Filter {public String name () {return This.getclass (). Getsimplename ();} Public waveform process (waveform input) {return input;} Remember, please add public}
Lowpass.java
/*** Book: Thinking in Java * Features: Fully decoupled, policy design mode * here the Apply.process () method can accept any type of processor, apply it to an object, and then print the result * File: lowpass.java* Time: April 2, 2015 20:04:46* Author: Cutter_point*/package Lesson9interfaces.filters;public class LowPass extends Filter {double cutoff;public lowpass (double cutoff) {This.cutoff = cutoff;} Public waveform process (waveform input) {return input;}}
Highpass.java
/*** Book: Thinking in Java * Features: Fully decoupled, policy design mode * here the Apply.process () method can accept any type of processor, apply it to an object, and then print the result * File: highpass.java* Time: April 2, 2015 20:07:46* Author: Cutter_point*/package Lesson9interfaces.filters;public class HighPass Extends Filter {double cutoff;public highpass (double cutoff) {This.cutoff = cutoff;} Public waveform process (waveform input) {return input;}}
Bandpass.java
/*** Book: Thinking in Java * Features: Fully decoupled, policy design mode * here the Apply.process () method can accept any type of processor, apply it to an object, and then print the result * File: bandpass.java* Time: April 2, 2015 20:07:46* Author: Cutter_point*/package Lesson9interfaces.filters;public class BandPass Extends Filter {double Lowcutoff, highcutoff;public bandpass (double lowcut, double highcut) {This.lowcutoff = Lowcut;this . Highcutoff = Highcut;} Public waveform process (waveform input) {return input;}} /* * This coupling with the previous process is particularly tight * */
Output:
Wind (). Play () Middle_c obj1
Percussion (). Play () Middle_c obj1
Stringed (). Play () Middle_c obj1
Brass.play () Middle_c obj1
Woodwind.play () Middle_c obj1
This seems to fit apply.process (), also in the "Thinkinginjava" 10 inside of that class, I have, http://blog.csdn.net/cutter_point/article/details/45098003
In the following article, we continue to compare this class with the previous apply class, which looks similar,
But you can't put
Filter for the Apply.process () method, even if you can run
"Thinkinginjava" 12, fully decoupled, strategy design mode (2)