Suppose you have a class called Explosion where it makes no sense to instantiate it without any information from another instance of the class. The constructor is not published.
Is it better to do this:
Explosion e;
Collision c = new Collision()
e = c.createExplosion()
Or better, if Explosion has a static method to instantiate, and you pass the Collision object as an argument:
Explosion e
Collision c = new Collision()
// do some stuff with collision
e = Explosion.createExplosion(c)
When you are the author of both classes.
source
share