Index
Getter Concept


A getter has a simple single purpose which is to return the ivar value for the associated ivar.

The associated ivar is named like this:

Given ivar: "foo"
Associated getter name: "getFoo"


And specifically for our example:

Given ivar: "width"
Associated getter name: "getWidth"


Getters (Accessors)


Getter accessors get (or access) data (ivar value) from the given object and return it. This is the normal use of the term "getter".

These examples are in JavaScript, but the idea is the same in any object language.

Getter for ivar "width"
getWidth() {
	return this.width;
}
Getter for ivar "height"
getHeight() {
	return this.height;
}

Getters (Other)


We may use the term "getter" more broadly for a method that simply "gets" and returns a value. It may calculate the value, get it from a database, etc (but the bottom line is it returns a value).

Compute area of rectangle as width * height.
Return computed value
getArea() {
	return this.width * this.height;
}
Compute perimeter (boundary length) of rectangle as total (sum) length of all edges.
Return computed value
getPerimeter() {
	return 2 * (this.width + this.height);
}