Lenar Hoyt
Lenar Hoyt

Reputation: 6159

Correct Objective-C class naming method?

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**?

Upvotes: 0

Views: 160

Answers (5)

Jens Ayton
Jens Ayton

Reputation: 14558

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.

Upvotes: 1

ColdLogic
ColdLogic

Reputation: 7275

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.

Upvotes: 1

user155959
user155959

Reputation:

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.

Upvotes: 2

sergio
sergio

Reputation: 69047

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.

Upvotes: 0

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.

Upvotes: 1

Related Questions