当两个不同的wicket应用程序共享通用功能时,如何重用代码 [英] How can I reuse code when two different wicket applications share common functionality
问题描述
我有一个Wicket AuthenticatedWebApplication,它有几个页面和功能需要在我必须开发的新AuthenticatedWebApplication中重用。
I have a Wicket AuthenticatedWebApplication which has several pages and features that need to be reused in a new AuthenticatedWebApplication that I have to develop.
我正在使用Wicket 1.4, Spring和Hibernate。
I am using Wicket 1.4, Spring and Hibernate.
两个应用程序甚至会共享相同的外观(应用程序徽标除外),现在在基页中实现。
Both applications will even share the same look (except for Application logo) which is now implemented in a base page.
有没有人有类似的经历?我绝对不想重复复制粘贴代码,因为常用功能实现了可以并且将会改变的工作流程。
Has anyone had a similar experience? I definitely don't want to recur to copy-paste code because the common functionality implements a workflow process which can and will change.
我可以做些什么来保持我的应用程序模块化,实现我的目标?
What can I do to keep my applications modular, and achieve my goal?
推荐答案
我的公司一直这样做。我们有一个核心包,包含基本UserApplication,用户帐户,登录,身份验证等。然后,我们开发的每个项目都扩展了这个基础包。有一些重复 - 例如几乎所有配置文件在每个配置文件中看起来都相同 - 但是每个配置文件都有自己的主题
目录,该目录提供标记,并根据应用程序的外观进行自定义。
My company does this all the time. We have a core package that holds the base UserApplication, User accounts, login, authentication, etc. Then, every project we develop extends this base package. There is some duplication - e.g. almost all of the configuration files look identical in each - but each one has it's own theme
directory that supplies the markup, customized to the look and feel of the application.
当你这样做时有一些建议:
Some suggestions as you do this:
- 核心应用程序应该有相当数量的
getXPanel()
每个子应用程序覆盖的方法。例如,getHeaderPanel()
- 使用每个人都扩展的BasePage类。您可以在此处设置整体外观,在子应用程序主题文件夹中覆盖,并大量使用
< wicket:extend>
功能。也是放置jQuery导入的好地方,ec。 - 请记住,标记很容易被覆盖。您的子应用程序不需要创建页面的Java扩展名来更改徽标。只需使用不同的标记。
- The core application should have a fair number of
getXPanel()
methods that each sub-application overrides. For example,getHeaderPanel()
- Use a "BasePage" class that everyone extends. This is where you set up your overall look-and-feel, overridden in sub-application theme folders, and make heavy use of
<wicket:extend>
features. Also a good place to put your jQuery import, ec. - Keep in mind that markup is easily overridden. Your sub-application doesn't need to create java extensions of pages in order to change the logos. Just use different markup.
我们的每个应用程序至少分为4个模块。例如:
Each of our applications is divided into at least 4 modules. For example:
- base - Wicket依赖,基本事件记录
- 数据 - UserApplication,AdminPage,用户休眠对象。每个页面都有自己的标记,但通常会被覆盖。
- science - 一个核心项目,包含大量用于显示科学教科书的代码。
ScienceApplication扩展了UserAppication
。 - 基础 - 针对小学生的主题特定实现
FoundationsApplication扩展了ScienceApplication
- 查询 - 针对高中学生的不同主题特定实施
InquiryApplication扩展ScienceApplication
- base - Wicket dependency, basic event logging
- data - UserApplication, AdminPage, User hibernate obect. Each page has its own markup, but is usually overridden.
- science - A core project with a lot of code for displaying a science textbook.
ScienceApplication extends UserAppication
. - foundations - A theme specific implementation for elementary students
FoundationsApplication extends ScienceApplication
- inquiry - A different theme specific implementation for high school students
InquiryApplication extends ScienceApplication
我们的两个科学应用程序有不同的标题,甚至有几个不同的页面,但 ScienceApplication
有我上面描述的那些方法。
Our two science applications have different headers and even a few different pages, but ScienceApplication
has a those methods I described above.
这篇关于当两个不同的wicket应用程序共享通用功能时,如何重用代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!