为什么特征有时会分组为“关注点”。在PHP软件包中?
查看包源文件时,我经常看到一个名为“关注点”的文件夹,该文件夹似乎仅限于包含特征文件。一些示例:
而其他软件包只有一个名为“特质”的文件夹。例如:
是个人喜好,还是背后有含义将文件夹命名为“关注”?
When looking through package source files, I often see a folder titled "concerns" that seems to exclusively house trait files. A few examples:
While other packages just have a folder named "traits" for traits. Ex:
Is it just personal preference, or is there a meaning behind naming the folder "Concerns"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为这只是社区选择的“足够好”的名字。的确,特征不是“对象”或“工厂”或“存储库” - 他们自己做任何事情,而是在为所使用的类中添加属性和素质。 “关注”一词不仅意味着“令我担心的东西”,还意味着“关于某事”,这通常与特质的目的相匹配。
我个人认为“关注”一词比“特质”更好或更有信息。特别是对于那些熟悉概念和PHP术语的人,以及该文件夹是否确实包含特征。但是有时候,最好选择一个更通用的名称以避免受到特定语言的命名。
只是为了澄清这一点 - 您可以在项目“数据库”中调用文件夹/名称空间,但是如果以后您决定仅存储数据仅在memcache中,那么拥有“ memcache数据库”看起来会出乎意料且很奇怪。但是,如果您选择了一个通用的名称“存储” - 则适合将远程服务的任何数据库,memcache甚至接口都放入其中。
upd :我太好奇了,做了更多的回报。事实证明,在这种情况下,“关注”一词来自Ruby-on-on-cor-on-rails world,它基本上与PHP中的特征相同(另一个相当常见的词是“ mixin”):
“ ://stackoverflow.com/questions/14541823/how-to-use-conconcerns-in-rails-4>如何在Rails中使用关注点4
I think it's just a "good enough" name picked by community. Indeed, traits are not "objects" or "factories" or "repositories" - they don't do anything by themselves, but they are adding properties and qualities to classes where they are used. And the word "concern" doesn't only mean "something that worries me", but also "being about something", which generally matches the purpose of traits.
Personally I don't think the word "concern" is better or more informative than "trait". Especially for those familiar with the concept and PHP terminology and if that folder indeed contains just traits. But sometimes it's good to pick a more generic name to avoid being bound by language-specific naming.
Just to clarify this - you can call a folder/namespace in you project "databases", but if later you decide you store your data only in memcache, it would look unexpected and weird to have "memcache database". But if you picked a generic name "storage" - then any database, memcache or even interface for a remote service is appropriate to be put into it.
UPD: I've got too curious and done a bit more reaserch. Turns out the word "concern" in this context came from Ruby-on-rails world, where it basically means the same as trait in PHP (another pretty common word for this is "mixin"):
https://medium.com/@carlescliment/about-rails-concerns-a6b2f1776d7d
How to use concerns in Rails 4