When do you write a private method, versus protected?
oop
Solution
`public` and `protected` methods form the 'interface' to your object, `public` for developers using (delegating to) your class, and `protected` for developers wishing to extend the functionality of your object by subclassing it.
Note that it's not necessary to provide `protected` methods, even if your class will be subclassed.
Both `public` and `protected` interfaces need careful thought, especially if this is an API to be used by developers outside your control, since changes to the interface can break programs that make assumptions about how the existing interface works.
`private` methods are purely for the the author of the object, and may be refactored, changed and deleted at will.
I would go for `private` by default, and if you find you need to expose more methods, have a careful think about how they will be used - especially if they are virtual–what happens if they are replaced completely with an arbitrary alternative function by another developer–will your class still work? Then design some appropriate `protected` which are useful for developers subclassing your object (if necessary), rather than exposing existing functions.
Problem
If I'm writing a class, when do I make a method private, versus protected? In other words, how I can know in advance that a client programmer would never ever need to override a method? In a case where it's something that has external considerations, like a database connection?