具有 3 种模式的 Java 客户端/服务器应用程序

发布于 2024-09-14 23:20:17 字数 280 浏览 3 评论 0原文

我是一名大学生,我必须在月底之前完成以下任务...... 我必须用java编写一个客户端/服务器应用程序,它实现3种模式:好莱坞原则外观模式模板方法模式...必须至少有 3-4 个域对象...数据库必须是 MS Access(我知道,我知道...) 我应该查看任何建议或资源,一些类似的工作,因为我不知道从哪里开始? 我正在考虑制作图书馆应用程序。我感兴趣的是您将使用什么域对象以及您将如何开始......

I am a college student, and I have to complete following task by the end of the month...
I have to write a client/server application in java that implements 3 patterns: Hollywood principle, Facade pattern and Template method pattern... It must have at least 3-4 domain objects... Database has to be MS Access (I know, I know...)
Any suggestions or resources that I should look at, some similar work, cause I dont know where to start?
I was thinking about making Library application. I am interested what would you use for domain objects and how would you start...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夕嗳→ 2024-09-21 23:20:17

好吧,如果您想构建一个图书馆应用程序,那么请考虑一个已经存在的应用程序以及它可以使用哪些域对象。就像当您访问某个网站时(在大多数情况下)必须登录一样,对吧?那么这就意味着有一个用户类别。假设您至少需要两个用户,那么您可以创建一个抽象用户,一个图书馆员和一个图书馆用户(或者您想要称呼想要租借书籍的人的任何名称) - 在这里您可以使用模板方法模式 我猜是这样的。然后想想你在图书馆做什么?好吧,你租书,所以你需要一个图书课程!是否要使其抽象并创建一些子类取决于您。这将为您提供至少 3-4 个域对象。

对于 Vinynag 所说的好莱坞原则,使用像 Spring 或 Google Guice 这样的 IoC/DI 框架会容易得多,问题是你可以这样做吗?如果没有,那么您将不得不手动注入所有内容,这并不难,但现在在大多数情况下手动执行是没有意义的。

我不得不说我对 MS Access 一无所知,但如果它是类似 MySQL/PostgreSQL/Oracle 的东西,那么对于对象关系映射我会选择 Hibernate,基础知识非常非常简单,添加用户/书籍,根据某些标准等找到它们应该不成问题!

至于立面图案……好吧,现在已经很晚了,我想不出任何东西,所以我将它留给你去弄清楚。

哦,我想你也可以在视图部分使用一些东西,那么我建议使用 JSP 或 JSF,两者都非常简单。因为它是一个小型应用程序,所以我首先制作 UML 图,然后编写应用程序的“主干”代码(域对象,添加 Hibernate/Spring 注释),然后添加 JSP/JSF 页面并开始放置它一起添加一些业务逻辑,然后添加一些 DAO 来启动并运行数据库连接。

Well if you want to build a library app then think of one that already exists and what domain objects it could be using. Like when you visit one you (in most cases) have to log in, right? Then that means there is a user class. Lets say you need at least two users, then you can make an abstract User, a Librarian and a LibraryUser (or whatever you want to call the people who want to rent the books) - here you could use the Template Method pattern for something I guess. Then think what do you do at a library? Well you rent books, so you'll need a Book class! Whether you want to make it abstract and make some subclasses is up to you. That will give you at least 3-4 domain objects.

For the Hollywood principle as vinynag said it would be much easier to use an IoC/DI framework like Spring or Google Guice, the question is are you allowed to do that? If not, then you'll have to manually inject everything, it's not that hard but nowadays it's just pointless to do it manually in most cases.

I have to say I don't know a thing about MS Access but if it's anything like MySQL/PostgreSQL/Oracle then for the Object-Relational Mapping I'd go with Hibernate, the basics are really really simple and adding users/books, finding them according to some criteria etc. shouldn't be a problem!

As for the facade pattern... well it's quite late here and I can't think of anything atm, so I'll leave it for you to figure out.

Oh also I guess you could use something for the view part also, then I'd suggest either JSP or JSF, both are quite simple. Since it's a small app I'd start with making a UML diagram, then code the "backbone" of the app (the domain objects, add the Hibernate/Spring annotations) then I'd add the JSP/JSF pages and start putting it together, add some business logic and then some DAOs to get the DB connection up and running.

热风软妹 2024-09-21 23:20:17

Spring 框架最适合这种情况。它具有您正在寻找的所有三种模式。

Spring Framework is best suited for this. It has all three patterns you are looking for.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文