how do i represent this in aggregation C# code

P1 and P2 as classes and then use aggregation to assign A, A’ instances to them.

apprecite a reply thanks

P1 component has A and B components
so how do i represent it in aggregation
hope thi helps

appreciate a reply

thnaks

so the description is as "You could represent P1 and P2 as classes if you like too – and then use aggregation to assign A, A’ instances to them"

Many ways to do it

class P {
    A[] myArray;

    public P(int A') {
        myArray = new A[A'];
        for (int i = 0; i < A'; i++) {
            myArray[i] = new A();
        }
    }
}

class P1 {
    List<A> myList = new List<A>();

    public P1(int A') {
        for (int i = 0; i < A'; i++) {
            myList.Add(new A());
        }
    }
}

Note that A' is not a valid variable name, I just used it to match your description. myArray and myList are aggregates of type A.

hey momerath
in a situation like
image6

if P1 is primary and p2 is seconday os this the way i represent

 class P1 {
    List<trackManager> A = new List<trackManager>();
    List<trackManager> B = new List<trackManager>();
    public P1(int tm) {

        }
    }
}

class P2 {
    List<trackManager> A' = new List<trackManager>();
    List<trackManager> B' = new List<trackManager>();
    public P2(int tm) {

        }
    }
}

appreciate a reply

thanks

This article has been dead for over six months. Start a new discussion instead.