mardi 1 août 2017

Is there a design pattern or basic object-oriented principle that deals with this case of shared resources?

Let's say I have three classes, Solid, Face, and Edge that are defined as follows:

class Solid{
    public:
        // perform an action on a single edge.
        void addFillet(int edgeNum);
        // perform an action on a single face
        void addBore(int faceNum);
        // perform an action on all faces and edges
        void move(Pos newPosition);
    private:
        std::vector<Edge*> edges;
        std::vector<Face*> faces;
};

class Face{
    public:
        // will modify a subset of edges
        virtual void changeHeight(int newHeight) = 0;
    private:
        int myNum;
        std::vector<Edge> edges;
}

class Edge{
    public:
        virtual void changeLength(int newLength) = 0;
    private:
        int myNum;
        int length;
}

in this example, Solid manages a 'superset' of Edges. Each Face that Solid manages will have a 'sub-set' of Solid.edges. Further, any two Solid.faces may have a common Edge.

My question: are there any design patterns or general object-oriented principles for dealing with situations like this? How can I manage the relationship between Solid.edges and Face.edges? More specifically

Aucun commentaire:

Enregistrer un commentaire