Questions tagged [properties]

A property, in some object-oriented programming languages, is a special sort of class member, intermediate between a field (or data member) and a method. Properties are read and written like fields, but property reads and writes are (usually) translated to get and set method calls.

Property, in some object-oriented programming languages, is a special sort of class member, intermediate between a field (or data member) and a method.

Properties are read and written like fields, but property reads and writes are (usually) translated to get and set method calls. The field-like syntax is said to be easier to read and write than lots of method calls, yet the interposition of method calls allows for data validation, active updating (as of GUI visuals), or read-only 'fields'. That is, properties are intermediate between member code (methods) and member data (instance variables) of the class, and properties provide a higher level of encapsulation than public fields.

See:

18121 questions
570
votes
8 answers

@synthesize vs @dynamic, what are the differences?

What are the differences between implementing a @property with @dynamic or @synthesize?
nico
  • 9,668
  • 8
  • 26
  • 28
477
votes
9 answers

Property initialization using "by lazy" vs. "lateinit"

In Kotlin, if you don't want to initialize a class property inside the constructor or in the top of the class body, you have basically these two options (from the language reference): Lazy Initialization lazy() is a function that takes a lambda…
regmoraes
  • 5,329
  • 3
  • 24
  • 33
441
votes
9 answers

How to create an object property from a variable value in JavaScript?

I want to add a new property to 'myObj', name it 'string1' and give it a value of 'string2', but when I do it it returns 'undefined: var myObj = new Object; var a = 'string1'; var b = 'string2'; myObj.a = b; alert(myObj.string1); //Returns…
ecu
  • 4,433
  • 2
  • 16
  • 4
429
votes
12 answers

Remove array element based on object property

I have an array of objects like so: var myArray = [ {field: 'id', operator: 'eq', value: id}, {field: 'cStatus', operator: 'eq', value: cStatus}, {field: 'money', operator: 'eq', value: money} ]; How do I remove a specific one based…
imperium2335
  • 23,402
  • 38
  • 111
  • 190
407
votes
19 answers

Property 'value' does not exist on type 'EventTarget'

I am using TypeScript Version 2 for an Angular 2 component code. I am getting error "Property 'value' does not exist on type 'EventTarget'" for below code, what could be the solution. Thanks! e.target.value.match(/\S+/g) || []).length import {…
user584018
  • 10,186
  • 15
  • 74
  • 160
406
votes
14 answers

Public Fields versus Automatic Properties

We're often told we should protect encapsulation by making getter and setter methods (properties in C#) for class fields, instead of exposing the fields to the outside world. But there are many times when a field is just there to hold a value and…
I. J. Kennedy
  • 24,725
  • 16
  • 62
  • 87
382
votes
26 answers

react-router - pass props to handler component

I have the following structure for my React.js application using React Router: var Dashboard = require('./Dashboard'); var Comments = require('./Comments'); var Index = React.createClass({ render: function () { return (
Kosmetika
  • 20,774
  • 37
  • 108
  • 172
381
votes
10 answers

Set object property using reflection

Is there a way in C# where I can use reflection to set an object property? Ex: MyObject obj = new MyObject(); obj.Name = "Value"; I want to set obj.Name with reflection. Something like: Reflection.SetProperty(obj, "Name") = "Value"; Is there a way…
Melursus
  • 10,328
  • 19
  • 69
  • 103
380
votes
8 answers

Objective-C ARC: strong vs retain and weak vs assign

There are two new memory management attributes for properties introduced by ARC, strong and weak. Apart from copy, which is obviously something completely different, are there any differences between strong vs retain and weak vs assign? From my…
Jakub Arnold
  • 85,596
  • 89
  • 230
  • 327
350
votes
2 answers

Java system properties and environment variables

What's the difference between system properties System.getProperties() and environment variables System.getenv() in a JVM?
Praveen Sripati
  • 32,799
  • 16
  • 80
  • 117
316
votes
19 answers

Are there any reasons to use private properties in C#?

I just realized that the C# property construct can also be used with a private access modifier: private string Password { get; set; } Although this is technically interesting, I can't imagine when I would use it since a private field involves even…
Edward Tanguay
  • 189,012
  • 314
  • 712
  • 1,047
309
votes
7 answers

What does the => operator mean in a property or method?

I came across some code that said public int MaxHealth => Memory[Address].IsValid ? Memory[Address].Read(Offs.Life.MaxHp) : 0; Now I am somewhat familiar with Lambda expressions. I just have not seen it used it…
Mike
  • 5,918
  • 9
  • 57
  • 94
305
votes
5 answers

Is there a “not in” operator in JavaScript for checking object properties?

Is there any sort of "not in" operator in JavaScript to check if a property does not exist in an object? I couldn’t find anything about this around Google or Stack Overflow. Here’s a small snippet of code I’m working on where I need this kind of…
Aaron
  • 10,386
  • 13
  • 37
  • 53
305
votes
25 answers

How to add property to a class dynamically?

The goal is to create a mock class which behaves like a db resultset. So for example, if a database query returns, using a dict expression, {'ab':100, 'cd':200}, then I would like to see: >>> dummy.ab 100 At first I thought maybe I could do it…
Anthony Kong
  • 37,791
  • 46
  • 172
  • 304
298
votes
17 answers

Shortcut to create properties in Visual Studio?

I have seen some people creating properties in C# really fast, but how did they do it? What shortcuts are available in Visual Studio (currently using Visual Studio 2010) to create properties? I am using C#. For example, public string myString…
user467058