OOP:命名类
在我的应用程序中,我有一个带有许多级别的市场。每个级别都有商品和供应链运营。现在,我一直在思考如何命名用这些实体填充级别的一系列类。我知道名称很重要,因为适当的名称可以使代码自我注释。由于像 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
就我个人而言,我喜欢使用命令/查询模式作为划分和管理这些类型的方式类。
在这种情况下,你的类将是一个命令。无论哪种方式,我都会命名我的类来描述他们实际所做的事情。
你们班做什么的?
也许是
PopulateLevelsForMarket
或PopulateMarketLevels
? (如果使用命令/查询范例,则为 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
orPopulateMarketLevels
? (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.
您的描述让我认为
Market
和Level
构成了四人帮复合模式。这是正确的吗?我想说
LevelBuilder
或LevelLoader
比较合适。我不明白你的“更多的是接线类”[原文如此]的反对意见。对我来说,填充听起来像是一个创造动词。Your description makes me think that
Market
andLevel
make up a Gang of Four Composite pattern. Is that correct?I would say that a
LevelBuilder
orLevelLoader
would be appropriate. I don't understand your "more of a wiring classes" [sic] objection. Populate sounds like a creation verb to me.