Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Technical Support
 Encapsulate Field enhancement
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Pitchfork
New Member

2 Posts

Posted - Jan 17 2007 :  03:26:42 AM  Show Profile  Reply with Quote
When refactoring old code we usually have the situation where we have a public member variable that we want to hide.


class A
{
public:
  
  int x;
}


Now we could use Encapsulate Field to make accessor functions. This gives us the following:



class A
{
public:
  
  int x;
  int X() const { return x; }
  void X(u16 val) { x = val; }
}


But what we really need as next step is to make the member variable private and replace all code accessing it with the appropriate accessor functions. In large codebases with widespread use of some basic classes this would come really handy.

feline
Whole Tomato Software

United Kingdom
18939 Posts

Posted - Jan 17 2007 :  12:18:21 PM  Show Profile  Reply with Quote
This is well beyond the current scope of VA's Encapsulate Field. To start with it would require VA to be very accurate when working out if a given reference to the variable modified it or not - so it would know which function to use in its place.

My gut instinct is that you would run into edge cases where VA produced unwanted results, especially when people start getting clever with macros.

For now have you considered running replace on the variable, and then making sure only "get" operations are ticked and replacing the variable with "getX()", and the same idea for "setX()"? This way a programmer considers all of the code changes, but they are still done in an automatic, quick and simple manor?

zen is the art of being at one with the two'ness
Go to Top of Page

Pitchfork
New Member

2 Posts

Posted - Jan 18 2007 :  03:38:55 AM  Show Profile  Reply with Quote
Yes that is an option but I hoped for a perfect solution :-)

Thanks for you help!
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000