选择哪种设计模式
因此,我最终遇到了这样的情况:我参与的一个项目有两种类型的列表(至少目前如此):预订和轮班列表。制作这两个列表是为了让我们拥有一个包含这两个列表的逻辑的 List 对象,以及用于各个功能的单独的 Shift 和 Booking 列表对象。
List 对象开始变得难以承受。它具有分页、编辑器功能、选择和双击打开弹出窗口、鼠标悬停弹出窗口以及过滤和分页。我想将代码重构为更易于维护的东西,也许重构为更小的单元。我应该在这里考虑哪些设计模式?
如果重要的话,List 对象包含超过 3k 行的 OO JavaScript 代码。
So I have ended up in a situation with a project I'm part of that has two types of lists (at the moment, at least): booking and shift list. Both lists are made so that we have a List object containing logic for both of them, and a separate Shift and Booking list objects for individual features.
The List object is starting to be overwhelming. It has pagination, editor capabilities, selection and double click to open popups, mouse hover popups as well as filtering and paging. I would like to refactor the code to something more maintenable and perhaps into smaller units I suppose. What design patterns should I be thinking about here?
If it matters, the List object contains over 3k lines of OO JavaScript code.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实上,这是压倒性的。没有简单的答案或选择的设计模式。我将开始应用“关注点分离”设计原则。一类/一组函数只做一件事。这将有助于降低复杂性。然后您可以应用结构设计模式。首先,您可以使用委派。在您的情况下,装饰器设计模式可以适合,因为您可以根据功能“装饰”基本列表用法...
在考虑 DP 之前,请考虑关注点分离,将代码划分为易于理解的小部分。然后使用一些 DP 将它们全部链接起来。
祝你好运 !
我的2c
Well in fact it is overwhelming. There is no simple answer or chosen design patterns. I will begin to apply the "separation of concern" design principle. One class/set of functions only do one thing. That will help to reduce the complexity. Then you can apply structural design patterns. To begin, you can just use delegation. In your case the decorator design pattern can fit as you can "decorate" the basic list with functionalities depending of the usage ...
Before thinking DP, think separation of concern to divide your code in small understandable parts. Then use some DP to link them all.
Good luck !
my2c