Rustang
Rustang

Reputation: 546

A getter method that doesn't necessarily get a member's value?

Say I have a C++ class that holds an array.

A member function of this class for example, could be to return the value at a certain index. I'm confident this would be considered a getter method.

However, how would you classify a similar function that instead simply returns a boolean based on whether or not the value exists in the array?

This function is 'getting' something but not necessarily a value from a member of the class. Would this still be considered a getter method?

Upvotes: 0

Views: 97

Answers (1)

463035818_is_not_an_ai
463035818_is_not_an_ai

Reputation: 123263

Does it really matter? Consider this interface:

struct Adder {
    Adder(int a,int b);
    int get_sum();
};

for the user of this class it should not matter at all whether implementation is this:

struct Adder {
    Adder(int a,int b) : a(a),b(b) {}
    int get_sum() { return a+b; }
private:
    int a,b;
};

or this:

struct Adder {
    Adder(int a,int b) : c(a+b) {}
    int get_sum() { return c; }
private: 
    int c;
};

The second does return a member and according to your definition it would be a "getter" method. The first does not, but does it mean that it is not a true "getter" method? Whether the method actually returns a member or something else is an implementation detail and should not matter to the caller, nor should it affect the name you give to the method.

Upvotes: 2

Related Questions