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 3456464
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T09:44:23+00:00 2026-05-18T09:44:23+00:00

I am currently refactoring a very useful but poorly designed class in C++, and

  • 0

I am currently refactoring a very useful but poorly designed class in C++, and I’m running into a problem with the design: rather passing data around using arguments to methods, the data is passed around by setting private state variables in the class. This makes it very difficult for me to diagram out how data moves through functions. It’s my weekend task to try and remove this style of passing data around as much as possible, as makes the program very impossible to understand from just the method signatures, as the signatures only tell a part of the story. I’ve decided

My current approach to test if a method communicates using private class-level variables is the following:

  1. Edit the method and make it a function rather than a method, which removes its access to the state variables in the class.
  2. Edit all of the calls to the method so that they call the function rather than the method.
  3. Compile, see if anything breaks. Make a list of accessors to add to the original class.
  4. Run the unit tests to see if I’ve broken anything in a very subtle way.

Is there a better way of doing this, perhaps one that can be easily automated? Is this refactoring a well-known technique that I can cite if I show it to other people?

The only mention of this problem that I’ve found so far is this quote from Coders at Work via the Object-oriented programming Wikipedia entry:

“The problem with object-oriented languages is they’ve got all this implicit environment that they carry around with them. You wanted a banana but what you got was a gorilla holding the banana and the entire jungle.” – Joe Armstrong

Edit in response to a good question from Oli Charlesworth:

I understand that the point of OOP is to sometimes communicate through state variables of the class. The difficulty with my current case is that there are currently 78 different data members in the class, many of which are key-value pairs of strings to other data types, and there are undocumented implicit dependencies on the order in which they need to be initialized. It’s possible that given a sufficiently smart programmer working with this class would be easy, but it’s currently very difficult for me. I think that several of these data types could be abstracted into their own classes, but before I can do that I need to understand more clearly how the data members interact with each other.

  • 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-18T09:44:23+00:00Added an answer on May 18, 2026 at 9:44 am

    Given the clarification in the question my “are you sure it’s not just that you don’t like the other programmer’s style” comment dies a death 😉

    Personally I’d just refactor normally. That is, with 78 data members and lots of bits that are related but not in a class of their own I’d start by grouping the related data and extracting the functionality that works on it. There’s no need, IMHO, to go through a stage where you explicitly pass the data into the functions in the existing class. Just pick a group of related data items, come up with a decent name, extract them and work out where they were used and how you need to move functionality into the new class.

    Ideally, I’d start writing unit tests for the main class and the new broken out classes as I went along…

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

Sidebar

Related Questions

I'm currently working on refactoring a large amount of CSS, and a common trend
I am currently busy refactoring big parts in my application. The main purpose is
We are currently in the process of refactoring our site and we have decided
I'm currently editing a good sized class in C# that has a ton of
I'm doing some refactoring work on PHP/MySQL code and stumbled across an interesting problem,
I'm currently involved in a project that is migrating some old VB6 code to
I'm currently writing a PyGTK application and I'd like some advice as to the
I am a Asp.Net developer, currently working on Webforms in 3.5. I do C#
It's possible (even probable) that I'm just not fully grokking the concept of a
Along with: An attempt was made to load a program with an incorrect format

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.