0

I have encountered with this problem often. Couldn't think of a way to how to face this. Now I got this excellent forum!! I'm sure experts here will help me with this.

This is not a problem about a specific code segment like thing. I am capable (as I think) of doing some advance projects in java. It means, simply, I can finish the project to give the exact result.

But the problem is, though I can finish it some how, I'm not satisfied with the management of the classes etc. Actually I don't know how to properly manage it. I'll explain considering the project I'm currently working on (I'm not a professional coder, this will be for my self learning).

I'm working on a database management system (MySQL + Java). There I'm hoping to implement several features there. The flow will be, roughly, like this.

1. Login
2. Main window

Main window will be like this.

enter image description here

In the left panel you can select what you need to do.

Eg.

*. Add some entries to the database

*. Search database

*. Other..(will be add later)

Can some one please tell me how to manage all those things, two frames and several panels.

What I've done is like this.

I've written a managerClass which has the main method. Then It'll call loginFrame first. After validation, loginFrame calls a method in managerClass, to load mainFrame. But I keep a reference to the managerClass in all the frames, panels etc.. as I save all the required info in managerClass, like user name ect..

But when modifying and debugging, things become really really difficult. As I haven't done thing according to any specific rule. I'll have to modify almost all the classes to do a slight modification. I've though a lot and sea

Anubis
  • 6,995
  • 14
  • 56
  • 87

1 Answers1

1

From what I can understand of your application, your main issue is the coupling between your components and the different layers of the application (presentation, interaction control, domain logic). I would suggest using two design patterns (or styles) that may help here:

  1. Model-View-Presenter: separates the Model/Domain logic from the presentation (View) from the logic of controlling user interactions. I've used it recently in a large application and I've found it really helps to separate concerns in a clean way and makes testing much more simple. Please don't confuse it with the Model-View-Controller model, which is close, but have many issues. There's a nice article by Martin Fowler describing these two patterns
  2. Adopt an event based interaction between your components. Instead of the Login frame calling the Manager class, make it fire an event ("user authenticated"), which is handle by the interested components. For example, you may have a small user account details panel in the main window which is not displayed until this event is triggered. Unfortunately, I'm not aware of any event framework for plain Java (which I suspect if the what you are using for development) The one I use is for Google Web Toolkit.
pablochacin
  • 947
  • 1
  • 14
  • 35
  • 1
    Thanks for your guide. I haven't adopted any of those patterns to my projects yet (I knew there are such). Hope it's time to go for such. And I found your two links much helpful. I haven't go through them fully yet, but seems like they'll have some answer for my problem. Thank you for your effort. I'll give some feedback later.. – Anubis Aug 03 '12 at 06:47
  • 2
    I found [this thread][http://stackoverflow.com/questions/2105121/what-to-use-mvc-mvp-or-mvvm-or] **very very** useful. BTW, thanks @pablochacin, I'll accept yours as the answer.. – Anubis Aug 04 '12 at 04:44