SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: Class naming

  1. #1
    SitePoint Member
    Join Date
    May 2013
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Class naming

    How do you name your classes/objects?

    I see a lot of different approaches, some using verbs, some is using nouns, or a combination of both(?)

    What do you use, and why?
    A few examples:

    PHP Code:
    class Validate{}
    class 
    Validator{}

    class 
    XmlWrite{}
    class 
    XmlWriter{} 
    What`s the better naming? Maybe it`s just personal preferences, or?

  2. #2
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    Personal Preference, just remain consistent.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  3. #3
    SitePoint Addict skunkbad's Avatar
    Join Date
    Apr 2008
    Location
    Temecula, CA
    Posts
    272
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just pick the naming convention that you like and stick with it.

  4. #4
    SitePoint Member
    Join Date
    May 2013
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So it`s not considered bad practice ending class names with "er"? e.g. FileDownloader, PdfReader and so on?

    And yep, one could argue it`s just personal preference, but doesn`t proper OOP has some "do's and don'ts" on this topic?

    The “-er-er” principle. Challenge any class name that ends in “-er.” If it has no parts, change the name of the class to what each object is managing. If it has parts, put as much work in the parts that the parts know enough to do themselves.
    Thanks for the replies.

  5. #5
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    There is no such thing as "proper" OOP. There are some helpful hints and guides for effective managing but in truth it is all personal preference.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.


  6. #6
    SitePoint Member
    Join Date
    May 2013
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hum, okey, so naming one class User and one ProfileUpdater is kind of, bad, then? User and UpdateProfile could be cool too, but sometimes I prefer naming some of my classes with an "er" ending.

  7. #7
    . shoooo... silver trophy logic_earth's Avatar
    Join Date
    Oct 2005
    Location
    CA
    Posts
    9,013
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    The name of the class should describe what the object does. Having a "User" object and a "ProfileUpdater" object is not back. Both labels are clear. The part about being consistence is when it comes to when using verbs to name a "DOING" object. If you are using Updater, Reader, Writer as verbs, using them for all those cases. Don't have "UpdateProfile" if you are using Verbs.
    Logic without the fatal effects.
    All code snippets are licensed under WTFPL.



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •