Hi, I would like learn from people with experience in C++, which of the
following styles of way to construct "get/set" member functions would be the
best in terms of usability, speed, et cetera.
The following class with be used as an example:
class MyClass {
public:
// member function would go here.
private:
int data_;
};
Way #1:
int getData() const;
void setData(const int);
Way #2:
int getData() const;
int setData(int); // returns data_
Way #3:
int data() const;
void data(int);
Way #4:
int data() const;
int data(int); // returns data_
My preference would be to use the fourth way, but I would like to know which
of the ways listed should be prefered or if there are any other ways that
should have been included.
Also, I notice that people who are into OOA and OOD seem to use getBlah, and
setBlah. Why is this the case? Were most of these individuals influened by
one source and that is why they all share the same way of doing it?
Thanks.
following styles of way to construct "get/set" member functions would be the
best in terms of usability, speed, et cetera.
The following class with be used as an example:
class MyClass {
public:
// member function would go here.
private:
int data_;
};
Way #1:
int getData() const;
void setData(const int);
Way #2:
int getData() const;
int setData(int); // returns data_
Way #3:
int data() const;
void data(int);
Way #4:
int data() const;
int data(int); // returns data_
My preference would be to use the fourth way, but I would like to know which
of the ways listed should be prefered or if there are any other ways that
should have been included.
Also, I notice that people who are into OOA and OOD seem to use getBlah, and
setBlah. Why is this the case? Were most of these individuals influened by
one source and that is why they all share the same way of doing it?
Thanks.
Comment