0

There are 2 different design. Second one is(below) improved version of first one. Difference is that I add 2 child class to B. So A is dependended to 2 child class now. but what will happen if B has more child classes later?

Is it really best practice? Especially with GRASP perspective?

two different version

Yavuz
  • 1,257
  • 1
  • 16
  • 32

1 Answers1

0

Instad of having an association to each classes, I would prefer the following.

enter image description here

Red Beard
  • 3,436
  • 1
  • 14
  • 17
  • But doesnt this mean A will have an instance of B? This is like "B b= new B" in A class and in this case I can not use sub1 and sub2. – Yavuz Nov 28 '13 at 15:40
  • yes that's mean that A will have at least one B instance but sub1 and sub2 instances are also B instances. So the code B b = new sub2(); is valid also. You can also set B as abstract in order to model the fact that you will never have B instances – Red Beard Nov 29 '13 at 10:28