I have to generate three instances of the same object in my code in different places.
//This puts ship in new location.
spaceShipLocation location = new PhyiscsEngine();
Is it considered bad style to repeat this 3 times in the code or should I wrap it in a method?
(my intuition says no).
p.s
this is for intro to computer science course.
If you need to instantiate a class, just go ahead and do it. Wrapping every
new Foo()statement in a method would make your code awful to read and maintain.Also, since you mentioned ‘good style’, Java naming conventions state that Class names should begin with a capital letter and use camel case.
spaceShipLocation(assuming it’s a class, due to the code snippet) should actually beSpaceShipLocation.