Public mutator methods in object-oriented programming, responsible for changing and returning the value of private class members, thus keeping with the principle of encapsulation.
Questions tagged [getter-setter]
2157 questions
0
votes
1 answer
Python: Directly access setter method of property when using the @property decorator
I want to make use of properties in python while still being able to call the setter method of a property directly in some cases. The reason being, that I need to assign variables in lambda statements while using PySide/PyQt.
The following example…

johnson
- 3,729
- 3
- 31
- 32
0
votes
2 answers
Typescript: why is get necessary in this case?
I'm following this auth0 tutorial. In this particular service, only one method has get in front of it.
I read this answer and some tutorials, but it really didn't clarify anything in this particular case.
As I understand it, getters go along with…

james keller
- 99
- 2
- 7
0
votes
1 answer
Dynamically adding Spinner and handling each onItemSelected event
I am trying to get values from spinner which are generated dynamically using getter and setter and custom adapter. I am able to display it, but i want to add onclicklistners to each of spinner generated and add get the selected value from it and…

New learner
- 202
- 1
- 2
- 14
0
votes
1 answer
Passing parameter to class property in Java
I have this property in a visual basic class. NET 2008, the property in addition to the get and set has a parameter called "pParam. "
Public Property UpdateField(ByVal pParam As String) As String
Get
Return Me.idField
End…

seba123neo
- 4,688
- 10
- 35
- 53
0
votes
0 answers
Setters relation in doctrine
My Item.orm.yml:
AppBundle\Entity\Item:
type: entity
manyToMany:
categories:
targetEntity: AppBundle\Entity\Category
cascade: ['persist']
inversedBy: items
joinTable:
…

Dialkord
- 111
- 1
- 3
- 12
0
votes
0 answers
Why can we customize ctors & dtors but not accessors?
(This is not a question about overloading operator. in general.)
We know that there are many good reasons to use setter and getter methods.
Well, then, it seems strange to me these are not customization points of member access i.e. if class A has a…

einpoklum
- 118,144
- 57
- 340
- 684
0
votes
1 answer
JavaScript Empty Setter Method Error
Given this code:
let person = {
_name: 'Lu Xun',
_age: 137
}
Need to add new setter method to change the person's age. I'm trying to add an empty age setter method, but get an error message Unexpected identifier or "Must have at least one…

Charity
- 1
- 1
0
votes
0 answers
Less clunky way to generate properties?
TLDR:
What is the best way to build a class with generic property attributes and one can specify the getter and setter upon building those attributes?
Background:
I'm trying to make an object oriented representation of a SCPI command structure with…

Azial
- 179
- 1
- 9
0
votes
2 answers
Can't get variable from GUI into main class
I am trying to use a getter to retrieve some variables that the user will input into a GUI, however it gives me an "non-static method cannot be referenced from a static context" error. I have tried making my getters and setters static and that did…

Parker Bellante
- 21
- 1
0
votes
1 answer
How do change class attributes individually?
I read a bit about getters and setters, but haven't quite figured it out. One of my issues is the declaration in the init method: how can I change only one attribute if the method needs to arguments? Any other methods are of course welcome as…

Doe J
- 145
- 1
- 1
- 13
0
votes
1 answer
Getting data from a gui class to a different class
I have this project that is supposed to get information from a GUI and perform calculations, but it seems the data only returns null values and I'm stumped on how to tailor the setters and getters to work with a GUI. Here's my GUI class:
import…

Parker Bellante
- 21
- 1
0
votes
2 answers
hide the getter or add in the proto Object
is a way how i can create a getter, but hide it or add it in proto ?
example here, i use simple OBJ.
Look get sprite()
buttonsData[name] = {
name:name,
type:bType,
slot:slot,
get sprite() { return…

jon
- 1,494
- 3
- 16
- 29
0
votes
1 answer
Call an objects setter when its children are assigned to
Let there be an object userSingleton defined as such:
var userSingleton = new function() {
var _user = undefined;
Object.defineProperty(this, 'activeUser', {
get: function() {
console.log("Getter called, done something…

Ivan Rubinson
- 3,001
- 4
- 19
- 48
0
votes
2 answers
Python set variable in switch statement
i try to set variables dependend on the type with an switch case statement.
I have a class rule with looks as following:
class rule:
def __init__(self):
name = ""
src = ""
def setName(self, name):
self.__name =…

Cinux
- 11
- 1
- 1
0
votes
1 answer
TypeScript: get/set, referring to itself and underlying values
How does this particular getter/setter in TypeScript work:
export class MyClass {
get prop() {
return this.prop;
}
set prop(val: string) {
this.prop = val;
}
}
The getter and setter both refer to this.prop, but they both also…

keldar
- 6,152
- 10
- 52
- 82