12/13/2006

OO Design Question

Filed under: — Moonglum @ 19:41

Class A and Class B are used by different parts of the same large application. I am refactoring part of the code that takes B’s, but needs A’s. They have a function:

private A getAfromB(B b);

Upon seeing this function I immediately thought, self I thought, why isn’t this a constructor for A? This is a fairly complicated function and has a fair amount to do with the internals of A, but this may be the only place where that conversion is needed. So my question is, do I leave this function private at the point of use, never to be seen by the outside world, or do I add a public constructor to A where it can be reused in the future, but might cause confusion to future users of A, or worse add odd Library dependencies (e.g. B needs to be defined in A.java even though it is in an entirely different package)?

Powered by WordPress