Java类设计

发布于 2024-10-09 14:40:32 字数 268 浏览 0 评论 0原文

所以我正在制作这个 Web 应用程序,到目前为止,有一个数据库类可以处理数据库功能 queryMovies、updateMovies 和 getConnection。现在我想将从文件目录中检索到的电影标题数组解析到 addMovies 中。添加此功能最有效的方法是什么?

我应该将其添加到数据库构造函数中并使用数组成员变量吗?另一个班级?在servlet 中?想想看,我可能想添加一些函数来文件字符串名称检索以获得更多模块化......也许另一个类是最好的。此功能始终用于数据库查询嗯。嗯。一些帮助会很棒。

So I have this web application I am making, as of now there is a Database class that handles database functionality queryMovies, updateMovies, and getConnection. Now I want to parse an array of movie titles retrieved from a file directory into addMovies. What would be the most efficient way to add this functionality?

Should I add it in the Database constructor and use an array member variable? another class? in the servlet? Come to think of it I may want to add some functions to file string name retrieval for more modularity... maybe another class would be best. This functionality would always be used for database queries hmmm. hmmm. Some help would be great.

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

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

发布评论

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

评论(1

满地尘埃落定 2024-10-16 14:40:32

下面的内容可以帮助您入门。请记住针对接口编写代码,以便轻松单元测试。保持抽象的重点(单一职责原则

public interface FileParser
{
    List<Movie> parse(String filePath);
}

public class Movie
{
    ...
}

public class FileHandler
{
    MovieRepository repo=new MovieRepository();
    void storeMovies(List<Movie> movies);
}

pubic class MovieRepository
{
    //handles CRUD by talking to the DB
} 

The below can get you started. Remember to code against interfaces so that it is easy to unit test. keep the abstractions focused (Single Responsibility Principle)

public interface FileParser
{
    List<Movie> parse(String filePath);
}

public class Movie
{
    ...
}

public class FileHandler
{
    MovieRepository repo=new MovieRepository();
    void storeMovies(List<Movie> movies);
}

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