OOP:命名类

发布于 2024-12-07 02:41:13 字数 207 浏览 1 评论 0原文

在我的应用程序中,我有一个带有许多级别的市场。每个级别都有商品和供应链运营。现在,我一直在思考如何命名用这些实体填充级别的一系列类。我知道名称很重要,因为适当的名称可以使代码自我注释。由于像 Builder、Creator、Factory、Provider 这样的东西更多的是一个接线类,所以我没有想法。现在我使用 Market_Level_Goods_Filler,但感觉很奇怪。有什么建议吗?谢谢

In my application I have a Market with a bunch of Levels. Each level has Goods and Supply Chain Operations. Now, I'm stuck figuring out how to name a family of classes that populate Levels with these entities. I know that a name is important in a sesnse that a proper one makes code self-commented. Since stuff like Builder, Creator, Factory, Provider is more of a wiring classes, I'm out of ideas. Right now I use Market_Level_Goods_Filler, but it feels odd. Any suggestions? Thanks

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

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

发布评论

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

评论(2

随遇而安 2024-12-14 02:41:13

就我个人而言,我喜欢使用命令/查询模式作为划分和管理这些类型的方式类。

在这种情况下,你的类将是一个命令。无论哪种方式,我都会命名我的类来描述他们实际所做的事情。

你们班做什么的?

也许是 PopulateLevelsForMarketPopulateMarketLevels? (如果使用命令/查询范例,则为 PopulateLevelsForMarketCommand)。

如果您发现很难命名您的类,因为它执行各种不同的操作,您将需要开始考虑分解该类,以便将焦点集中在一组操作上。

在班级层面考虑SRP

Personally I like to use the Command/Query pattern as a way of dividing and managing these types of classes.

In this context your class would be a command. Either way I'd be naming my classes to describe what they actually do.

What does your class do?

Perhaps PopulateLevelsForMarket or PopulateMarketLevels? (PopulateLevelsForMarketCommand if using the Command/Query paradigm).

If you're finding it hard to name your class because it does a variety of different things you'll want to start thinking about breaking up the class so that the focus is one a single set of operations.

Think SRP at the class level.

孤檠 2024-12-14 02:41:13

您的描述让我认为 MarketLevel 构成了四人帮复合模式。这是正确的吗?

我想说 LevelBuilderLevelLoader 比较合适。我不明白你的“更多的是接线类”[原文如此]的反对意见。对我来说,填充听起来像是一个创造动词。

Your description makes me think that Market and Level make up a Gang of Four Composite pattern. Is that correct?

I would say that a LevelBuilder or LevelLoader would be appropriate. I don't understand your "more of a wiring classes" [sic] objection. Populate sounds like a creation verb to me.

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