vendredi 23 décembre 2016

Design to access elements of object owner

Let's say I have two classes:

Class A {
  B b;
  Foo bar;
}

Class B {
// some stuff
}

Since an object of type A owns an object of type B, some stuff of B could be accessed by A. What would be a good design, if an object of type B has to has access to it's owning object (of type A)? E.g. if I have an object of type B and want to get the bar value of the object it is a member of.

Would it be good practise to add a reference to A to B everytime a B is created?Or some kind of delegate pattern?

Aucun commentaire:

Enregistrer un commentaire