• Post Reply Bookmark Topic Watch Topic
  • New Topic

Needing some direction on architecture- would love some pointers  RSS feed

 
Rick Reumann
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've looked over Sun's tutorials and just bought the book "graphic Java 2" by David Geary.
What I am really looking for are some examples on how to architect Swing applications. Basically all the tutorials and sample code usually deal with small bits of information. What I'm wanting are some tips on how to best design a real application.
To start with I'm trying to mess around developing a simple application that will allow the user to display contact information in a JTable and then create a "New" contact list. Edit the list, Save, Load etc.
As I started this work I found I was putting everything into one class file. This doesn't seem very object oriented to me, but I'm wondering what is normally seperated out into other class files. In other words are their typical architectural considerations to keep in mind. For example, should I make each listener a seperate class file or is it best to keep them all together iniside of another class?
I'm also familiar with MVC architecture but all the examples I see of it relation to Swing are dealing with it on the pluggable look and feel end. Are there good examples of MVC being used for a small Swing application that I could study?
I'm comfortable dealing with Java when it comes to JSP and Servlets and web based architecture but this Swing stuff is all new. Thanks for any direction some could give me.
Rick
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, it sounds like you are confusing "class file" with source code file... If you have several listeners that are inner classes, they will compile into several different .class files from one .java file. So they are technically seperate classes.

So, what you are really asking is "What should be an inner class, and what should be a top-level class for the class I am building?" This is not an easy question and is different for each application. Generally, the things that are separate classes (either inner or top-level) are 3 things -
  • Models,
  • Renderers (views),
  • and Listeners (controllers).


  • To decide if a class should be a top-level class or an inner class is based on 2 things -
  • Do they need to be inner classes to access some value of the outer class?
  • Do other classes need to use or access them?


  • Generally, my classes usually start out as inner classes, and then as I start building more code I see where an inner class of one class can be used by the new one, so I refactor my original inner class into a top-level class.

    But it's really just something you have to learn by doing multiple times... and even doing over and over within the project you are working on...

    Good Luck!

    -Nate
     
    Rick Reumann
    Ranch Hand
    Posts: 281
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks Nate, yes, I should have been more clear.. that exactly what I want to know..what types of classes should be defined as top level classes. I'll work with your approach for now of building most things as inner classes (which is what I'm doing currently) and see how the application develops from there.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!