Do you start writing GUI class first or reverse

programming practices

I want to write my first Java program, for example Phonebook, and I wonder what to do first. My question is should I write GUI classes first or util classes first?
I am database developer and want to know best practice in building program.

Best Answer

In theory, there are at least five possible approaches.

Top-Down:

Start with UI mock-shots or a paper prototype. Turn them into real dialogs, and work your way from the button handlers and other controls down through the logic and to the database.

Bottom-Up:

Start with the data structures (probably the database schema). Then add logic (modelling real-world processes); finally, your UI is just an interface to trigger the logic and display the results.

Logic first:

Start with the program logic, implementing data access and a rudimentary UI as needed. Then formalize and harden the data structures, and finally flesh out the UI properly.

Meet in the middle:

Start with database schema and UI, and simultaneously work towards the point where they meet. With this approach, the logic comes last.

Horizontal expansion:

Start by identifying the absolute minimum amount of functionality that would do something interesting, and implement the whole stack (data structures, logic, and UI) for this part. It could be just a basic CRUD cycle with a simple edit dialog for just one entity. Then start adding more features, implementing the whole stack for each feature (hence 'horizontal').

Each of these has pros and cons.

Top-down gives you something visible early in the process, and allows you to check your functional design with stakeholders - mock-shots often tell users more about a design than flowcharts or walls of text.

Bottom-up gives you a chance to design a rock-solid database schema before you commit to anything; since a database schema is notoriously hard to modify once released, you want to get this part right - the impact of modifying a UI is much smaller and produces fewer and less severe bugs.

Logic-first means you can test the logic before spending serious time on the database and the presentation, which is especially interesting if your logic is going to be really complex.

Meet-in-the-middle combines the advantages of bottom-up and top-down, but you'll have to jump back and forth between two tasks, and you risk ending up with logic that is more complex than necessary because your two ends don't meet naturally.

Horizontal expansion goes well with an iterative workflow, and it has the added advantage that, if you prioritize well, you will have a working application at any given time, so if you don't make a deadline, you will have a version that has fewer features, but is still fully functional, as opposed to a version that has a complete database, but no UI at all.

So which one you choose depends on your personal style, and on the circumstances.