setters

If you are using getters and setters, how should you name the private member variables?

As kind of a follow up to this question about prefixes, I agree with most people on the thread that prefixes are bad. But what about if you are using getters and setters? Then you need to differeniate the publicly accessible getter name from the privately stored variable. I normally just use an underscore, but is there a better way? ...

Which is more appropriate: getters and setters or functions?

Is it ever appropriate to abandon the "getMyValue()" and "setMyValue()" pattern of getters and setters if alternative function names make the API more obvious? For example, imagine I have this class in C++: public class SomeClass { private: bool mIsVisible; public: void draw(); void erase(); } I could add functions to g...

Entity objects getters and setters for data properties

I recently started working in Java and was introduced to the wild and crazy world of getters and setters for everything. I hated it at first, but quickly got used to it. Too used to it. I have been spending a lot of time lately thinking more about class design. One of the things I am trying to do is avoid the trap of doing getters and s...

After restricting Setter scope and then applying an interface, scope is disregarded!

If I set a Friend-level scope on a setter, like this... Public Class MyClass Public Property IsDirty() As Boolean Get Return _isDirty End Get Friend Set(ByVal trueFalse As Boolean) _isDirty = trueFalse End Set End Property End Class ...And then call it from another proje...

Java: Are Getters and Setters evil?

I'm currently working on a simple game in Java with several different modes. I've extended a main Game class to put the main logic within the other classes. Despite this, the main game class is still pretty hefty. After taking a quick look at my code the majority of it was Getters and Setters (60%) compared to the rest that is truly nee...

Is this setter 'evil'

There's alot of talk about getters and setters being 'evil' and what not. My question is: is the following setter evil? (rest of class omitted for brevity's sake) int balance public void deposit(int amount) { this.balance += amount; } This class is emulating an ATM. In the UK there are a few ATM's that lets you deposit as ...

How to expose properties of a WPF DataTemplate?

I have a data template that I use in many pages, the data template contains a few buttons, I want to hide some of these buttons by triggers (I mean setting the IsEnabled Property of these buttons in the page where I use this DataTemplate). In other words, I would even like to set in style triggers/setters a property 'ButtonXIsEnabled', ...

Getter/Setter problem in C#

I am doing static bool isWorking { get { return _isWorking; } set { myform.treeView1.Enabled = !value; _isWorking = value; } } and stepping through the debugger shows it stops at the first set line. After trying this line instead set { myform.treeView1.Enabled = !(_isWorking = ...

Overriding a setter method, and getting info out

I have a setter method (setMinimumNumberOfSides) that I want to override after using synthesize. In it, I'm putting in a constraint on the instance variable to make sure the int is within certain bounds. Later in a custom init method, I'm setting another instance variable (numberOfSides), but I need to make sure minimumNumberOfSides an...

Why I should use __get() and __set()-magic methods in php?

Duplicate: When do/should I use __construct(), __get(), __set(), and __call() in PHP? Well, the title says it all. This is one area that I have not found any good answer. Can anyone explain to me why/how to use them correctly? Aren't they just a bad design decision? ...

Using object's setter to trigger data updates, best practices.

I have an object that gets instantiated in a linq to sql method. When the object fields are being assigned, i want to check a date field and if it is an old date, retrieve data from another table and perform calculations before continuing with assigning this object. Is there anything wrong with triggering such an event through the proper...

Constructor with all class properties or default constructor with setters?

Following are the two approaches: constructor with all the class properties Pros: I have to put an exact number of types of parameters so if I make an error the compiler warns me (by the way, is there a way to prevent the problem of having erroneously switched two Integer on the parameter list?) Cons: if I have lots of properties t...

Getters/setters in Java

I'm new to Java, but have some OOP experience with ActionScript 3, so I'm trying to migrate relying on stuff I know. In ActionScript 3 you can create getters and setters using the get and set keywords, meaning you create a method in the class and access data through a property of an instance of that class. I might sound complicated, but...

Sould setter for delegate be in the interface ?

Hello, We have lot of object with this kind of design : Interface and several implementations, and use of several object by composition. Exemple : Foo implements IFoo and have a Bar object who implements IBar Foo also have a setBar(IBar bar) method for injection of dependancie. My question is : the setter sould't be in the interfac...

Allen Holub wrote "You should never use get/set functions", is he correct?

Allen Holub wrote the following, You can't have a program without some coupling. Nonetheless, you can minimize coupling considerably by slavishly following OO (object-oriented) precepts (the most important is that the implementation of an object should be completely hidden from the objects that use it). For example, an object's insta...

Can't Set Property's Property

I am having trouble with, as I said, setting a property's property. Let's say I have a class that represents a transaction. In my class I have a property that represents another class, such as this: Public Class PersonRecord _myPerson = new Person() Public Property MyPerson as Person Get _myPerson = Person.GetApp...

Simple Getter/Setter comments

What convention do you use to comment getters and setters? This is something I've wondered for quite some time, for instance: /** * (1a) what do you put here? * @param salary (1b) what do you put here? */ public void setSalary(float salary); /* * (2a) what do you put here? * @return (2b) */ public float salary(); I always find...

Code Layout for getters and setters

I am writing a class that has lots of getters and setters and was wondering on what people thought about the following: The normal way is to code like the following: public function setChangeSort($changeSort) { self::$changeSort = $changeSort; } public function getChangeSort() { return self::$changeSort; } What are your opin...

How can I access the Groovy setter shortcut for multiparameter setters?

Let's say I have a java.util.Properties object. The Properties object has a method called setProperty(String name,String value). Is there a setter shortcut for it? EDIT: maybe the Properties class was not the best example, because I think it handles that by adding the keys as properties. But how about a setter method that takes an arbit...

How often do you see abuse of C# shorthand getters/setters?

In C# you can create getter/setters in a simpler way than other languages: public int FooBar { get; set; } This creates an internal private variable which you can't address directly, with the external property 'FooBar' to access it directly. My question is - how often do you see this abused? It seems like it has a high potential to v...