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
 Feature Requests
 1649: Encapsulate field behaviour
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Frunobulax
Ketchup Master

84 Posts

Posted - Sep 17 2008 :  06:59:43 AM  Show Profile  Reply with Quote
Hi,

consider the following code, VS2005/C++:

class _Bar;

class _Foo {
public:
    _Foo() {}
private:
    _Bar _member;
};


Using encapsulate field on _member results in the functions

    _Bar getMember() const { return _member; }
    void setMember(_Bar val) { _member = val; }

below the member.

I have two problems with that:
(1) The encapsulated functions shouldn't be private. I realize that it may not be clear where the implementation should be placed (if there are several public sections), but placing them in private or protected sections will be reliably wrong.

(2) I would prefer passing the parameters as const reference, i.e.

    _Bar const& getMember() const { return _member; }
    void setMember(_Bar const& val) { _member = val; }

(I do know that I can edit the snipped and I did, but I would still suggest to change the default snippet.).

Apart from the obvious performance issues (although the optimizer should handle most cases) if the copy constructor is expensive, this is risky code if the member is something like a STL container and calling programs try to construct iterators from the result of getMember().

Maybe it would make sense to have two variations of encapsulate field, one that passes parameters as const reference and one that doesn't.

Regards, Thomas

"The nice part about being a pessimist
is that you are constantly being either
proven right or pleasantly surprised."
(George F. Will)

accord
Whole Tomato Software

United Kingdom
3287 Posts

Posted - Sep 18 2008 :  2:50:26 PM  Show Profile  Reply with Quote
Point 1
You can edit Encapsulate Field to something like this:

public:
	$end$$SymbolType$ $GeneratedPropertyName$() const { return $SymbolName$; }
	void $GeneratedPropertyName$($SymbolType$ val) { $SymbolName$ = val; }
private:


Point 2:
We have a feature request: Encapsulate Field should pass object instances by reference.

case=7382

I have put in a note on this case about the idea to create two different snippets, which can be an another approach.

Edited by - accord on Sep 18 2008 2:58:54 PM
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