setters

Overriding setters not being called in Objective-C

I'm debugging a sample tutorial snippet and am confused about the overriding of setters. I declare and override as shown here: // // PolygonShape.h // @interface PolygonShape : NSObject { int numberOfSides; } @property int numberOfSides; // // PolygonShape.m // @synthesize numberOfSides; // custom setter. - (void) setnumber...

Using Python's @property decorator on dicts

I'm trying to use Python's @property decorator on a dict in a class. The idea is that I want a certain value (call it 'message') to be cleared after it is accessed. But I also want another value (call it 'last_message') to contain the last set message, and keep it until another message is set. In my mind, this code would work: >>> class...

Putting Styles on controls inside a Grid style

I want' to define that every control of specific type inisde a grid gets a Style. This is easy just put the styles with TargetType inside the grid resources. But what then if I wan't to reuse this grid as a style? I can create a grid style and have a setter to resources but can only put one style there. <Style x:Key="GridStyle" TargetT...

Auto-properties: Checking/validating during the "set"

I think we can all agree that Automatic Properties in C# 3.0 are great. Something like this: private string name; public string Name { get { return name; } set { name = value; } } Gets reduced to this: public string Name { get; set; } Lovely! But what am I supposed to do if I want to, say, convert the Name string using the...

Why does wrapper classes for primitive data types don't have a setter ?

What is the reason why Wrapper classes (like Integer, Double, etc.) don't have a setter for their inner primitive value ? I am asking this because that kind of functionality would have simplified calculus, and have made the Java language a little more flexible . Let me give you some examples. 1) Let's take the following example: Int...

WPF Style Triggers from another control

Hi, I have an image that i want to make it when the user hover with mouse over it, another image next to it will be displayed. The code below, doesn't work: <Image Source="volumen.png"> <Image.Style> <Style> <Style.Triggers> <Trigger Pro...

Getters / Setters / Assigning one object to another

I have a class called Chair. I have a view controller that contains an object of type Chair. At some point, I am trying to assign my viewcontrollers instance to another instance of a Chair object as such: [viewcontroller setChair: thisChair]; My setter looks as such: - (void) setChair:(Chair *)thisEntryChair; { myVCChair = ...

Shall I specify setter or not?

Here is an initial specification for a simple Address class. This is a simplification as it ignores complications such as apartments in the same building potentially having the same ‘number’, e.g. 29a, 29b. class Address { private: int number; string name; string postcode; public: //getters implemented ...

In Objective-C on iOS, what is the (style) difference between "self.foo" and "foo" when using synthesized getters?

I have searched many questions on ObjC accessors and synthesized accessors to no avail. This question is more of a "help me settle an issue" question; I don't expect one answer, but I'm rather looking for experts to weigh in on the argument. In a Cocoa Touch class, I would write some code like this (where soundEffects is a synthesized ...

Combining getters and setters into gettersetters

In terms of "good code", is it acceptable to combine set and get methods into one? Like this: public function dir($dir=null) { if (is_null($dir)) return $this->dir; $this->dir = $dir; } ...

When using MVVM pattern, should code relating to property changes go in the setter or an event?

Looking for guidance on where to place code which is dependent upon changes to a property. For example, I have a view model which is used to hold state for an applications settings public SettingsViewModel(ISettingsRepository settings) { _settings = settings; // ... } For each change to a settings property we have to persist ...

setter and getter methods

I know that you use @synthesize to create setter and getter methods, which makes things easier because then you don't have to write your own. There are certain places where you have to use self.property instead of just property in order to make use of the setter and getter methods, such as in dealloc and initWithCoder. This tells me th...

getters and setters for custom classes

If you synthesize a custom class, do getters and setters get created for it? This is the custom class I created. // MyClass.h #import <Foundation/Foundation.h> @interface MyClass : NSObject <NSCoding> { NSString *string1; NSString *string2; } @property (nonatomic, retain) NSString *string1; @property (nonatomic, retain) NSS...

Bestpractices: StructureMap and ASP.NET MVC 2 - Setter Injection/Contructur Injection in an abstract base Controller

public abstract class ConventionController : Controller { public const int PageSize = 5; public IMappingService MappingService { get; set;} } How do I set up StructureMap to get the Instance of IMappingService? Edit: With the help of Joshua Flanagan I now have the following code: EmployeeController public class EmployeeCon...

ruby on rails custom setter help

Hello, sorry for my english, I have a model named Recipe and Recipe has an attribute named duration In my form, I have 2 dropdowns to get duration attribute select_tag 'duration[hours]' select_tag 'duration[minutes]' I need the value of duration attribute like this format hh:mm:ss I have tried with def duration=(d) self.duration...

Setting values of an object

Hi. Let's say I've got a class called House with the two fields name address Each of these fields has got a getter and a setter. Now I want another method in the House class called setValues. This method should set the fields with properties from a passed object of a different type. There would be two ways on how to create this met...

WPF: XAML property declarations not being set via Setters?

I have a WPF application where I'm using dependency properties in codebehind which I want to set via XAML declarations. e.g. <l:SelectControl StateType="A" Text="Hello"/> So in this example I have a UserControl called SelectControl, which has a property called StateType which manipulate some other properties in it's setter. To help...

EventTrigger with Setter in WPF?

I have a normal Button and TextBox in a WPF-Window and I want a Template for the Button with a EventTrigger that listens to Button.Click and then sets a boolean-property of the TextBox. No code-behind. Something like this: <ControlTemplate.Triggers> <EventTrigger SourceName="MyButton" RoutedEvent="Button.Click"> <Setter TargetNam...

Limiting access to a public setter to specific objects (C#)

I'm trying to create a class (in C#) that serves as an environment for my application. I'm trying to make the class dynamic, and send it as a parameter to entities in my application. The problem is, that I want to be able to change the properties of this environment class (public setters), but at the same time I want the classes that re...

Java Reflection to set attributes

Hi. I have a class that has many settable/gettable attributes. I'd like to use reflection to set these attributes, but I have 2 questions about my implementation Here is some stripped down code from my class class Q { public String question_1; public String question_2; public String question_3; public String answer_1; publi...