Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Technical Support
 Encapsulate Field enhancement

You must be registered to post a reply.
Click here to register.

Screensize:
UserName:
Password:
Format: BoldItalicizeUnderlineStrikethrough Align leftCenterAlign right Insert horizontal ruleUpload and insert imageInsert hyperlinkInsert email addressInsert codeInsert quoted textInsert listInsert Emoji
   
Message:

Forum code is on.
Html is off.

 
Check to subscribe to this topic.
   

T O P I C    R E V I E W
Pitchfork Posted - Jan 17 2007 : 03:26:42 AM
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.
2   L A T E S T    R E P L I E S    (Newest First)
Pitchfork Posted - Jan 18 2007 : 03:38:55 AM
Yes that is an option but I hoped for a perfect solution :-)

Thanks for you help!
feline Posted - Jan 17 2007 : 12:18:21 PM
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?

© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000