dimanche 15 janvier 2017

Solution to trigger event between container and element?

I have a class like this:

public class Graph {
    List<Node> nodes;

    List<Relation> relations;

    public void addNode(Node node){
        nodes.add(node);
    }

    public void addRelation(Relation relationship){
        relations.add(relation);
    }

//getter and setter
}
public class Node {
    List<Relation> relations;

    public void addRelationship(Relation relation){
        relations.add(relation);
    }
//getter and setter
}

How can Graph call it's method: addRelation(Relation relationship) when node.addRelationship(Relation relation) is called. I can add Graph property in class Node but it seem not close to HAS-A relationships in OOP

Aucun commentaire:

Enregistrer un commentaire