How to design Java application? [closed]
Asked Answered
M

9

24

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

Mohican answered 9/7, 2010 at 14:34 Comment(2)
There are many ways to do it. JavaEE apps will be designed differently from console apps will be designed differently from Swing apps will be designed differently from mobile apps will be designed differently from.... Tell us what kind of app you're thinking of and it will be easier to help you.Murmurous
Thanks, i want to start up with simple console apps, then go to J2EE appsMohican
C
14

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
Caesarism answered 9/7, 2010 at 14:38 Comment(0)
F
5

In my opinion it all boils down to meeting the below

  1. easy to understand
  2. easy to maintain and evolve
  3. multiple developers able to contribute to the project (mostly in parallel)

To achieve the above there are certain guidelines and principles that are suggested by experts based on experience which are

  1. Follow layered architecture
  2. Follow the SOLID principles within and across layers. All the design patterns are one way or the other help achieve these principles only. SRP: Single Responsibility Principle, OCP: Open Closed Principle, LSP: Liskov Substitution Principle, ISP: Interface Segregation Principle, DIP: Dependency Inversion Principle
  3. DRY and KISS principles

These guidelines and principles are independent of any programming paradigm or language. However, OOP languages help implement these easier.

Fivestar answered 9/7, 2010 at 15:56 Comment(0)
D
3

There are various paradigms (very often 3 letters acronyms) :

  • DDD : Domain Driven Design
  • SDD : Serviice Driven Design
  • MDA : Model Driven Architecture (code and architecture is extracted from the UML model)
  • TDD : Test Driven Development (validation tests are implemented before the application)

With theses key-words, you'll find a lot of informations on the web.

In J2EE, I would say that the SDD is the most used (it is now very "normalized", even if I'm not sure it is the best solution) : service (software "intelligence") > domain (bean objects used for persistance) > DAO (persistance).

Now DDD is becoming more and more used : the conception is refocused on domain objects, which are taking the "software intelligence" layer.

Diastema answered 9/7, 2010 at 14:49 Comment(1)
TDD is not a design approach per se (although it can be used to test the usability of your API, and as such it is very useful). MDA was very much hyped in the 90s, then it faded away, for a good reason: UML is a very good tool for communicating your design, but not good for generating source code from it.Apotheosis
S
3

I really advice you to take a look at GRASP principles, it gives you a good design basis skills.

Segmental answered 12/11, 2011 at 20:28 Comment(0)
L
2

Welcome to stack overflow. If you are good with Java, read Head First Design Patterns. and Head First Object-Oriented analysis and design - er, may be in reverse order :)

Listlessness answered 9/7, 2010 at 14:44 Comment(1)
I won't throw myself into Design Pattern if I were a beginner.Prinz
N
1

Start by looking up UML Class diagrams that will get the ball rolling in the right direction, then take a look at Gang of Four design patterns. That is an excellent first step.

http://en.wikipedia.org/wiki/Class_diagram

http://en.wikipedia.org/wiki/Design_Patterns

Lastly, I would pour over good open source code like the Spring Framework

http://www.springsource.org/

Needful answered 9/7, 2010 at 14:39 Comment(1)
And yes you should definetly model everything, but be willing to go back and change the model if it doesn't work. The key is flexibility...Needful
P
1

I'd recommend emergent design with TDD.

I think there is nothing specific to Java design : if you already know about Object Design, you're ready to go !

Prinz answered 9/7, 2010 at 14:46 Comment(1)
I disagree. The classes you would design for a Java app are almost certainly different from the classes you would design for the same app in C++ or C# -- not to mention languages like SmallTalk or OCaml.Shrier
N
1

Do not start coding immediately without having any design. But this does not mean that you should design all before coding. Because from my previous experiences, I could not have any design which does not need corrections. Especially if you are new in a programming language your design will change according to the features of the language you are using and the libraries available. My advice is to have a general design which is based on the most important aspects of object oriented design such as inheritance, polymorphism, encapsulation etc. Starting from this general design and the needs you encounter while programming, revise your design accordingly.

As much as you get experienced in the language, your first general design will fit in a much more efficient way to your program.

Although most of the people say that one object oriented design should be able to be written in any object oriented language, it is not that easy to have a very good generic design like that. To be more realistic, disregarding the language that is used for implementing a particular design is not a good way as far as I am concerned.

Nainsook answered 9/7, 2010 at 14:50 Comment(1)
Thanks Mustafa. What am doing now is writing small applications with an intial design that does the core functionality, then refactoring the code(rediesgning) to follow oop.Mohican
J
1

Well odds are what you'll be doing has already been done before - at least something similar. Luckily, there's lots of open-source stuff nowadays. So if you really have no idea, one thing you can do is download several open-source applications that do the same thing and study them. It should give you a good start.

Jesu answered 9/7, 2010 at 14:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.