//main๋งค์๋
package Chap_08;
import Chap_08.Camera.SpeedCam;
import Chap_08.detector.AccidentDetector;
import Chap_08.reporter.VideoReporter;
public class _Quiz_08 {
public static void main(String[] args) {
SpeedCam speedCam = new SpeedCam();
speedCam.setDetector(new AccidentDetector());
speedCam.setReporter(new VideoReporter());
speedCam.detect();
speedCam.report();
}
}
package Chap_08.detector;
public class AccidentDetector implements Detectable {
@Override
public void detect() {
System.out.println("๊ตํต ์ฌ๊ณ ๋ฅผ ๊ฐ์งํฉ๋๋ค.");
}
}
package Chap_08.Camera;
import Chap_08.detector.AccidentDetector;
import Chap_08.detector.Detectable;
import Chap_08.reporter.Reportable;
import Chap_08.reporter.VideoReporter;
public class SpeedCam extends Camera implements Detectable, Reportable {
public AccidentDetector accidentDetector;
public VideoReporter videoReporter;
@Override
public void showMainFeature() {
System.out.println("์๋ ์ธก์ , ๋ฒํธ ์ธ์");
}
@Override
public void detect() {
accidentDetector.detect();
}
@Override
public void report() {
videoReporter.report();
}
//์ธ์๋ก ๋ค์ด์จ ๋
์์ ์ด๋ฒ ๊ฐ์ฒด์ accidentDetector๋ผ๋ ๋ณ์์ ๋ฃ์ด๋ผ
public void setDetector(AccidentDetector accidentDetector) {
this.accidentDetector = accidentDetector;
}
public void setReporter(VideoReporter videoReporter) {
this.videoReporter = videoReporter;
}
}
package Chap_08.reporter;
public class VideoReporter implements Reportable{
@Override
public void report() {
System.out.println("์ง์ 30์ด ์์๊ณผ ํจ๊ป ์ ๊ณ ๋ฅผ ์งํํฉ๋๋ค.");
}
}
//์ธํฐํ์ด์ค๋ค
package Chap_08.detector;
public interface Detectable {
void detect(); // ํ์ฌ ๊ฐ์ง
}
package Chap_08.reporter;
public interface Reportable {
void report(); //์ ๊ณ ๊ธฐ๋ฅ
}
0