Skip to content

Commit

Permalink
create interfacce per visitor e observer
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriele Fedi committed Nov 24, 2018
1 parent fe1e494 commit a684c05
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 0 deletions.
5 changes: 5 additions & 0 deletions nbproject/private/private.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/Users/work/NetBeansProjects/MpProject/src/mpproject/ObserverRegister.java</file>
<file>file:/Users/work/NetBeansProjects/MpProject/src/mpproject/Player.java</file>
<file>file:/Users/work/NetBeansProjects/MpProject/src/mpproject/Opponent.java</file>
<file>file:/Users/work/NetBeansProjects/MpProject/src/mpproject/Team.java</file>
<file>file:/Users/work/NetBeansProjects/MpProject/src/mpproject/MpProject.java</file>
<file>file:/Users/work/NetBeansProjects/MpProject/src/mpproject/MyObservable.java</file>
<file>file:/Users/work/NetBeansProjects/MpProject/src/mpproject/Match.java</file>
<file>file:/Users/work/NetBeansProjects/MpProject/src/mpproject/MyVisitor.java</file>
<file>file:/Users/work/NetBeansProjects/MpProject/src/mpproject/MyObserver.java</file>
</group>
</open-files>
</project-private>
17 changes: 17 additions & 0 deletions src/mpproject/Match.java
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;
}
16 changes: 16 additions & 0 deletions src/mpproject/MyObservable.java
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);
}
14 changes: 14 additions & 0 deletions src/mpproject/MyObserver.java
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);
}
14 changes: 14 additions & 0 deletions src/mpproject/MyVisitor.java
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);
}
38 changes: 38 additions & 0 deletions src/mpproject/ObserverRegister.java
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));
}

}

0 comments on commit a684c05

Please sign in to comment.