A constructor should allocate an object and any necessary members only.
For operational things, like placing the sub in the sea, this should be done via a separate method.
Remember that the main purpose of OO code is enhanced reusability and maintenance. Muddling up the constructors with something other than simple object initialization is a no-no.
For operational things, like placing the sub in the sea, this should be done via a separate method.
Remember that the main purpose of OO code is enhanced reusability and maintenance. Muddling up the constructors with something other than simple object initialization is a no-no.
There are plenty of times when it's an acceptable or even necessary pattern for a constructor to register itself with an outside object.
This is doubly true because, unlike wrt closures, Java genuinely lacks destructors.
Comment