重新构造我的项目的建议 [英] Suggestions for re-Structuring my Project

查看:107
本文介绍了重新构造我的项目的建议的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,
我对构建项目的方式有些犹豫.到现在为止一切都很好,但是现在看来我必须重新构造它.

我的项目是点对点聊天和文件共享.它执行设备发现,聊天和文件传输.

我计划使用JTabbedPane来实现它,其中一个主选项卡代表在线联系人,并在需要时为每个联系人创建其他选项卡.

直到现在,我创建了Main文件,并在其中创建了JTabbedPane,并使用一个标签进行设备发现.为了简单起见,我创建了一个用于聊天的程序(文件传输尚未编码).

现在如何将这些代码整合在一起并继续操作?

我应该吗?
1:将整个聊天代码合并到主文件本身中吗?
2:每次都调用聊天程序以创建新实例,并一次将一个面板添加到JTabbedPane吗?
还有其他建议.

如果解决方案是2,请引导我,有点卡住.

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.

推荐答案

您的所有事情都没有.

您需要构建代码.为此创建软件包.将代码拆分为具有逻辑结构的类.有大量的课程是很正常的-我正在(目前)有超过400个课程的项目中.
但是,不要只是创建随机的包-请考虑适当的命名:

-com.foo.main(应用程序启动程序)
-com.foo.gui(Gui在这里)
-com.foo.action(常规操作处理)
-com.foo.fascade.chat(用于聊天的生命周期数据存储)
-com.foo.fascade.filesharing(用于文件共享的生命周期数据存储)
-com.foo.chat(聊天通用代码)
-com.foo.chat.images(用于聊天的图标和图像)
-com.foo.filesharing(文件共享的通用代码)
-....

这样,您将拥有一个引导您的结构.

您还应该尝试拆分GUI和命令.因此,您可以在不更改代码范围的情况下更改GUI.这称为 MVC [ ^ ],可以看作是非常基本的结构模式.

在此处阅读有关适当的Java设计的更多信息:

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

http://www.oodesign.com/ [ ^ ]
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/[^]


根据Torsten的回答,有一种方法可以找到您的候选课程.首先从清单上写出要求.每当您出现名词或名词短语时,都可以成为该类的候选者:
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:
要求:

我的项目对等聊天文件共享.它执行设备发现聊天文件传输.

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



如您所见,您已经有很多候选人.其背后的想法是找到可以轻松描述且是具体项目的事物.例如,您可能会看到诸如视频,音频,记录,消息和剪辑之类的单词,但实际上它们只是文件而已.因此File成为您的候选课程.

值得尝试以一种非技术性的方式放下您想要做的事情 ,以便您可以看到需要做的事情.
在确定候选类的位置之后,下一步就是查找它们是否对任何事情负责,或者是否需要与其他类进行协作.一段时间后,这会自动完成,但是值得一试才能理解这些概念.



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.


这篇关于重新构造我的项目的建议的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆