Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
 All Forums
 Visual Assist
 Feature Requests
 1649: Encapsulate field behaviour

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
Frunobulax Posted - Sep 17 2008 : 06:59:43 AM
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
1   L A T E S T    R E P L I E S    (Newest First)
accord Posted - Sep 18 2008 : 2:50:26 PM
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.

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