Frank Carver wrote:B.
is sometimes used when you need to call only one non-static method of a class, but don't care about keeping the object around afterwards.
In my opinion this often shows poor design. It may be aproblem with the class being used - the method should be static or there should me more reason to keep the object around. It may also be a clue to the calling code not caring about object creation overhead, and not making use of the power, flexibility, and testability of dependency injection.
It may be appropriate in a main() method invocation, where you only need a reference to the object running the app once.Frank Carver wrote:. . . this often shows poor design. . . .
Education won't help those who are proudly and willfully ignorant. They'll literally rather die before changing.
is sometimes used when you need to call only one non-static method of a class, but don't care about keeping the object around afterwards.
In my opinion this often shows poor design. It may be aproblem with the class being used - the method should be static or there should me more reason to keep the object around. It may also be a clue to the calling code not caring about object creation overhead, and not making use of the power, flexibility, and testability of dependency injection.
Education won't help those who are proudly and willfully ignorant. They'll literally rather die before changing.
Frank Carver wrote:
C.
Each catch block will only be used if the corresponding exception type is thrown. Think of it a bit like a case statement but which switches on the type of the exception.
Out on HF and heard nobody, but didn't call CQ? Nobody heard you either. 73 de N7GH
The compiler will catch them and the code will fail to compile.Les Morgan wrote:. . . the other catch clauses will never be hit . . .
Carey Brown wrote:I don't feel this statement fits all use-cases. There a cases where you create an object which then goes off to handle its own life-cycle and nothing else needs to retain a reference to control it, See my main() example.
Education won't help those who are proudly and willfully ignorant. They'll literally rather die before changing.
Morning came much too soon and it brought along a friend named Margarita Hangover, and a tiny ad.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|