-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create interfacce per visitor e observer
- Loading branch information
Gabriele Fedi
committed
Nov 24, 2018
1 parent
fe1e494
commit a684c05
Showing
6 changed files
with
104 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package mpproject; | ||
|
||
/** | ||
* | ||
* @author work | ||
*/ | ||
public class Match { | ||
private Opponent opponent1; | ||
private Opponent opponent2; | ||
private String score; | ||
public static ObserverRegister<Match> observerRegister; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package mpproject; | ||
|
||
/** | ||
* | ||
* @author work | ||
*/ | ||
public interface MyObservable <T>{ | ||
public void addObserver(MyObserver<T> o); | ||
public void removeObserver(MyObserver<T> o); | ||
public void notifyObservers(T event, String code); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package mpproject; | ||
|
||
/** | ||
* | ||
* @author work | ||
*/ | ||
public interface MyObserver <T> { | ||
public void update(T event, String code); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package mpproject; | ||
|
||
/** | ||
* | ||
* @author work | ||
*/ | ||
public interface MyVisitor <T> { | ||
public void visit(T obj); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package mpproject; | ||
|
||
import java.util.LinkedList; | ||
|
||
|
||
/** | ||
* | ||
* @author work | ||
*/ | ||
public class ObserverRegister <T> implements MyObservable<T>{ | ||
private LinkedList<MyObserver<T>> observers; | ||
|
||
public ObserverRegister() { | ||
this.observers = new LinkedList<>(); | ||
} | ||
|
||
|
||
@Override | ||
public void addObserver(MyObserver<T> o) { | ||
observers.add(o); | ||
} | ||
|
||
@Override | ||
public void removeObserver(MyObserver<T> o) { | ||
observers.remove(o); | ||
} | ||
|
||
@Override | ||
public void notifyObservers(T event, String code) { | ||
observers.forEach(e -> e.update(event, code)); | ||
} | ||
|
||
} |