Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6246615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T12:43:24+00:00 2026-05-24T12:43:24+00:00

Similar Questions When do you write a private method, versus protected? Best to use

  • 0

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)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T12:43:26+00:00Added an answer on May 24, 2026 at 12:43 pm

    Here’s what I consider a best practice, do with my developments and suggest to all of my clients:

    1. Start with your test (or specification, if you’re into BDD). Production classes and methods that you pull from your tests should be public.
      • Note: If you’re developing in .NET, you may wish to consider using the internal keyword (and adding the InternalsVisibleTo assembly attribute to your production assembly, so that your test project can use the code) instead. Then you would make it public only if another production assembly depends on it.
    2. Any method that you create as part of the refactoring phase of your TDD should be made private.
    3. Make helper methods protected only when a derived production class needs them.
    4. Any method created in the refactoring phase (now private or protected), that you need in another production class should be extracted to a helper class and made public (or internal in .NET, and any language that supports the concept).
    5. If the helper class is needed in another assembly, then:
      • If the other assembly already depends on the helper class’ assembly, make the helper class public (if it isn’t already).
      • If the other assembly does not depend on the helper class’ assembly, extract the helper class to a helper assembly (the best fit, or a new one) and make it public. Be sure to make the original assembly reference the new helper assembly, if it doesn’t already.

    This should pretty much cover all of your cases.
    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I see many similar questions, however I want to find the Username of the
Similar questions have been asked, but nothing exactly like mine, so here goes. We
Similar questions to this one have been asked but none seem to address my
I've seen similar questions and answers regarding conversions from virtual to absolute and url,
I didn't see any similar questions asked on this topic, and I had to
I've seen a few similar questions to this one, but none that were quite
I saw a couple of similar questions on the same topic, but none of
Note: This is the opposite direction to most similar questions! I have an iPhone
I hope this isn't considered a duplicate since it's more pointed than similar questions
There are a couple of questions similar to this on stack overflow but not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.