setters

Constant instance variables?

I use 'property' to ensure that changes to an objects instance variables are wrapped by methods where I need to. What about when an instance has an variable that logically should not be changed? Eg, if I'm making a class for a Process, each Process instance should have a pid attribute that will frequently be accessed but should not be ...

Why use getters and setters?

What's the advantage of using getters and setters - that only get and set - instead of simply using public fields for those variables? If getters and setters are ever doing more than just the simple get/set, I can figure this one out very quickly, but I'm not 100% clear on how: public String foo; is any worse than: private String fo...

AS3 - multiple level loaded swfs , unloading and assigning xml

I have a Main Document class that instantiates 2 classes that control loading of two navigation grid swfs. These are populated by xml from navigation buttons on the main stage. A 3x3 navigation grid repopulates it's images and links when the buttons on the main stage are clicked Then loads the chosen video when a node on the grid is clic...

accessing struct variable inside getter setter in a c++ class

Okay, I have something like this in C++: class MyClass{ private: int someVariable; int someOtherVariable; struct structName{ int someStructVariable; int someOtherStructVariable; };//end of struct public: //getters & setters for the defined variables. int getSomeStructVariable() { // this does not work I get ...

Setting string in setter method

Is there something I need to do differently in setting a string in a setter method? This is my class: class SavingsAccount { public: void setData(); void printAccountData(); double accountClosure() {return (accountClosurePenaltyPercent * accountBalance);} private: int accountType; string ownerName; long ssn; ...

Eclipse setting for generating getters and setters insertion point last member

It really annoys me already now... I can not find the setting to have by default insertion point at last member. Why? Generating getters and setters would then be: ALT+SHIFT+S -> space, space, space... -> ENTER :) And not like now: ALT+SHIFT+S -> space, space, space... -> tab, tab, tab, tab, tab, -> up, up, up... -> ENTER ...

Ruby setter idiom

I'm working on a Chart class and it has a margin parameter, that holds :top, :bottom, :right and :left values. My first option was to make margin a setter and set values like this: # Sets :left and :right margins and doesn't alter :top and :bottom chart.margins = {:left => 10, :right => 15} It's nice, because it is clearly a setter, ...

How do I call a property setter from __init__

I have the following chunk of python code: import hashlib class User: def _set_password(self, value): self._password = hashlib.sha1(value).hexdigest() def _get_password(self): return self._password password = property( fset = _set_password, fget = _get_password) def __init__(self, user...

Getting and Setting values from Core Data elements in Objective-C?

I've got a simple application with two entities: Person: Attributes: name Relationships: nativeLanguage: (<<-> Language.natives) nonNativeLanguage: (<<-> Language.nonNatives) Language: Attributes: name Relationships: natives: (<->> Person.nativeLanguage) nonNatives: (<->> Person.nonNativeLanguage) On the ed...

benefits of getter/setter VS public vars?

Is there a benifit to using: private var _someProp:String; public function set someProp(value:String):void { _someProp = value; } public function get someProp():String { return _someProp; } As opposed to just using: public var someProp:String; I realise using getter/setter can be useful when you need to further processing ...

DataGridCell.IsEditMode?

How Can I know if the DataGridCell is currently in edit mode (not IsSelected), I mean, for example a DataGridTextColumn cell is clicked it becomes a TextBox and not a TextBlock, that's what I call IsEditMode. I wanna set a trigger-setter for this mode. EDIT: I tried to set a general style for DataGridCell.IsEditing but it doesn't seem t...

Is mixing constructor-based and setter-based injections a bad thing?

I have a class for products import from CSV file operation which requires about 7 parameters. This is an info which is definitely needed for importer. All of this parameters have the same life time. In the end we must have an Immutable Object. I was too scared to list all of them in constructor because of its affect to readability and ...

Set Accessor on class does not appear to work with TextInfo and TitleCase

Whilst playing around with an nhibernate mapping, I noticed that a property setter I had was being overloaded (or ignored). This is expected default behaviour with an nhibernate mapping. So I changed it to use the field.camelCase - so NHibernate would set the private field of the entity class and not the propety getter/setter so I could...

tutorial on getters and setters?

im from the php world. are there good tutorials explaining what getters and setters are and could give you some examples? ...

Why stick to get-set and not car.speed() and car.speed(55) respectively?

Apart from unambiguous clarity, why should we stick to: car.getSpeed() and car.setSpeed(55) when this could be used as well : car.speed() and car.speed(55) I know that get() and set() are useful to keep any changes to the data member manageable by keeping everything in one place. Also, obviously, I understand that car.speed() and car.s...

Does "LValue" not mean what I think it means?

In the following code: _imageView.hasHorizontalScroller = YES; _imageView.hasVerticalScroller = YES; _imageView.autohidesScrollers = YES; NSLog(@"scrollbar? H %p V %p hide %p", &(_imageView.hasHorizontalScroller), &(_imageView.hasVerticalScroller), &(_imageView.autohidesScrollers)); I'm getting the error: Contro...

Python: multiple properties, one setter/getter

Consider the following class definitions class of2010(object): def __init__(self): self._a = 1 self._b = 2 self._c = 3 def set_a(self,value): print('setting a...') self._a = value def set_b(self,value): print('setting b...') self._b = value def set_c(self,value): ...

Setter Getter oddness @property

I am having a really odd problem trying to set a simple float value to 1. My property: { float direction; } @property(nonatomic)float direction; Which is synthesized: @synthesize direction; I then used the following code: - (void)setDirection:(float)_direction { NSLog(@"Setter called with value of %f",_direction); self->d...

Overriding setter on domain class in grails 1.1.2

I have following two domain classes in Grails 1.1.2: class A implements Serializable { MyEnumType myField Date fieldChanged void setMyField(MyEnumType val) { if (myField != null && myField != val) { myField = val fieldChanged = new Date() } } } class B extends A { List children void setMyField(MyEnumType val) { if (m...

supplying dependency through base class

I have a list of Parts and some of them need a pointer to an Engine, lets call them EngineParts. What I want is to find these EngineParts using RTTI and then give them the Engine. The problem is how to design the EnginePart. I have two options here, described below, and I don't know which one to choose. Option 1 is faster because it doe...