Questions tagged [setter]
Setter is public mutator method, used in object-oriented programming, which gives new value to a private member of a class.
1,766
questions
0
votes
0
answers
4
views
Conventions for property method, <>.setter and setter method names
Is there a convention for naming:
1.- the property method: in the example below, " def get_number (...)". Is that a good name? Should it be another one?
2.- the setter: in the example below &...
-4
votes
1
answer
50
views
C# decimal setter is not working anymore since moving to Visual Studio 2022 .net 7. The value is always set to 0 [closed]
I have a screen shot of the debugger where I can set an local decimal to the value and I see it in the debugger as getting set but the setter's private decimal variable is not setting to the value. Is ...
0
votes
2
answers
49
views
Maui Custom Entry Behavior is blocking blocking Set call on ViewModel
I have created a custom behavior for the Entry control that allows a collection of Entry controls to provide a single-digit code input field that moves the cursor to the next field ( to the right ) ...
0
votes
0
answers
31
views
Name Mangling In Python Regarding Setter methods
I had an issue with my setter methods not working when the if conditions were met, and I was not sure why (I ended up fixing it, but my question is WHY this fixed it). Here is my code:
class Employee:
...
0
votes
0
answers
34
views
python getter and setter properties
I am new to properties in Python and a bit confused on how below code is working
class FavoriteShape:
def __init__(self, color, shape):
self.color = color
self.shape = shape
@...
0
votes
1
answer
31
views
how to override a setter of an abstract class to make the value final
Given an abstract class "Foo" that has a getter and setter for a "value"
abstract class Foo<T> {
T get value;
set value(T newValue);
}
I'm trying to override getter and ...
-1
votes
3
answers
41
views
What's this setter error ("X" is not defined...) when using a property?
@property
def GetURLLabel(self):
return self._URLLabel
# Setter methods
@URLLabel.setter
def SetURLLabel(self, value):
if isinstance(value, str):
self._URLLabel = value
else:
...
0
votes
1
answer
69
views
DWScript: Property getter/setter for object
The tdwsUnit declares a property of type TObject, as well as a getter and a setter. An instantiated object shall be stored in an "object store" on the Delphi side. The goal is to transport ...
0
votes
0
answers
28
views
Why is this setter method in the Node class not working?
I am trying to build kinda dynamic array. When trying to assign the array's last space the ignite property's set method creates a node and assigns this node's next reference. That's what I am thinking....
0
votes
1
answer
87
views
kotlin serializable with constructor properties and custom setters
I wanted to make a class of mine Serializable (kotlinx.serialization) but realized this is not possible due to these constraints in Kotlin:
Serializable requires every parameter in the primary ...
0
votes
3
answers
55
views
What is the python alternative for C#'s custom property setters?
I'm coming from C# world into python. In C#, I can use get and set to make updates to other object properties upon setting a value to a property, something like this:
private int _age;
private string ...
0
votes
0
answers
59
views
How would I invoke setter when modifying properties in C#?
Suppose I have a class Character, which have stats of the class Stat. Specifically each character has a Character.Speed Stat that can be modified. This speed stat is heavily related to a float ...
0
votes
1
answer
32
views
Accessor magic method not working in PHP 8 [duplicate]
I recently upgraded Ubuntu from 20.04 LTS to 22.04 LTS. I noticed that PHP was upgraded to the following version:
PHP 8.1.2-1ubuntu2.13 (cli) (built: Jun 28 2023 14:01:49) (NTS)
Copyright (c) The PHP ...
0
votes
0
answers
26
views
String getMode() and setMode(String mode), or String mode() and mode(String mode)? Is the way of naming getters/setters changing, and when? [duplicate]
Up until today, I created my objects with getters/setters of the form:
private String mode;
public String getMode() { return this.mode; }
public void setMode(String mode) { this.mode = mode; }
But ...
2
votes
1
answer
90
views
setter methods and Restricted Python
I have a class "MyClass" with a class attribute and its methods.
class MyClass:
def __init__(self):
self._my_attr = None
@property
def my_attr(self):
return self....
0
votes
1
answer
34
views
Setter only does assignment, yet declares that it throws a ParseException; in Hibernate
Discovered a Date setter that only does the typical assignment, yet has a throws ParseException for what seems like no good reason. No Date construction is happening in the body of the setter. Just ...
0
votes
0
answers
16
views
Is it pythonic to call the setter from the property
I am often using the @property decorator on classes where the attribute in question requires some calculation before being returned. My question is how to divide the responsibility between the @...
0
votes
1
answer
73
views
Python: Using setter inside class init for a private attribute
I'm trying to create a private attribute in the class initialization, using parameters described in the setter.
I can do it by typing the same code twice, but I'd like to keep the checks inside the ...
0
votes
1
answer
74
views
Get a warning when using setter as a property
I'm working on an angular project where we often use this "pattern"
public _value;
@Input() public set value(value) {
this._value = value;
}
It is widespread in the project and it has ...
1
vote
1
answer
63
views
For an instance field which is an array value, how does one handle additional tasks whenever the array mutates by e.g. pushing into or splicing it?
The set accessor does not take place whenever one does mutate the Crumbs class property value by e.g pushing into it.
I'm trying to create a class property via set syntax which I expect to handle an ...
0
votes
1
answer
35
views
Unable to access class property using __dict__ in Python 3.8
I've two classes test and a child class test2, and I'm using a @property and a setter decorator to create the brand property. An example is shown below:
class test:
def __init__(self):
...
1
vote
3
answers
126
views
What is the efficient way of null and empty check in setter
I need to add null and empty checks to each of the 27 fields in my DTO class, and I'm searching for the most effective method to accomplish it. Can anyone suggest any ideas?
private String settingType;...
1
vote
1
answer
417
views
Style target behaviors MAUI
I want to create styled editor for my current page. I use it few times so i decide to wrote style for this element and wondering how to use Behaviors inside style. If i do this like regular way, ...
-1
votes
1
answer
37
views
How to activate a setter method without input in the main program code?
I'm working on a program that needs to check if a value is an integer before applying it to an attribute of a class. This must be done in a setter ("set") method.
internal class Dummy {
...
-2
votes
1
answer
52
views
Access to elements of Matrix
Help me to implement access and change of elements of matrix using property without numpy. I'm a beginner)
What I tried to do
class Matrix:
def __init__(self, matrix=[[0] * 3 for i in range(3)], ...
0
votes
0
answers
29
views
python builder design patter unresolved reference error [duplicate]
class AlgDispenser:
# super class to output an algorithm out of a selection of algorithms
def __init__(self, *algorithms: Algorithm):
super().__init__()
self._algs: list[...
-1
votes
2
answers
75
views
Why doesn't return getter like in Java (C#)
I want to move from Java to C# and I want to try getter and setter like in Java
internal class Person
{
internal string name;
internal void setName (string name)
...
0
votes
0
answers
23
views
Replace labels in networkx graph according to translation given by list of tuples
I have a MultiDiGraph, G with the following edges:
[('SP', 'LU', 0), ('SP', 'KI', 0), ('LU', 'PC', 0), ('LU', 'LR', 0), ('LU', 'LR', 1), ('PC', 'LI', 0), ('PC', 'HT', 0), ('PC', 'HT', 1), ('LI', 'TE', ...
2
votes
2
answers
165
views
Is there a way to call a function when any setter is used in Kotlin
import java.time.LocalDateTime
class Company(var address: String, var name: String, var owner: String){
var modified=LocalDateTime.now()
}
int main(){
var company=Company("Adrd", "...
-2
votes
1
answer
40
views
How to access text value outside of initialization of Radiobutton
fruit_frame = LabelFrame(root, text = "Fruit", padx = 15, pady = 15) fruit_frame.grid(row = 0, column = 0)
veg_frame = LabelFrame(root, text = "Vegetables", padx = 15, pady = 15) ...
0
votes
0
answers
20
views
Pythonic way of initialising class with infrequently variables optional arguments
Background
I'm working on an Element class that is of the following charactirtics:
Stores bespoke_data variable that varies across instances
Stores components variable that seldom varies across ...
0
votes
1
answer
47
views
How to apply input to the set method, and in another case, input outside main?
me again. This time I need to get user input, plug them into various set methods, and output a value. It sounds pretty easy although the assignment instructions make it seem way harder.
In depth:
I ...
0
votes
0
answers
30
views
Why isn’t possible to define the setter via lambda with ":=" operator? [duplicate]
Formally, the lambda body can contain literals, identifiers, and operators. Why doesn’t Python understand the lambda body for such property implementation?
class Test:
test = property(
...
0
votes
2
answers
200
views
c++ setter/getter does not work as expected
for some reason my prof insists I have to use setter/getter everywhere.
Well... in this linked list I don't understand why this one doesn't work
#include <iostream>
#include <string>
using ...
0
votes
2
answers
269
views
Dynamically generate mypy-compliant property setters
I am trying to declare a base class with certain attributes for which the (very expensive) calculation differs depending on the subclass, but that accepts injecting the value if previously calculated
...
0
votes
1
answer
30
views
How to set userkey_id with @setter and token in django?
I have created a client frontend and have tested the url using cUrl and it works, sending the auth token via axios headers allows me in to call the api. The problem is that I get a NOT NULL constraint ...
0
votes
1
answer
86
views
getter setter can't change textBox.Text control value in Winform c#
Why textBox3.text do not shows value _TextBoxRequestMsg. MessageBox opens and shows _TextBoxRequestMsg value OK, console prints too.
public partial class F_Main : Form
{
private string ...
0
votes
0
answers
100
views
Pandas dataframe as a property of a class: setter not called when columns changed
I want to have a pandas DataFrame as a property of my class. I want users to be able to interact with the DataFrame in a normal way, but when it changes I want to run a few checks and balances over ...
0
votes
0
answers
56
views
Adding a Command Within C# Get/Set Shorthand
Here is my understanding of C# get/set shorthand. The long way of defining a property in C#:
private int myVar;
public int MyProperty
{
get { return myVar; }
set { myVar = value; }
}
We can ...
0
votes
1
answer
59
views
How do you force Swift setter to trigger on initial value?
In the DecimalAmount function I can't get it to display the initial value of the amount. It shows 0.00 as the initial display even though the actual value is 22.22. Anyone know how to get around this ...
0
votes
2
answers
97
views
Setter not running when assigning to the same reference
My setter code is not running here, I think by design because I am setting the same reference.
Is there syntax I can use to ensure the setter runs?
var settings = new Settings();
var a = settings....
4
votes
1
answer
185
views
How do getters and setters work in Python?
The following is a snippet of code from CS50P.
I don't understand how it works and cannot seem to find an adequate explanation.
Firstly, as soon as the Student constructor is called with user inputted ...
0
votes
1
answer
233
views
Why Are Conditional XAML Setters In Default WinUI Styles Invalid In UWP?
I copied the default WinUI button style from the WinUI GitHub repo into an empty project. Below is my App.xaml. When I try to run the project, I get this error: The XAML Binary Format (XBF) generator ...
-1
votes
1
answer
58
views
Is it possible to define setters for a Class in Swift
I have created a version of CurrentValueSubject which can't be completed similar to @Published. However, I want to remove the need for .send(value) and define a setter for this class which will ...
0
votes
0
answers
255
views
How to properly silence mypy when you have a setter with a decorator?
Consider the following code, that is also basically the example given at https://pyro5.readthedocs.io/en/latest/servercode.html :
import Pyro5.server
class PyroService(object):
value = 42 ...
0
votes
1
answer
379
views
problem defining class property in python
I'm new to python programming, I'm trying to encapsulate all property checking of a size in the class object below but one of them is not working (checking to see if withdraw is bigger than amount of ...
0
votes
1
answer
354
views
Wanting to change a setter of a single input field, how to advance to check if those were changed before and how not to lose the previous addages?
This is a follow up question to Setter for HTMLInputElement.value.
If I changed the setter and getter of a single input-element (not on all input elements in general), and later on I want to make ...
1
vote
1
answer
240
views
a pointer to a bound function may only be used to call the function using a setter
I am using an SDL Template and I am trying to implement gravity into my code so I am trying to set a Y as the strength of my gravity in update but when I try to use a pointer to setY I always get an ...
1
vote
1
answer
45
views
My code works fine from constructor but always returns 1 using a setter
My Java teacher asked for an exponentiation exercise. He wants us to use bucle (for or while) for this, not math functions. Well, I have wrote the code but I realised that if I use the constructor, it ...
0
votes
1
answer
1k
views
Jackson: How to only ignore a Json property when creating a response?
I my Spring app I am getting a String from S3, I need convert this to JSON then to Person object. This is all working as expected.
import com.fasterxml.jackson.core.JsonProcessingException;
import com....