Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

good programming style, two classes using each other's inner classes

I have class A with its inner class defined A1 and class B with its inner class defined B1. Do you think it is alright that class A in its implementation refers to B1 and class B refers to A1. Is it not a bad programming style? Its just A1 is very A specific class and B1 very B specific, that's why I coupled them. Is it Ok to leave it like that or its better to have A1 and B1 as separate classes? What do you think? Thx.

like image 838
azerIO Avatar asked May 20 '11 13:05

azerIO


1 Answers

I believe that if you need to refer to inner classes of another class, in one of your classes, it is because possibly the class which holds the inner class should be providing some methods to avoid this problem.

If the problem is not like that, then the inner class is probably generic enough to be of use in both other classes, and as such should be an independant class, which should be probably part of the same package which specifies its context of application/use.

like image 157
Luis Miguel Serrano Avatar answered Sep 17 '22 13:09

Luis Miguel Serrano