How to design Java application? [closed] - java

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
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

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

In my opinion it all boils down to meeting the below
easy to understand
easy to maintain and evolve
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
Follow layered architecture
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
DRY and KISS principles
These guidelines and principles are independent of any programming paradigm or language. However, OOP languages help implement these easier.

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.

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

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 :)

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/

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 !

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.

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.

Related

software analysis .... Start with UML or Design Patterns? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I am a java programmer with 2 years experience, I really like programming, especially OO programming, and if I have a project, I start with programming directly, without any system analysis operations, so my code is not sorted as it should be, I want to learn how to write and design a good code, should I start learning UML or I can go directly through Design patterns ? and what are the best books for learning UML and Design Patterns.
Thanks a lot for your time
Start with a broad-brush design, where you identify the major parts of your solution. You can use UML for that, but it's not mandatory.
Then, start writing tests, or executable specifications, and evolve the code to meet those tests. Use your broad-brush design as a guide, and also the tests. Practice test-driven development. Solicit feedback from your stakeholders. Iterate. Iterate. Iterate.
(Of course, that depends a lot on the type of application that you do, I'm assuming business-like, non-safety-critical software).
As for books, look at "Domain Driven Design" and "Growing Object Oriented Software, Guided by Tests".
Oh, and never start with design patterns...
UML is a means to an end, and by no means the only one. Try it and see if you like it, personally I'm not too fond of it. You need to discover yourself how you want to think about and design your applications. Personally I like drawing boxes on a whiteboard.
Design patterns can be useful but they describe solutions to more specific problems. A pitfall here is that people that start off with design patterns try to apply them everywhere. They try to match a design pattern with a problem, but it should be other way around. UML and Design Patterns are in no way mutually exclusive and they don't (necessarily) serve the same purpose.
As far as design patterns are concerned, I found Head First Design Patterns to be a nice and easy to read book, although this is terribly subjective as I know a lot of people who really hate the writing style of the Head First books.
UML is a way to represent a model, it's not a replacement for the model. The model can be expressed in UML, but not only in UML.
Design patterns help creating the suitable model and avoiding common mistakes. Personally, I found books by Martin Fowler and Eric Evans very useful, but I'm sure there are many other good writers as well.
There's no recipe for learning how to design code, it's about experience.
well, after 15+ years of assembly/basic/pascal/java/c/c++/C# and another gazillion languages sometimes my code is just not sorted as it should (or could be), still I'm well payed and generally considered a good programmer.
Too many reasons behind that, tight release dates, too fast evolving tech, dumb client requirements, monstrous frameworks designed only thinking about extendability (it's this even an English word) and not focusing on usabiliy.
When I start a new project, the first thing I do is have a coffee.
Then I contact the customer (or whoever will use the application) and try to get a grasp on what they really need. Understanding what the client needs is the real goal (after getting paid of course ^^)
After this, I took pencil and paper and draw, not following any standard. Boxes, circles, arrows, with notes, some kind of artistic brainstorming.
Design patterns... best way to use them is avoid them. Too often they don't match real life problems, but programmers all over the world are abusing them everywhere, yes, mainstreaming leads to that. But if you feel the absolute reason to use them, start with the GoF beast (Design Patterns: Elements of Reusable Object-Oriented Software: Erich Gamma, Richard Helm, Ralph Johnson e John Vlissides).
2 years is just a small amount of time. Designing good code requires a bit more time (and of course experimenting with different languages)
The best book available for design patterns is the book 'Design Patterns: Elements of Reusable Object-Oriented Software' By the Gang of Four. The latest version of this book also includes an UML book in the package. Together this will be a good start.
However, just implementing design patterns is wrong. When you want to learn to write and design good code, understanding when to use patterns (and when to develop your own!) is a must.

Component Oriented Software and Design

Recently my ad-visor asked me to see if I could build a simulation framework which can be used for implementing + testing some new distributed computation paradigms.
I looked into some open source frameworks - and found that there are quite a few simulation frameworks available and most of them are based on component oriented software design principles. I looked up this topic on the internet and found that this was sort of the thing in the late 90s and early 00s but has now kind of faded away from the high point. Does anyone has some good books to suggest on what exactly it is? Now having some exposure to Java - I also noticed that I might have already have used some of component oriented software concepts (e.x - I have created simple wysiwyg document editors using Swing's text apis, so I am aware of concepts such as - Views, StyleContext, StyleDocument etc. etc.) - though I explicitly didn't take notice of the techniques.
Any pointers to beginner books/tutorials will be greatly appreciated. I just want to create some small app to see if any of this at all makes any sense.
To build a flexible simulation framework you may want to look at a functional programming language, such as Scala, as by design it works better for this since you can then either design a DSL (Domain Specific Language) to help abstract out writing the simulators, so others can focus on their research instead.
For an example of someone wanting to use Scala for a simulator you can look at Howto design a clock driven multi-agent simulation.
For an interesting page with a .NET reference that compares OOP with Component Oriented programming you can look at this blog: http://www.elenkist.com/bushido_burrito/blog/?p=11.
Before you get too wrapped around a language or technology, design out what you want to do, how you want the user to interact with your framework, then decide on the best approach, rather than trying to pick an approach and forcing your solution to work within those constraints.

Is MVC the only acceptable way to develop a desktop application with a GUI?

Or are there other generally accepted patterns for creating a generic business application with a graphical interface and no network connectivity.
There is another similar pattern that fully separates the layers, n-tier architecture though very similar is easier to understand and once you manage to separate the logic it makes the hardware separation easier if you would like to further extend it.
I use the Observer quite a bit. A similar example in the wild is RCP's selection service.
It isn't the only acceptable way, but the concepts in an MVC design will provide you with a good foundation. The Computer Science community has built these design patterns because of the years and decades we have developing applications. After dealing with the same problems over and over, we've built up these design patterns to avoid the problems in future development.
If you don't want to follow these design patterns, you can.... but you're setting yourself up for pain. There isn't a good reason to reinvent the wheel. It's better to take a cue from all of the developers who came before you. :)

Is there an Online Programming Bible? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 6 years ago.
Improve this question
I'm interested in Programming especially in Java. Is there a page, which explains different informatics topics in Java or generic for all OOP languages? I mean something wikipedia-styled, but more understandable and just for programming/informatics.
Maybe with exercises, but basicly it should explain different problems of informatics.
There are a lot of good online resources for learning Java, and many of them will teach you good OOP practices as well.
The Java Tutorials
Java API Specification
Thinking in Java 4th ed. by Bruce Eckel
The Java Language Specification
The Java Virtual Machine Specification
For programming in general though, I recommend Structure and Interpretation of Computer Programs.
For programming topics on Java, go to the Oracle (Sun) Java site. That's the holy grails of everything regarding Java. For a Wikipedia-style format, just go to wikibooks (as it will have topics on Java and other programming languages, not just OO.)
Other than that, a short answer to your question will be simply NO. Programming is too complex a topic for someone to create the type of material that you are asking.
If you are seriously interested in programming (and I mean seriously), focus on one language alone and learn it (as opposed to looking for the perfect language or trying to analyze all possible alternatives and falling into "paralysis by analysis".)
Again, if you are serious...
just pick one of the following:
C
Python
Ruby
Scala
C would make you face the nitty gritty of computing and people have been successful in learning programming with C as its programming languages (don't let OO and/or Ruby/Python/Java/.NET fanboys tell you otherwise.)
Python and Ruby are extremely beautiful languages that will teach to program, and do not force you to make everything into an object (a really retarded idea, more on that below.) Scala is another elegant and effective alternative.
Learn The Fundamentals of Programming First, the OO Analysis and Modeling (not the other way around
Avoid languages that force you to write everything in objects. That includes Java and C#. I've been working with Java for 12 years now, and it is a reliable platform. But it is a retarded language in that it does not allow you for procedural programming. Not everything is an object nor should be modeled as an object, sometimes not even in complex systems. People are still grappling with how to program correctly using a OO paradigm and they keep failing because they still don't get the capabilities and limitations of OO modeling and analysis.
So my suggestion is not to learn programming with Java (or C#). Go with the hard procedural (C) or the elegant, paradigm-agnostic (Python, Ruby or Scala.) Focus on modularity, structured programming and algorithms. Then, later you will be better equipped to truly understand where OO languages fit in.
I'm not going to delve into why I chose these 4 options or why I advise against Java and C#. That debate has been discussed a plenty and you can find it easily in stackoverflow and/or google. That's just my suggestion, from my experience (Java and otherwise), a suggestion that I always give to those serious about learning programming.
In the end, it doesn't really matter which of those four you pick. Just flip a coin, pick one and stick to it until you are decent with it. Focus on learning proper programming techniques, problem decomposition and algorithms rather than on the language itself.
Good luck.
edit:
I forgot to mention, if you are serious about learning programming, buy books. You won't learn from visiting sites. And you have to put your time in it (we are talking 4hrs a day at least... I don't see anyone learning programming with anything less than that.) Anything less is just make-believe going through the motions of learning.
I strongly recommend imo the best book written about Java.
Effective Java by Joshua Bloch
http://www.programmingpraxis.com could help you a lot since i go through most of the examples from there.Have a look.
EDIT:
http://www.cs.sunysb.edu/~skiena/392/javaprograms/
http://projecteuler.net
Continuing the Bill's recommendation
http://www.artima.com/insidejvm/ed2/jvm.html
Effective Java by Joshua Bloch.
I would recommend these: Sun Tutorials,
FreewareJava.com,
java2s

Good problem domain for introduction to OO project?

I'm working with someone who's looking to get back into programming after several years of IT support work. They know all the iterative programming basics and have used them frequently, but their only object-oriented programming experience was in college. The goal is to come up with a decent-sized project that is good for illustrating and practicing OO concepts. Has anyone ever used or thought of a good problem domain for an introduction to OO? I'm looking for a domain where concepts such as inheritance, abstraction and polymorphism really make sense and provide an advantage when modeling with the classes.
Of course, I did some googling and found the popular ATM and Address Book OO examples. They're both pretty good, but ATM is a little more complex than what I'm looking for. Address Book may be decent, but I think it might not be complex enough, or a clear enough domain for modeling objects. The goal is for the project to take a decent amount of effort to complete, not something that can be completely done in an afternoon or two.
As for implementation specifics, the project will be implemented as a Java console app with a minimal UI. Learning the OO concepts and how to implement them in Java is the primary purpose of this app.
How about a text based adventure game?
I like casino game simulation. Simulation is one of the application domains that lead to the development of OO programming. Casino games are relatively simple but with some sophistication.
You can look at http://homepage.mac.com/s_lott/books/oodesign.html.
Along the same lines as address book, a general catalog (cds, books, dvd, equipment & so on). The idea here, you have a base item that is extended by all the other types (inheritance) and each one can implement a specific interface for display and other purposes (polymorphism).
When I've taught other people how to understand OO-principles, I've asked them to relate to OO-programming as if they were building a house. A house has everything you need.

Categories

Resources