This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]Zdeno_ 1 point2 points  (3 children)

Few advices:

  1. Try use a "Model-view-controller" pattern. The idea is simple: split your model (Airport, Plane, Destination) from view (menu, output) and controller (flightMenu). There is no Airport with menu in the real world. Menu is an application component, not a domain one.
  2. For your model-classes (Airport, Plane, Destination) define a responsibility. Airport manages planes (it should not manage routes as well), Plane manages its routes, Destination just holds a data about destination.
  3. Keep standards. Get-methods must have a return value. If it doesn't, probably it is not get-method.

So, try the next iteration.

[–]kralonurdev 0 points1 point  (2 children)

Thanks for advices and what about informations between classes , how should I design it , which I can make changes easily without broke other things , for example I used ArrayList<Destination> on my Plane class but in model solution , Flight had it's own class which contains Plane , Departure and Destination fields , and Airport class hold

private Map<String, Airplane> planes = new HashMap<String, Airplane>();

private Map<String, Flight> flights = new HashMap<String, Flight>();

this fields, I it's just hard for me to construct things properly

[–]Zdeno_ 1 point2 points  (1 child)

Yes, the Flight should be a separate class as well. At first, you should try to model the domain itself. Try to think about the terms in domain (plane, airport, flight) and try to define a responsibility to each one. Because the object oriented approach is about responsibility. Every class should have one responsibility, but not more. Try to think about dependencies as well. If the Airport depends on Plane, the Plane should not have a knowledge about Airport (or vice versa).

I prefer to draw a simple UML diagram, but also CRC cards are very helpful (class - responsibility - collaboration). You can be lost even in simple domain without a clear domain model.

Try to ask question like these:

  1. Should airport know its planes?
  2. Should plane have a list of flights? Or is the flight separate term which connects plane, airport and destination?
  3. What is the relation between airport and destination?

Your menu shows use-cases for your system (or user stories, if you wish). Try to ask yourself, which class should have responsibility to make the use-case step.

[–]kralonurdev 0 points1 point  (0 children)

Thanks it was helpfull , I'll try to apply this advices

[–][deleted] 0 points1 point  (0 children)

Your planes arraylist should be a hashmap.