Click here to Skip to main content
15,881,172 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
Hey,
I am kinda stuck with the way I should structure my Project. Was going well till now, but now it seems I'll have to re-structure it.

My project is Peer to Peer chat and File Sharing. It performs device discovery, chat and file transfer.

I plan to implement it using JTabbedPane where one main tab would represent the online contacts and others would be created for each contact as and when needed.

Till now I created my Main file where i created the JTabbedPane with one tab for device discovery. For simplicity, i had created another program altogether for chat (file transfer is yet to be coded).

Now how do I bring these codes together and go ahead?

Should I?
1: Combine the whole chat code in the main file itself?
2: Make calls to the chat program to create new instances everytime and add one panel at a time to the JTabbedPane?
And if anything else, please suggest.

If the solution is 2, please guide me, m kinda stuck.
Posted

Non of your things.

You need to structure your code. Therefor create packages. Split your code in classes, which have a logical structure. It's quite normal to have a big number of classes - I'm working on a project with (currently) over 400 classes.
But don't just create random packages - think of a proper naming:

- com.foo.main (Application starter)
- com.foo.gui (Gui goes here)
- com.foo.action (general action handling)
- com.foo.fascade.chat (lifecycle data store for chat)
- com.foo.fascade.filesharing (lifecycle data store for filesharing)
- com.foo.chat (general code for chat)
- com.foo.chat.images (icons and images for chat)
- com.foo.filesharing (general code for filesharing)
- ....

this way you will have a structure that leads you.

You should also try to split GUI and command. Therefor you can change the GUI without changing the reest of the code. That is called MVC[^] and can be seen as a very basic structure pattern.

read here for more information on proper Java Design:

http://www.javaworld.com/columns/jw-java-design-patterns-index.html[^]

http://www.oodesign.com/[^]
 
Share this answer
 
v2
Comments
Mehdi Gholam 9-Jan-12 7:41am    
My 5!
Further to Torsten's answer, there is a way to find your candidate classes. First off list write out the requirements. Whenever you come to a noun or noun phrase, that is a candidate for being a class:
Requirements:
My project is Peer to Peer chat and File Sharing. It performs device discovery, chat and file transfer.


As you can see, you already have quite a few candidates. The idea behind this is to find things that can be easily described and which are a concrete item. As an example, you may find you get words like video, audio, record, message and clip but they are actually all just files; so File becomes your candidate class.

It is worth trying to put down what you want to do in a non-technical form so you can see what is needed.
After identifying where your candidate classes are, the next step is to find if they are responsible for anything or need to collaborate with other classes. This becomes automatic after a while, but it is worth doing a few times to get the hang of the concepts.
 
Share this answer
 
Comments
Mehdi Gholam 9-Jan-12 7:41am    
My 5!
TorstenH. 9-Jan-12 7:42am    
nice! Never tried that, but sounds logical and fun! +5!
Nagy Vilmos 9-Jan-12 8:00am    
It is a very worth while exercise.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900