Objective-C 类的命名方法正确吗?

发布于 2024-11-26 23:35:12 字数 245 浏览 0 评论 0原文

我应该如何调用时间线自定义视图的类?我的项目的前缀是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 技术交流群。

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

发布评论

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

评论(5

千鲤 2024-12-03 23:35:12

对我来说,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.

不乱于心 2024-12-03 23:35:12

如果它是从 UIView 继承的

,那么

     HMTimelineView will be best

如果它是从 NSObject 继承的

,那么

      HMTimeline will be best.

你必须明白,

每当有人去使用像 HMTimelineView、HMTimeline 这样的 urCustom 对象时,他们就会自动知道

   "oh it would be from View" -for HMTimelineView.

   "oh it would be from NSObject" -for HMTimeline.

if it is inherited from UIView

then

     HMTimelineView will be best

if it is inherited from NSObject

then

      HMTimeline will be best.

u have to understand that

whenever anyone go to use urCustom objects like HMTimelineView,HMTimeline then then they will automatically come to know

   "oh it would be from View" -for HMTimelineView.

   "oh it would be from NSObject" -for HMTimeline.
柠栀 2024-12-03 23:35:12

如果你的对象只是一个视图,那么你可以把视图放在它的末尾。 NSButtonNSImageView 的区别是因为 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 and NSImageView are because an NSButton 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 to HMTimelineView will not break your code. Its just a way to help a developer understand what the object is.

唔猫 2024-12-03 23:35:12

“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 (like NSText). In general, a view that presents content (which I assume a “timeline view” does) should have a “View” suffix.

拔了角的鹿 2024-12-03 23:35:12

我想,这很大程度上取决于您的偏好,以及组成您的应用程序的整套类名称的可理解性。很大程度上还取决于约定,您只需通过查看其他代码的编写方式(大部分是相同的 SDK)即可了解这些约定。

我认为 HMTimelineViewHMTimeline 更容易理解。您还必须考虑您可能会有一个 HMTimeLineViewController,因此 HMTimeLime 可能会不明确。如果您愿意,请想一想:视图、控制器和模型在设计模式 (MVC) 中发挥着作用,因此使用后缀来标识它们非常有用。对于委托类也是如此,其中后缀也是常见的。

关于NSButton,它当然是继承自NSView,但它的直接类是NSButton;所以,从某种意义上说,我认为它的“控制性质”优于视图性质,并且 NSButtonUIButtonView 更容易理解。

希望这有帮助。

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 than HMTimeline. You also have to think that possibly you will have a HMTimeLineViewController, so HMTimeLime 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 from NSView, but its direct class is NSButton; so, in a sense, I think that its "control nature" prevails on the view nature, and NSButton is far more understandable then UIButtonView.

Hope this helps.

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