setters

Javascript getters/setters in IE?

For whatever reason, Javascript getters/setters for custom objects seem to work with any browser but IE. Does IE have any other non-standard mechanism for this? (As with many other features) If not, are there any workarounds to achieve the same functionality? ...

C# How to make public getters and setters and private methods for a collection?

Hello All, I'd like to have a class "A" with a (for example) SortedList collection "SrtdLst" property, and inside this class "A" allow the addition or subtraction of "SrtdLst" items. But in a instance of the class "A", only allow to get or set the content of the items, not to add new items or subtract the existing ones. In code: class ...

Convert Pascal-cased setter to an underscore-separated variable name

This is not as simple as it seems. Most of you are likely thinking of the regex /([A-Z])/_$1/ like I have found all over the Internet, but my particular situation is slightly more complicated. My source string contains more content that I don't want to have converted before a portion that I do. Consider a regular setter: public funct...

Make Object Immutable at Runtime [C#]

Is there any way (utilizing Reflection I hope) that I can make an instantiated object immutable along with all of its public properties? I have a class from someone else's codebase (no source available) that I need to utilize and I basically want an exception to be thrown if any piece of code anywhere tries to call a public setter within...

Java Interface Usage Guidelines -- Are getters and setters in an interface bad?

What do people think of the best guidelines to use in an interface? What should and shouldn't go into an interface? I've heard people say that, as a general rule, an interface must only define behavior and not state. Does this mean that an interface shouldn't contain getters and setters? My opinion: Maybe not so for setters, but some...

A question about setter in objective-c

This is an example from The Objective-C 2.0 Programming Language. I was just wondering, in the setter at the bottom, can I use value = [newValue retain] instead of value = [newValue copy] ? @interface MyClass : NSObject { NSString *value; } @property(copy, readwrite) NSString *value; @end // assume using garbage collecti...

Actionscript 3.0 Setter - Getter

I want to pass Value from Constructor in my Main Class to another Class. Main Class: public function Main() { Snap.locationX = 350; } Another Class: public function get locationX():Number{ return _value; } public function set locationX(x:Number):void{ _value = x; } It returns 1061: Call to a poss...

How do I use PHP's __get() and __set() for defined fields in my class?

I've had a good read of the PHP specs on overloading, and most of the examples appear to be intended to simply allow defining of custom fields (similar to stdClass). But what about the private fields defined in my class? How should these be retrieved/assigned? I could do a switch on possible values and act on certain values: class A { ...

WPF - How to make Style.Triggers trigger a different named style to be applied

Hi guys Lets say I have the below: <Style TargetType="{x:Type TextBox}"> <Setter Property="BorderThickness" Value="1" /> <Setter Property="BorderBrush" Value="Gray" /> <Style.Triggers> <Trigger Property="IsFocused" Value="true"> <Setter Property="BorderBrush" Value="Green" /> <Setter Proper...

Can I use mvc without getters and setters?

If I don't want to expose the state of my object, but I still need to display it (in HTML, XML or JSON let's say), how would I go about doing that in an MVC environment. Does it make sense to have an export method which exports a dumbed down immutable object (a "data class" if you will). What about adding in a render method which talks...

setters/getters in one method

Just an idea: example (in PHP): to set name: $object->name('name'); to get name: $object->name(); If no argument: the method is used as getter, else as setter. For simple getters/setter. Stupid, whatever, maybe? edit: to follow up on the answers: I don't really like get and set because I prefer to have the interface as explicit as pos...

Setters/Getters, Visibility [ OOP ] in PHP

I'm in the process of reformatting my class ( seen below ) - I think I made the mistake of setting everything with the same visibility in my class, whereas properties should really be private and getters/setters should be public in most cases. To grab a property I just do $path->propertyname but I've noticed its more practical to have s...

does the 'getters and setters are evil' fail for the view layer?

Many people know this article: more on getters and setters. I think it does a convincing job of portraying the evil side of getters/setters. I've also tested it by trying to convert an existing project (unfinished) to code without getters/setters. It worked. Code readability improved greatly, less code and I've even managed to get rid of...

How can I access a property with a protected setter in my asp.net-mvc controller from fluent-nhibernate?

Using S#arp Architecture 1.0RC... I have a controller that never seems to update one of my properties. My class is a User abstract class with a Manager property. Manager is subclasses from User, as is Employee. I declared the property setter for Manager as protected and provided a method to AddManager. That way, I could also control t...

Proper way to modify an NSMutableDictionary instance variable?

Hello! I have an Objective-C NSMutableDictionary declared inside a class's @interface section, with getter/setter methods, like so: @interface myClass : NSObject { NSMutableDictionary *dict; } - (void) setDict: (NSMutableDictionary *) newDict; - (NSMutableDictionary *) dict; Inside some of my @implementation methods I want to mo...

How to set ContextMenu of a bound item?

I am trying to achieve the following: <Style TargetType="ListBoxItem"> <Setter Property="ContextMenu"> <Setter.Value> <ContextMenu> <MenuItem Name="mnuEdit" Header="_Edit" Click="MenuItem_Click" /> </ContextMenu> </Setter.Value> </Setter> <Style> But it throws the followi...

What is the point of setters and getters in java?

Please forgive the length, but here are two programs, both the exact same, but one with and one without setters, getters, and constructors. I've taken a basic C++ class before and don't remember any of these from it, and at the moment I'm not seeing the point of them, if anyone could explain them in lamen's terms I'd much appreciate it....

Generating Indexed Property Getters/Setters in Eclipse

By default, eclipse generates getters/setters according to JavaBeans regular properties style: * public void setName(String name) * public String getName() As of J2SE 5.0 JavaBeans specification allows IndexedPropertyChangeEvents which have a different getter/setter naming scheme for arrays: * public void setName(int index, String n...

A line of java code and what it does?

So I have purchased the book "Java for Dummies" 4th Edition, and I must say it is probably the best 30 dollars I have ever spent on a book. I'm not new to coding, am actually fairly decent at at it if I say so myself. However, I've come across a line of code that has me a touch confused: public void setName(String n) { if(!n.equa...

Why does a readonly property still allow writing with KVC

I'm working through the "Key Value Coding" chapter in "Programming for Mac OS X". I've built an interface with a slider and a label, both bound to fido, an int. If I set the property for fido to readonly, moving the slider still causes the label to change it's value. I had assumed that I'd get some sort of error for this. If the property...