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

  • SEARCH
  • Home
  • 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 8092555
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:18:38+00:00 2026-06-05T20:18:38+00:00

oo design basics here… Edit: To clarify after first answer – I’m not asking

  • 0

oo design basics here…

Edit:
To clarify after first answer – I’m not asking how to fix this but whether on the face of it the design seems screwy. I don’t want to point out the original code for social considerations.

I’m working with some code that has a virtual method which does nothing but modify a private member variable of the class. I’d like to just change the details of that modification. That’s the only behavior I want to change, but I can’t reference the private member, so I can’t just override the method. On the face of it, is that design by the original author wrong/odd, or is this not enough information to say?

public class X
{
    private List<string> InterestingThings = new List<string>();

    public virtual void MethodIWantToOverride(string rawData)
    {

         string fixedData = ... 
         // do some fancy stuff to clean up data that I want to come thru 'dirty'
         InterestingThings.Add(fixedData);
    }
 }
  • 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-06-05T20:18:39+00:00Added an answer on June 5, 2026 at 8:18 pm

    If the purpose of the code is to enforce some invariant upon items which get added to the list, requiring that all attempts to add items to the list go through a virtual method would be a way to achieve that. Exposing the list field as protected would allow derived classes to violate the base-class invariant. If that’s what you’re trying to do, and if you will be upholding all portions of the invariant that code actually relies upon, you might make the list field protected, but I would suggest that you at least consider adding another protected, possible virtual, base-class method to mutate it in a way that upholds a weaker invariant.

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

Sidebar

Related Questions

Look here (Abstract Class Design): http://msdn.microsoft.com/en-us/library/ms229047.aspx It says: (1) Do not define public or
My problem design is seen here (using browser not IE). And the target design
This should be a very basic design question, but for some reason it doesn't
Here's the basics of the system we have in place today. We have a
This is a homework question, I got the basics down, but I can't seem
This is more of a MVVM application design question. I'm trying to implement a
I have in mind a design problem that does not look like complex, but
I'm first time poster here trying to pick up some Python skills; please be
This is a design issue I keep running into, so I thought I would
I have a design and object structuring related question. Here is the problem statement:

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.