"Thinkinginjava" 12, fully decoupled, strategy design mode (2)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.