Someone mentioned accessor methods?

Sascha Herrmann starfox899 at web.de
Tue Mar 9 22:17:03 UTC 2004


Steven T. Hatton wrote:
> Also, C++ers tend to simply use the name of the member field as the name of 
> the retrieval (getter) method.  Agreed? 
> 
> What about passing a reference verses passing a value; to the mutator 
> (setter)?; as the return value?  
> 
> What about constness? 
> 
> Does someone have a paradigm for this they would like to share?

Hi,
i wont claim to set up a paradigm but in my eyes that should look like:

class test {
public:
     test();
     ~test();
     // get...
     const double& getSize() const;
     // set... (for "big" structures or whenever copying takes to long)
     void setSize(const double& newValue);
     // maybe better for standard types
     void setSize(const double newValue);
protected:
     double m_Size;
};

setters should be void because modern error handling should be done with 
exceptions (that`s what i think!). To improve things further we should 
create a template for get/setters so anybody can choose his favorite style.

bye sascha

PS: i am away untill sunday, so do not expect any answers from me next 
days ;-)




More information about the KDevelop-devel mailing list