setters

What are getter and setters? PHP5

What are getters and setters in PHP5? Can someone give me a good example with an explanation? ...

Replacement for C style struct in OOP

Hey all, I am a student with a mainly electronics background getting into programing. The more I get into it, the more I realize how bad I am at it. I am trying to get better at OO design. One thing I have been reading about is the use of Getters and Setters. http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html?page=1 ...

Javascript setters/getters

var author = { firstname: 'Martin', lastname: 'Hansen' } function settersGetters(propStr) { for (var i = 0; i < propStr.length; i++) { author['_'+ propStr[i]] = null; author.__defineGetter__(propStr[i], function() { return author['_'+ propStr[i]]; }); author.__defineSetter__(propStr[i], function(val) ...

What is array portability?

From this page: http://www.doctrine-project.org/documentation/manual/1_2/en/working-with-models#dealing-with-relations:creating-related-records You can see that it says $obj['property']; is the recommended way of referring to an object's property in Doctrine for array portability purposes. I never heard about this term before and goog...

Getter/setter on javascript array?

Is there a way to get a get/set behaviour on an array? I imagine something like this: var arr = ['one', 'two', 'three']; var _arr = new Array(); for (var i=0; i < arr.length; i++) { arr[i].__defineGetter__('value', function(index) { //Do something return _arr[index]; }); arr[i].__defineSetter__('value', function(index, val) ...

Using .NET XmlSerializer with get properties and setter functions

I'm trying to use XmlSerializer from C# to save out a class that has some values that are read by properties (the code being just a simple retrieval of field value) but set by setter functions (since there is a delegate called if the value changes). What I'm currently doing is this sort of thing. The intended use is to use the InT prop...

Approach to side-effect-free setters

I would like to get your opinion on as how far to go with side-effect-free setters. Consider following example Activity activity; activity.Start = "2010-01-01"; activity.Duration = "10 days"; // sets Finish property to "2010-01-10" Note that values for date and duration are shown only for indicative purposes. So using setter fo...

Ambiguous reference when getter/setter have different visibilities

The following code raises an ambiguous reference to value at compile time: import flash.display.Sprite; public class Main extends Sprite { private var _value : Number = 0.; public function get value() : Number { return _value; } private function set value(v : Number) : void { _value = v; } public function...

Java - Should private instance variables be accessed in constructors through getters and setters method ?

I know that private instance variables are accessed through their public getters and setters method. But when I generate constructors with the help of IDE, it initializes instance variables directly instead of initializing them through their setter methods. Q1. So should I change the IDE generated code for constructors to initialize th...

wpf, Style, Setters

Hello, I've got question about wpf xaml style definitions. When I try to set style in this way: <StackPanel Orientation="Vertical"> <StackPanel.Style> <Setter Property="BusinessModeler:GraphItemBehaviour.IsBroughtIntoViewWhenSelected" Value="True" /> </StackPanel.Styl...

What is a good practice to access class attributes in class methods?

I always wonder about the best way to access a class attribute from a class method in Java. Could you quickly convince me about which one of the 3 solutions below (or a totally different one :P) is a good practice? public class Test { String a; public String getA(){ return this.a; } public setA(String a){ ...

JAXB does not call setter when unmarshalling objects

Hi all, I am using JAXB 2.0 JDK 6 in order to unmarshall an XML instance into POJOs. In order to add some custom validation I have inserted a validation call into the setter of a property, yet despite it being private, it seems that the unmarshaller does not call the setter but directly modifies the private field. It is crucial to me...

Change field access to getter / setter method access

Hi everyone, is it possible to change external class field accesses in Java to getter / setter calls automatically, and also hide the exposed fields? I'm using Javabeans and I want change notifications when a field property changes (this is important). I've found cglib which can automatically insert the property change call to the Prope...

Setter for Canvas.Left and Canvas.Top readwrite in WPF but not in Silverlight 4, why ?

Hi, I have the following XAML, which works fine in WPF, but not in Silverlight 4 <ItemsPanelTemplate x:Key="ContentListBoxItemsPanelTemplate"> <Canvas/> </ItemsPanelTemplate> <DataTemplate x:Key="ContentListBoxItemTemplate"> <Border CornerRadius="15" Width="150" Margin="3" Height="300"> ...

Why can't I initialize a class through a setter?

If I have a custom class called Tires: #import <Foundation/Foundation.h> @interface Tires : NSObject { @private NSString *brand; int size; } @property (nonatomic,copy) NSString *brand; @property int size; - (id)init; - (void)dealloc; @end ============================================= #import "Tires.h" @implementation Tir...

iPhone Setting ViewController nested in NSMutableArray

Hello I'm trying to set attributes for a viewcontroller nested inside a NSMutableArray, for example I have 3 ViewController inside this array: FirstViewController *firstViewController = [FirstViewController alloc]; SecondViewController *secondViewController = [SecondViewController alloc]; ThirdViewController *thirdViewController = [Thir...

What Getters and Setters should and shouldn't do.

Possible Duplicate: Convention question: When do you use a Getter/Setter function rather than using a Property I've run into a lot of differing opinions on Getters and Setters lately, so I figured I should make it into it's own question. A previous question of mine received an immediate comment (later deleted) that stated set...

Symfony 1.4 setter type double precision

Hi volks, I want to save a number with 14 decimal places, but symfony only saves 6. How can I control this: $loc->setSinRadLon(0.73946213661883); In the schema the column looks like: sin_rad_lon: { type: double(), scale: 14, notnull: true } The DB stetting is: sin_rad_lon double(18,14) In the DB the column value is: 0.73946...

Custom setter methods in Core-Data

I need to write a custom setter method for a field (we'll call it foo) in my subclass of NSManagedObject. foo is defined in the data model and Xcode has autogenerated @property and @dynamic fields in the .h and .m files respectively. If I write my setter like this: - (void)setFoo: (NSObject *)inFoo { [super setFoo: inFoo]; [sel...

Public Data members vs Getters, Setters

Hi All, I am currently working in Qt and so C++. I am having classes that has private data members and public member functions. I have public getters and setters for the data members available in the class. Now my question is, if we have getters and setters for data members in our classes then what's the point in making those data mem...