Naming convention (Singular or plural name class)

I have a class that modelizes a Shop. So it has the following attributes:

  • name
  • description
  • address
  • phone
  • ... etc.
  • Should I have to name it ShopInfo or ShopInfos ?

    Any link to a naming convention?


    If you have an object of the class, it is only the information for one shop. The object describes one shop info. It is common use to write a class name that way, that it makes sense when using an object .

    Especially in method names and declaring variables it is clearer

    // CORRECT WAY
    - (UIAlertView *)calcualteSomething:(UIView I)view {
        UIView *newView = view;
        ...
        return [UIAlertView alertWith...];
    }
    

    It would be very odd to use the plural form in my opinion (it seems like the single object is more than one!):

    // BAD IDEA
    - (UIAlertViews *)calcualteSomething:(UIViews *)view {
        UIViews *newView = view;
        ...
        return [UIAlertViews alertWith...];
    }
    

    You can then easily use the object or test for the class and it makes sense too:

    [myObject isKindOfClass:[NSString class]]
    

    Here is the official link how you should write a name:

    https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CodingGuidelines/Articles/NamingBasics.html#//apple_ref/doc/uid/20001281-BBCHBFAH

    And there you see, Apple always avoids using the plural form (NSString, NSArray, etc.).

    Of course the other way around it also makes sense, but then more for class methods etc. . Other popular languages also use singular form for classes.


    Some other good coding guidelines is from CocoaDevCentral

    http://cocoadevcentral.com/articles/000082.php

    http://cocoadevcentral.com/articles/000083.php


    ShopInfo是正确的,ShopInfos对于例如ShopInfo数组很有用,但它不会被推荐,因为名称相似性可能会导致混淆。

    链接地址: http://www.djcxy.com/p/85308.html

    上一篇: .NET XML文档中的参考前缀

    下一篇: 命名约定(单数或复数名字类)