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
295
votes
16 answers

Passing properties by reference in C#

I'm trying to do do the following: GetString( inputString, ref Client.WorkPhone) private void GetString(string inValue, ref string outValue) { if (!string.IsNullOrEmpty(inValue)) { outValue = inValue; } } This is giving…
yogibear
  • 14,487
  • 9
  • 32
  • 31
290
votes
10 answers

Semantic Issue: Property's synthesized getter follows Cocoa naming convention for returning 'owned' objects

I'm currently using the iOS 5 SDK trying to develop my app. I'm trying to make an NSString a property, and then to synthesize it in the .m file (I have done this before with no issues). Now, I came across this: "Semantic Issue: Property's…
Noam
  • 3,100
  • 3
  • 16
  • 19
282
votes
6 answers

Can I update a component's props in React.js?

After starting to work with React.js, it seems like props are intended to be static (passed in from the parent component), while state changes based upon events. However, I noticed in the docs a reference to componentWillReceiveProps, which…
Matt Huggins
  • 81,398
  • 36
  • 149
  • 218
275
votes
7 answers

Why use 'virtual' for class properties in Entity Framework model definitions?

In the following blog: http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx The blog contains the following code sample: public class Dinner { public int DinnerID { get; set; } public string…
Gary Jones
  • 3,047
  • 4
  • 17
  • 14
265
votes
13 answers

Get name of property as a string

(See below solution I created using the answer I accepted) I'm trying to improve the maintainability of some code involving reflection. The app has a .NET Remoting interface exposing (among other things) a method called Execute for accessing parts…
Jim C
  • 4,517
  • 7
  • 29
  • 33
252
votes
12 answers

Error in Swift class: Property not initialized at super.init call

I have two classes, Shape and Square class Shape { var numberOfSides = 0 var name: String init(name:String) { self.name = name } func simpleDescription() -> String { return "A shape with \(numberOfSides) sides." …
JuJoDi
  • 14,627
  • 23
  • 80
  • 126
245
votes
7 answers

How to create abstract properties in python abstract classes?

In the following code, I create a base abstract class Base. I want all the classes that inherit from Base to provide the name property, so I made this property an @abstractmethod. Then I created a subclass of Base, called Base_1, which is meant to…
Boris Gorelik
  • 29,945
  • 39
  • 128
  • 170
227
votes
17 answers

How to use Java property files?

I have a list of key/value pairs of configuration values I want to store as Java property files, and later load and iterate through. Questions: Do I need to store the file in the same package as the class which will load them, or is there any…
Ali
  • 261,656
  • 265
  • 575
  • 769
221
votes
11 answers

Property getters and setters

With this simple class I am getting the compiler warning Attempting to modify/access x within its own setter/getter and when I use it like this: var p: point = Point() p.x = 12 I get an EXC_BAD_ACCESS. How can I do this without explicit backing…
Atomix
  • 13,427
  • 9
  • 38
  • 46
214
votes
9 answers

How to make a class property?

In python I can add a method to a class with the @classmethod decorator. Is there a similar decorator to add a property to a class? I can better show what I'm talking about. class Example(object): the_I = 10 def __init__( self ): …
deft_code
  • 57,255
  • 29
  • 141
  • 224
208
votes
13 answers

Getting the object's property name

I was wondering if there was any way in JavaScript to loop through an object like so. for(var i in myObject) { // ... } But get the name of each property like this. for(var i in myObject) { separateObj[myObject[i].name] = myObject[i]; } I…
Olical
  • 39,703
  • 12
  • 54
  • 77
199
votes
11 answers

What is the difference between attribute and property?

These seem to mean the same thing. But what term is more appropriate in what context?
caustic
  • 2,658
  • 3
  • 21
  • 13
194
votes
9 answers

Options, Settings, Properties, Configuration, Preferences — when and why?

There are several words with similar (in some sense) meaning: Options, Settings, Properties, Configuration, Preferences English is not my native language. Could you explain the difference in simple English please? I think the following template…
Andrew T
  • 5,549
  • 7
  • 43
  • 55
189
votes
5 answers

How do I use LINQ to obtain a unique list of properties from a list of objects?

I'm trying to use LINQ to return a list of ids given a list of objects where the id is a property. I'd like to be able to do this without looping through each object and pulling out the unique ids that I find. I have a list of objects of type…
mezoid
  • 28,090
  • 37
  • 107
  • 148
189
votes
8 answers

How to enumerate an object's properties in Python?

I C# we do it through reflection. In Javascript it is simple as: for(var propertyName in objectName) var currentPropertyValue = objectName[propertyName]; How to do it in Python?
Jader Dias
  • 88,211
  • 155
  • 421
  • 625