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?
...
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...
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...
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...
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...
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 ...
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', ...
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 = ...
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...
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?
...
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...
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...
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...
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 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...
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...
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...
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...
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...
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...