How to design Java application?

Dushyanth picture Dushyanth · Jul 9, 2010 · Viewed 44.1k times · Source

What are the general guidelines and best practices to keep in mind while designing Java application [Simple console apps to J2EE apps]?.

Hi

I recently completed Java programming tutorial from Sun and practised core java (I have previous programming experience). Now I understand the basics of Inheritance, Abstraction , Polymorphism,Encapsulation

Now i am writing Java code without much difficulty, but am not sure of application design. This is my main problem: "DESIGNING" the application. Say if i have given a task to create an application in Java, What should I start up with? How to think about? Any formal/informal guidelines I should follow while developing class hierarchies? I am really confused (abstract class or interface or sub class..?). Should I start by model everything, before writing code?

It would be very useful for people like me to have a SET OF GENERAL GUIDELINES/BEST PRACTICES, which we can follow while start developing a new java application.

Please provide me some guidelines/thoughts/books/resources/tools I should read or Use

Thanks in advance Scott

Answer

Péter Török picture Péter Török · Jul 9, 2010

It is difficult to give really general advice as there are so many different Java apps on different domains. However, one absolutely recommended book is Domain Driven Design by Eric Evans. See also Wikipedia for a short intro on it.

General advice:

  • don't try to design everything up front - do a reasonably good design which enables you to start coding, then refactor as your understanding of the problem domain and the implementation deepens
  • try to divide difficult problems into smaller parts/steps/modules which you can tackle one by one
  • try to think in terms of objects with well defined responsibilities, which (more or less) model the problem domain and cooperate to solve a problem / handle a task
  • becoming good at design requires practice, first and foremost; don't be afraid to make mistakes. However, when you do, analyze them and learn from them as much as you can
  • learn design patterns, but don't be overzealous - use them only when they really solve a problem and make your code cleaner