Observer Pattern (use Observable)

This commit is contained in:
kim
2021-01-17 23:07:00 +09:00
parent 3b7ff5babe
commit 8f907de6ff
34 changed files with 101 additions and 70 deletions

View File

@@ -1,4 +0,0 @@
package AbstractFactory.abst;
public interface Body {
}

View File

@@ -1,4 +0,0 @@
package AbstractFactory.abst;
public interface Wheel {
}

View File

@@ -1,10 +1,9 @@
package AbstractFactory; package AbstractFactory.example01;
import AbstractFactory.abst.BikeFactory; import AbstractFactory.example01.abst.BikeFactory;
import AbstractFactory.abst.Body; import AbstractFactory.example01.abst.Body;
import AbstractFactory.abst.Wheel; import AbstractFactory.example01.abst.Wheel;
import AbstractFactory.gt.GtBikeFactory; import AbstractFactory.example01.gt.GtBikeFactory;
import AbstractFactory.sam.SamFactory;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {

View File

@@ -1,4 +1,4 @@
package AbstractFactory.abst; package AbstractFactory.example01.abst;
public interface BikeFactory { public interface BikeFactory {

View File

@@ -0,0 +1,4 @@
package AbstractFactory.example01.abst;
public interface Body {
}

View File

@@ -0,0 +1,4 @@
package AbstractFactory.example01.abst;
public interface Wheel {
}

View File

@@ -1,8 +1,8 @@
package AbstractFactory.gt; package AbstractFactory.example01.gt;
import AbstractFactory.abst.BikeFactory; import AbstractFactory.example01.abst.BikeFactory;
import AbstractFactory.abst.Body; import AbstractFactory.example01.abst.Body;
import AbstractFactory.abst.Wheel; import AbstractFactory.example01.abst.Wheel;
public class GtBikeFactory implements BikeFactory { public class GtBikeFactory implements BikeFactory {
@Override @Override

View File

@@ -0,0 +1,6 @@
package AbstractFactory.example01.gt;
import AbstractFactory.example01.abst.Body;
public class GtBody implements Body {
}

View File

@@ -0,0 +1,6 @@
package AbstractFactory.example01.gt;
import AbstractFactory.example01.abst.Wheel;
public class GtWheel implements Wheel {
}

View File

@@ -0,0 +1,6 @@
package AbstractFactory.example01.sam;
import AbstractFactory.example01.abst.Body;
public class SamBody implements Body {
}

View File

@@ -1,8 +1,8 @@
package AbstractFactory.sam; package AbstractFactory.example01.sam;
import AbstractFactory.abst.BikeFactory; import AbstractFactory.example01.abst.BikeFactory;
import AbstractFactory.abst.Body; import AbstractFactory.example01.abst.Body;
import AbstractFactory.abst.Wheel; import AbstractFactory.example01.abst.Wheel;
public class SamFactory implements BikeFactory { public class SamFactory implements BikeFactory {
@Override @Override

View File

@@ -0,0 +1,6 @@
package AbstractFactory.example01.sam;
import AbstractFactory.example01.abst.Wheel;
public class SamWheel implements Wheel {
}

View File

@@ -1,9 +1,9 @@
package AbstractFactory2; package AbstractFactory.example02;
import AbstractFactory2.abst.Button; import AbstractFactory.example02.abst.Button;
import AbstractFactory2.abst.GuiFactory; import AbstractFactory.example02.abst.GuiFactory;
import AbstractFactory2.abst.TextArea; import AbstractFactory.example02.abst.TextArea;
import AbstractFactory2.concrete.FactoryInstance; import AbstractFactory.example02.concrete.FactoryInstance;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {

View File

@@ -1,4 +1,4 @@
package AbstractFactory2.abst; package AbstractFactory.example02.abst;
public interface Button { public interface Button {

View File

@@ -1,4 +1,4 @@
package AbstractFactory2.abst; package AbstractFactory.example02.abst;
public interface GuiFactory { public interface GuiFactory {

View File

@@ -1,4 +1,4 @@
package AbstractFactory2.abst; package AbstractFactory.example02.abst;
public interface TextArea { public interface TextArea {
String getText(); String getText();

View File

@@ -1,8 +1,8 @@
package AbstractFactory2.concrete; package AbstractFactory.example02.concrete;
import AbstractFactory2.abst.Button; import AbstractFactory.example02.abst.Button;
import AbstractFactory2.abst.GuiFactory; import AbstractFactory.example02.abst.GuiFactory;
import AbstractFactory2.abst.TextArea; import AbstractFactory.example02.abst.TextArea;
public class FactoryInstance { public class FactoryInstance {

View File

@@ -1,6 +0,0 @@
package AbstractFactory.gt;
import AbstractFactory.abst.Body;
public class GtBody implements Body {
}

View File

@@ -1,6 +0,0 @@
package AbstractFactory.gt;
import AbstractFactory.abst.Wheel;
public class GtWheel implements Wheel {
}

View File

@@ -1,6 +0,0 @@
package AbstractFactory.sam;
import AbstractFactory.abst.Body;
public class SamBody implements Body {
}

View File

@@ -1,6 +0,0 @@
package AbstractFactory.sam;
import AbstractFactory.abst.Wheel;
public class SamWheel implements Wheel {
}

View File

@@ -1,4 +1,4 @@
package ChainOfResponsibility; package ChainOfResponsibility.example01;
abstract public class Calculator { abstract public class Calculator {

View File

@@ -1,4 +1,4 @@
package ChainOfResponsibility; package ChainOfResponsibility.example01;
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {

View File

@@ -1,4 +1,4 @@
package ChainOfResponsibility; package ChainOfResponsibility.example01;
public class PlusCalculator extends Calculator { public class PlusCalculator extends Calculator {

View File

@@ -1,4 +1,4 @@
package ChainOfResponsibility; package ChainOfResponsibility.example01;
public class Request { public class Request {

View File

@@ -1,4 +1,4 @@
package ChainOfResponsibility; package ChainOfResponsibility.example01;
public class SubCalculator extends Calculator { public class SubCalculator extends Calculator {

View File

@@ -1,4 +1,4 @@
package ChainOfResponsibility2; package ChainOfResponsibility.example02;
public class Application { public class Application {
public static void main(String[] args) { public static void main(String[] args) {

View File

@@ -1,4 +1,4 @@
package ChainOfResponsibility2; package ChainOfResponsibility.example02;
public class Armor implements Defense{ public class Armor implements Defense{

View File

@@ -1,4 +1,4 @@
package ChainOfResponsibility2; package ChainOfResponsibility.example02;
public class Attack { public class Attack {

View File

@@ -1,4 +1,4 @@
package ChainOfResponsibility2; package ChainOfResponsibility.example02;
public interface Defense { public interface Defense {

View File

@@ -1,4 +1,4 @@
package Observer; package Observer.example01;
public class Application { public class Application {

View File

@@ -1,4 +1,4 @@
package Observer; package Observer.example01;
public class Button { public class Button {

View File

@@ -0,0 +1,21 @@
package Observer.example02;
import java.util.Observable;
import java.util.Observer;
public class Application {
public static void main(String[] args) {
Button button = new Button();
button.addObserver(new Observer() {
@Override
public void update(Observable o, Object arg) {
System.out.println(o + " is Clicked");
}
});
button.onClick();
button.onClick();
button.onClick();
}
}

View File

@@ -0,0 +1,11 @@
package Observer.example02;
import java.util.Observable;
public class Button extends Observable {
public void onClick() {
setChanged();
notifyObservers();
}
}