dimanche 4 janvier 2015

Design the classes' interaction: aggregation or duplication?

I have the two separate classes:



class RecTarget : public Target /* Abstract class */
{ /* The Points are located in a form of Rectangle */

std::set<Point> Set;
/* I've chosen the std::set to easy searching,
* "is the hit to Target is success?"
*/

/* ... */
};

class Moves
{ std::map< Point*, std::list<WayToGetTheHit> > hmoves;
/* This class monitors and saves the moves to hit
* for each Point of Target.
*/
Target* target; /* Aggregation? */
/* ... */
};


What is the best design way? Must I use an aggregation for correct handle the situation (Point* pointers to target->Set->Point), or must I duplicate all of the Points in this class instead of links to existing Points in Target? Or something else???


Thank you, in advance.


Aucun commentaire:

Enregistrer un commentaire