Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 3
    To prevent the programmer from writing public methods that scroll forever in the vertical direction. You need private methods to break your public method implementations into readable/maintainable/cohesive/reusable(DRY) chunks - each chunk ideally being a private method with an intention revealing name. Commented Apr 12, 2010 at 8:34
  • 1
    It's important to point out that most times you probably don't actually want a private method, but a protected method. (Difference) Commented Jan 26, 2018 at 18:55
  • 1
    @rinogo That’s true in Java and C++, but not in all OO languages (or even most). There is little uniformity across languages for what, if any, difference exists between private and protected. Commented Aug 5, 2020 at 20:38
  • It's not to break up public methods into more readable chunks. That can be done with more public methods, meaning the "privateness" of a method would be meaningless. The purpose of private methods rather is a) to help reduce the size of an object's public API and b) to indicate what's safe to refactor. Commented Nov 8, 2022 at 2:22