P
Peter D.
I've been trying to look this up but I can't really come to a
conclusion. Is it bad practice to create an object like so:
new MyObject(param1, param2);
Without assigning it to a variable. I know this is accepted to some
degree but lets say I just wanted a class to do some work on the side
without caring about the result of the work it has done for example:
new LogThis("Log this string");
The class will do it's business and go away. Or:
new Monitor(someStuff);
Which will then go off and monitor something during the runtime of the
application. What if I don't need to access the reference to this
object?
What are the drawbacks to using such techniques? I don't see much code
with random new's everywhere so I am wondering if some of the code I
am writing is cruddy...
Thanks.
conclusion. Is it bad practice to create an object like so:
new MyObject(param1, param2);
Without assigning it to a variable. I know this is accepted to some
degree but lets say I just wanted a class to do some work on the side
without caring about the result of the work it has done for example:
new LogThis("Log this string");
The class will do it's business and go away. Or:
new Monitor(someStuff);
Which will then go off and monitor something during the runtime of the
application. What if I don't need to access the reference to this
object?
What are the drawbacks to using such techniques? I don't see much code
with random new's everywhere so I am wondering if some of the code I
am writing is cruddy...
Thanks.