Whenever I am programming in an object-oriented language, I am always faced with what order and how to group the methods for an object. Are there any standards for this, or any suggestions?

  • 1
    voting to close as impossibly broad.
    – Telastyn
    Commented Jun 9, 2013 at 3:53
  • @MichaelT Progr. by Intention is just one approach for grouping, this question is one level above that. Commented Jun 9, 2013 at 5:53
  • 1
    This is probably a question most programmers will at some point ask themselves. However, I think for the most part this is a matter of coding style and the preference of the programmer and the way in which they like to organise their code.
    – Theomax
    Commented Jun 9, 2013 at 9:30

1 Answer 1


I don't know of any standard, but when I write an object I like to write out the method names first in a functional grouping, in coarse order of execution, with internal methods immediately after the method they were first written to be called by.

Were I asked to re-organize an existing class, of my own or someone else's, my first concern would be to group similar methods together, and have them in rough order of execution frequency. Different method signatures, if allowed, would always be listed together and in order of increasing complexity.

So, if I had a Box class with a constructor and methods to move the box or add contents to it, I might organize them as follows.

  • Constructors first

    1. new Box()
    2. new Box(contents)
  • Main functional group second.

    1. getContents
    2. addItem
    3. removeItem
  • Secondary functional group third.

    1. pickUp
    2. putDown
    3. move
    4. moveLeft
    5. moveRight
    6. moveUp
    7. moveDown

Of course, this is just a style question. Anyone using your code won't see the public methods or properties in internal source order, and anyone having to maintain your code will hopefully use a tool that guides them through it.

Not the answer you're looking for? Browse other questions tagged or ask your own question.