Objective-C 类的命名方法正确吗?
我应该如何调用时间线自定义视图的类?我的项目的前缀是HM
。
HMTimelineView
或者
HMTimeline
我不应该用后缀 View
命名任何视图类吗?但为什么是 NSButton
而不是 NSImage**View**
呢?
how should I call a class for a timeline custom view? My project's prefix is HM
.
HMTimelineView
or
HMTimeline
Shouldn't I name any view class with the suffix View
? But why is it NSButton
but NSImage**View**
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
对我来说,HMTimeline 听起来它可能是一个模型对象,所以我建议使用“View”后缀,但这是您必须根据您认为使代码更易于理解的方式做出的决定。
可能有一些我不知道的命名规则,但我相信 NSButton 不被称为 NSButtonView 因为按钮本质上是客户端可见的界面对象 - 它不呈现特定的模型对象,并且不太可能与模型对象混淆,因此省略后缀很方便。
To me, HMTimeline sounds like it could be a model object, so I would recommend the "View" suffix, but this is a decision you'll have to make based on what you think makes your code easier to understand.
There may be naming rules regarding this that I'm not aware of, but I believe NSButton isn't called NSButtonView because a button is intrinsically a client-visible interface object--it doesn't present a specific model object and is unlikely to be confused for a model object, so it's convenient to leave off the suffix.
如果它是从 UIView 继承的
,那么
如果它是从 NSObject 继承的
,那么
你必须明白,
每当有人去使用像 HMTimelineView、HMTimeline 这样的 urCustom 对象时,他们就会自动知道
if it is inherited from UIView
then
if it is inherited from NSObject
then
u have to understand that
whenever anyone go to use urCustom objects like HMTimelineView,HMTimeline then then they will automatically come to know
如果你的对象只是一个视图,那么你可以把视图放在它的末尾。
NSButton
和NSImageView
的区别是因为NSButton
有一个视图,它本身不仅仅是一个视图,它是一个按钮:P 。NSImageView
是图像的视图,它有图像,但是是查看图像的对象。也没有“正确”的方法。与
HMTimelineView
相比,使用HMTimeline
不会破坏您的代码。它只是帮助开发人员理解对象是什么的一种方法。If you object is just a view, then you can put view on the end of it. The difference in
NSButton
andNSImageView
are because anNSButton
has a view, it itself is not a just a view, it is a button :P.NSImageView
is the view of the image, it has an image, but is the object to view the image.There also isn't a "correct" way. Using
HMTimeline
by comparison toHMTimelineView
will not break your code. Its just a way to help a developer understand what the object is.“View”后缀在 Cocoa 中的使用不一致。一般来说,
NSControl
及其公共子类不使用“View”,但也存在一些不一致的地方(如NSText
)。一般来说,呈现内容的视图(我假设“时间轴视图”就是这样)应该有一个“View”后缀。The “View” suffix is used inconsistently in Cocoa. Generally speaking,
NSControl
and its public subclasses don’t use “View”, but there are some inconsistencies (likeNSText
). In general, a view that presents content (which I assume a “timeline view” does) should have a “View” suffix.我想,这很大程度上取决于您的偏好,以及组成您的应用程序的整套类名称的可理解性。很大程度上还取决于约定,您只需通过查看其他代码的编写方式(大部分是相同的 SDK)即可了解这些约定。
我认为
HMTimelineView
比HMTimeline
更容易理解。您还必须考虑您可能会有一个HMTimeLineViewController
,因此HMTimeLime
可能会不明确。如果您愿意,请想一想:视图、控制器和模型在设计模式 (MVC) 中发挥着作用,因此使用后缀来标识它们非常有用。对于委托类也是如此,其中后缀也是常见的。关于
NSButton
,它当然是继承自NSView
,但它的直接类是NSButton
;所以,从某种意义上说,我认为它的“控制性质”优于视图性质,并且NSButton
比UIButtonView
更容易理解。希望这有帮助。
This highly depends on your preferences, I guess, and understandability of the whole set of class names that make up your app. Much also depends on conventions that you will simply learn by looking at how other code is written, mostly the same SDK.
I think that
HMTimelineView
is far more understandable thanHMTimeline
. You also have to think that possibly you will have aHMTimeLineViewController
, soHMTimeLime
would be possibly ambiguous. Think of this, if you want: views, controllers, and models play a role in a design pattern (MVC) so that it is useful to identify them with a suffix. The same can be said for delegate classes, where the suffix is also usual.About
NSButton
, it certainly derives fromNSView
, but its direct class isNSButton
; so, in a sense, I think that its "control nature" prevails on the view nature, andNSButton
is far more understandable thenUIButtonView
.Hope this helps.