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
7
votes
1 answer

Why use @property decorator when I can use a normal method getter?

class Employee: def __init__(self, name): self.name = name def getName(self): return self.name @property def getNameAgain(self): return self.name person = Employee("John") print(person.getName()) #John…
Shee
  • 123
  • 1
  • 6
7
votes
3 answers

Mocking a Properties file with Mockito in Spring

I am trying to write a unit test for the following method in my controller. @Autowired private ApplicationContext context; private String getProperty() { try { Properties props = context.getBean("myProperties",…
blong824
  • 3,920
  • 14
  • 54
  • 75
7
votes
3 answers

evaluate a string as a property in C#

I have a property stored in a string... say Object Foo has a property Bar, so to get the value of the Bar property I would call.. Console.Write(foo.Bar); Now say that I have "Bar" stored in a string variable... string property = "Bar" Foo foo =…
jondavidjohn
  • 61,812
  • 21
  • 118
  • 158
7
votes
4 answers

Should I use a property or a method for a calculated value?

Possible Duplicate: Properties vs Methods I have some vector geometry classes, and there is lots of functionality I don't know whether to implement as (readonly) properties or methods. Examples include: Vector.Length or …
Eric
  • 95,302
  • 53
  • 242
  • 374
7
votes
1 answer

F# nameof operator not a first-class function

I'm using F# 4.7 with preview in my project file. I have a type like this: type Record = { Name : string Description : string FieldNotInterestedIn: int } I'd like to get the names of certain fields in a type-safe…
Brett Rowberry
  • 1,030
  • 8
  • 21
7
votes
4 answers

Is there an ES6 function that will return an object containing property changes?

ES6 has a lot of functions including assign and others. But is there a method to get a list of properties that are different from one object to the next? For example, if I have a component with two states. The default state has 100 properties that…
1.21 gigawatts
  • 16,517
  • 32
  • 123
  • 231
7
votes
2 answers

python colorama print all colors

I am new to learning Python, and I came across colorama. As a test project, I wanted to print out all the available colors in colorama. from colorama import Fore from colorama import init as colorama_init colorama_init(autoreset=True) colors = [x…
Gerrit Geeraerts
  • 924
  • 1
  • 7
  • 14
7
votes
4 answers

What is the equivalent for write_attribute for associations in Rails?

I'd like to override the setter for an association, but write_attribute() isn't working - probably because that method only works for database columns. I have tried super(), but that doesn't work either (didn't think it would... but it was worth a…
Fire Emblem
  • 5,961
  • 3
  • 24
  • 37
7
votes
3 answers

IBOutlets, instance variables and properties: Best Practices

I've done all sorts of research today on best practices with regards to declaring IBOutlets and instance variables, managing them, using the correct accessors and properly releasing them. I'm pretty much there, but I've got some niche questions that…
WheresWardy
  • 375
  • 3
  • 22
7
votes
4 answers

Accessing dict "values" like an attribute?

What I am looking for is having something like this: self.info['key'].attr2 But I'm not sure what would be the most elegant way to achieve it. So far I have defined a dictionary like below but don't have attributes from it. self.info =…
Alejandro
  • 879
  • 11
  • 27
7
votes
2 answers

Is there a way to directly invoke a property setter through a delegate?

I am working with Windows Forms, and many times have bumped into (as I understood it) the necessity to write wrapping functions around properties of the UI components, so that they (the properties) could be set from another thread by invoking their…
Srv19
  • 3,458
  • 6
  • 44
  • 75
7
votes
1 answer

Use of PropertySourcesPlaceholderConfigurer?

I am starting to learn Spring annotations. I'm currently using the @PropertySource annotation in my Configuration Class to resolve properties values and everything works fine, but then I read about PropertySourcesPlaceholderConfigurer. When or why I…
Djordje Vuckovic
  • 383
  • 1
  • 5
  • 11
7
votes
2 answers

Does a private @property create an @private instance variable?

I've read that @synthesize will automatically create corresponding instance variables for @property and that ivars are @protected by default. But, what if I use a class extension (like below) to indicate that the @property methods are to be…
ma11hew28
  • 121,420
  • 116
  • 450
  • 651
7
votes
0 answers

Spring 4 @Conditional: Environment properties not available unless @PropertySource is used

Problem: When using @Conditional bean definitions within @Configuration classes, properties from external sources, e. g. files, are not available in the Environment when Condition#matches is evaluated - unless @PropertySource is used. Using…
aebblcraebbl
  • 151
  • 7
7
votes
2 answers

Why is property.fget a read-only attribute?

I'm currently patching a property of a class from a library to make it more versatile. I'm doing this using the following code which works fine: _orig_is_xhr = BaseRequest.is_xhr.fget _orig_is_xhr_doc = BaseRequest.is_xhr.__doc__ BaseRequest.is_xhr…
ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
1 2 3
99
100