vendredi 22 juillet 2016

Coding style and organization

So I am currently making a airplane reservation system for a summer project to keep fresh with Java. With any reservation system its requiring a lot of classes and methods. Currently I'm working on importing the fleet.

My main method is acting like the chronological guide to my program.

public static void main(String[] args){
    //start here 
    //accept passenger credentials 
    //place passenger in seat on plane
}

My question is a formatting problem. When I'm looking to start "making" my aircraft for my fleet. It goes a little like this.

//...
Airplane Boeing737 = new Airplane(seats[], nameOfAircraft);

This will put all values that i need to construct my airplane, obviously there are more variables for the airplane constructor.

My thought is to make a method in the Airplane class that will do this for me. but in order to do this i need to call a blank constructor for the other class (the one with my main method) to see it. I feel like this is horrible form for some reason. Is there a better way to do this?

Another thought as I'm posting is to modify the constructor to not accept any arguments and have that do everything in there. I feel like that's what I should be doing but I'm not 100% sure that would be the correct choice. I guess my overall question would be what are best practices in situations like this.

Aucun commentaire:

Enregistrer un commentaire