Reputation: 7995
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)?
Upvotes: 4
Views: 1483
Reputation: 6317
Here's what I consider a best practice, do with my developments and suggest to all of my clients:
This should pretty much cover all of your cases.
Hope this helps.
Upvotes: 10