Similar Questions
- When do you write a private method, versus protected?
- Best to use Private methods or Protected methods?
- Reasons to use private instead of protected for fields and methods
My Question
Many people agree that protected methods should be used only when you have a reason to use them. How does a test-driven development model way into this? (Especially with regard to faking objects.) I have a friend who is a big fan of TDD and now BDD and is a C# developer, and he told me he hardly ever uses the private
keyword. After he said that, I kept using it for fields but starting defaulting all of my methods to protected
. Some people on StackOverflow also agree that protected
should be used by default—could some of you please weigh in on this question? What is the best reason to use protected
by default (since the threads above explain reasons not to)?
Edit: per Oded's comment, what about using protected
by default and the Open-Closed Principle (a class should be open for extension and closed for modification)?