can't figure out how aggregation and compostion relates to my program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • deltamami0999
    New Member
    • Feb 2008
    • 16

    can't figure out how aggregation and compostion relates to my program

    can someone help me figure out how i would relate composition and aggregation to a Person class that is composed of another class that is composed of another class and also includes itself in it. It also has a deep copy, a destructor, and all appropriate accessors and mutators in it as well.

    #include "Date.h"
    #include <cstring>
    class Person
    {
    public:
    Person(string name, int year, int month, int day);
    Person(Person&) ;
    Person::sister;-----------***this is susposed to be of type person but i don't know how to incorporate that...can someone show me how???*****
    Person::~Person ()
    string getName();
    Date* getBirthDate();

    private:
    string name;
    Person sister;
    Date* birthDate;
    };
  • Savage
    Recognized Expert Top Contributor
    • Feb 2007
    • 1759

    #2
    Originally posted by deltamami0999
    can someone help me figure out how i would relate composition and aggregation to a Person class that is composed of another class that is composed of another class and also includes itself in it. It also has a deep copy, a destructor, and all appropriate accessors and mutators in it as well.

    [CODE=cpp]#include "Date.h"
    #include <cstring>
    class Person
    {
    public:
    Person(string name, int year, int month, int day);
    Person(Person&) ;
    Person::sister;-----------***this is susposed to be of type person but i don't know how to incorporate that...can someone show me how???*****
    Person::~Person ()
    string getName();
    Date* getBirthDate();

    private:
    string name;
    Person sister;
    Date* birthDate;
    };[/CODE]
    I don't understand what are you asking for.What do you want to do with Person::sister? That's not a type,it's a member variable.Also you shoul have a pointer to parent for sister mameber.And one more thing:

    Your assignment constrcutor takes a string name,but you allready have it as a private member,how do you thik you will assign it using scope?

    Much better way and safer is to rename that to something else to avoid possible errors and make code cleaner and safer.

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      It would seem that a sister is a relation and a relation is a person.

      Maybe your class is the Relation class and maybe it contains a member for the type of relation ans a member for the Person who is the relative.

      The Person member may be either a contained object or a pointer to a Person. You choose based the realtionship between Relative and Person. If Person can change independently from Relative, you have an association ahnd that means Relative has a pointer to its Person member. Otherwise, it can use a contained object (composition).

      Comment

      Working...