Questions tagged [getter]

A getter is a public accessor method, used in object-oriented programming, which returns the value associated with a private member of a class.

A getter is public method, used in object-oriented programming, which returns the value associated with a private member of a class. A getter often refers to the get portion of a property. The getter method may perform other tasks such as validation, but is usually considered non-mutating.

1882 questions
16
votes
1 answer

How and when should I load the model from database for JSF dataTable

I've a data table as below: I'd like to populate it with a collection from the database obtained from a service method so that it is immediately presented when the page is opened during an initial…
Evgeni Dimitrov
  • 21,976
  • 33
  • 120
  • 145
16
votes
5 answers

C# getters, setters declaration

Possible Duplicates: Why use getters and setters? C# 3.0 Auto-Properties - useful or not? Is there a difference between defining properties the following way - // private, with getter & setter private string fName; public string Name { get {…
kosh
  • 551
  • 1
  • 9
  • 22
16
votes
4 answers

Redundant condition check before assignment suggestion for C# in Resharper 5

Is the condition check really redundant in the following sample?: public class MyClass { public bool MyProperty { get; set; } public void DoSomething(bool newValue) { // R# says: redundant condition check before assignment …
Kaleb Pederson
  • 45,767
  • 19
  • 102
  • 147
16
votes
2 answers

How to get FormArrayName when the FormArray is nested in another FormArray?

Refering to : https://angular.io/docs/ts/latest/api/forms/index/FormArrayName-directive.html, it is easy to get a FormArrayName :
M'sieur Toph'
  • 2,534
  • 1
  • 21
  • 34
16
votes
3 answers

Make a property that is read-only to the outside world, but my methods can still set

In JavaScript (ES5+), I'm trying to achieve the following scenario: An object (of which there will be many separate instances) each with a read-only property .size that can be read from the outside via direct property read, but cannot be set from…
jfriend00
  • 683,504
  • 96
  • 985
  • 979
16
votes
3 answers

Why are my Mongoose 3.8.7 schema getters and setters being ignored?

While working with Node.js, Mongoose and MongoDB, I have found that my Mongoose schema getters and setters do not fire when I perform a findOne query. I have found an old thread that suggests there was an issue with getters and setters in version…
Synzvato Chavea
  • 310
  • 1
  • 2
  • 7
16
votes
3 answers

JS getters and setters inside a class?

I'd like to create a class in JS that uses native getters and setters. I know I can create getters/setters for objects, like so: var obj = { get value(){ return this._value; }, set value(val){ this._value = val; …
Kuba Orlik
  • 3,360
  • 6
  • 34
  • 49
16
votes
2 answers

speed of getter function vs direct access

I have recently begun using more getter functions as opposed to direct access to make my code more flexible. I am curious what the cost of this is in terms of speed. Suppose that earth is an object and we have the following parent object: var…
gloo
  • 2,490
  • 3
  • 22
  • 38
15
votes
2 answers

DDD and the use of Getters and Setters

I've read a few articles/posts regarding the use of Getters and Setters, and how they help to defeat the purpose of encapsulation in domain model objects. I understand the logic behind not using setters - you are allowing client code to manipulate…
Chris
  • 7,996
  • 11
  • 66
  • 98
15
votes
5 answers

C# add validation on a setter method

I have a a couple of variables that i define in C# by: public String firstName { get; set; } public String lastName { get; set; } public String organization { get; set; } What i want is to add validation to these methods when you try to set a…
Marthin
  • 6,413
  • 15
  • 58
  • 95
15
votes
5 answers

Why do people write private-field getters returning a non-const reference?

We can all agree on public variables being bad for encapsulation and all that. However, I noticed a lot of code that does this type of stuff: class foo { private: int integer_; string someString_; // other variables public: int&…
Everyone
  • 1,751
  • 13
  • 36
15
votes
1 answer

Get all static getters in a class

Let's say I have this class (which I using like an enum): class Color { static get Red() { return 0; } static get Black() { return 1; } } Is there anything similar to Object.keys to get ['Red', 'Black']? I'm using…
Almis
  • 3,684
  • 2
  • 28
  • 58
15
votes
3 answers

Getters and setters in pure C?

Can I use getters and setters in pure C instead of using extern variables?
elusive
  • 193
  • 1
  • 1
  • 10
15
votes
3 answers

Defining a getter that takes arguments in Dart

I would like to define a getter that can optionally take arguments. I managed to achieve that, however it only works if I put the obligatory () after the call. Here's the code: get children => ([role=null]) { if(role == null || role == 'any') {…
orion3
  • 9,797
  • 14
  • 67
  • 93
14
votes
3 answers

PHP: empty doesn't work with a getter method

I have a "getter" method like function getStuff($stuff){ return 'something'; } if I check it with empty($this->stuff), I always get FALSE, but I know $this->stuff returns data, because it works with echo. and if I check it with…
Alex
  • 66,732
  • 177
  • 439
  • 641