getters

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...

C++ Virtual Methods for Class-Specific Attributes or External Structure

I have a set of classes which are all derived from a common base class. I want to use these classes polymorphically. The interface defines a set of getter methods whose return values are constant across a given derived class, but vary from one derived class to another. e.g.: enum AVal { A_VAL_ONE, A_VAL_TWO, A_VAL_THREE }; enum B...

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...

Java method naming conventions: Too many getters

Why do Java method names use the "get" prefix so extensively? At least in my Java programs there are a lot of methods with names starting with the word "get". The percentage of get-methods is suspiciously high. I am starting to feel that the word "get" is losing its meaning because of inflation. It is noise in my code. I have noticed th...

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 = ...

Getting the target when using bindable getter in flex

Hi I have the following files: model.as clint.mxml in clint.mxml I have the following line: <s:Group id='clint1' x="model.locationX"> ... in the model.as I have a getter: [bindable(event="locationXChanged")) function get locationX () : int { return ... } My problem is that I need to know within the getter locationX that the id ...

Groovy map - keys with space

I have a map in groovy that looks like the following... def book = [Title of Book: "Groovy Recipes", Author: "Scott Davis", Number of Pages: "241"] I add my each 'book' into a BookList and would like to be able to get each value later on but when I try something like... BookList.Title of Book[0] //prints something like Title[0] inste...

Flex: make getter Bindable in an value object

I have an value object in Flex which looks like: [Bindable] public class MyVO { public var a:ArrayCollection; public var b:ArrayCollection; private var timeSort:Sort; public function ShiftVO(){ timeSort = new Sort(); timeSort.compareFunction = sortDates; } public function get times():ArrayCollectio...

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; } ...

Javascript defineGetter

var a = {}; a.__defineGetter__('test',function() {return 5;}); var i ="test"; Is there any other way I can execute the getter other than a[i]; (while using var i to do it) EDIT: I was asking ways to use var i to do it. I'll explain the real problem a bit better. I am using getters on my namespace object to load modules only wh...

Is return atomic and should I use temporary in getter to be thread safe?

Is it necessary to use a temporary here to be thread-safe? int getVal() { this->_mutex.lock(); int result = this->_val; this->_mutex.unlock(); return result; } I'll give you disassembly of simple RAII test function int test() { RAIITest raii; //let's say it's a scoped lock return 3; } { 0...

php terminology: difference between getters and public methods?

My question is more about terminology then technicalities (or is it?). What's the difference between a getter method and a public method in a class? Are they one in the same or is there a distinction between them? I ask because I'm trying to learn best coding practices and this area seems grey to me. I was commenting my code out and n...

How to implement a getter-function (using callbacks)

I have to request data for a JS-script from a MySQL database (based upon a user-id). I did not find a simple solution for JavaScript and it was not possible to load the data using ajax, because the database is available under a different domain. I implemented a workaround using PHP and curl. Now the JS has to "wait" for the request...

Accessors / Getters and Lazy Initialization

I have a question about overriding auto-generated accessor methods. The following would not work (I believe) because each getter references the other getter. Is there a rule that accessor methods should not use other accessor methods, or do you just have to watch out for these situations individually? -(UIImage *) image{ if(image...

[C++] Is it a good idea to always return references for member variable getters?

If I have a class that has many int, float, and enum member variables, is it considered efficient and/or good practice to return them as references rather than copies, and return constant references where no changes should be made? Or is there a reason I should return them as copies? ...

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...

Beginner C++ Using accessors / getters to pull data from a private member variable (2D array)

Hi guys, total noob here with about 2 months of C++ experience (no other background) so go easy on me. I am writing a battleship game for a programming assignment. The game grid is 15X20 and I am trying to have the grid as a private member variable of the class player. My question is: If the class player has a private member variab...

How do you use an attr_accessor in a select form?

I am trying to capture the identity of a gallery so that I can create a form based around that particular gallery. So I put together a select form, and threw an attr_accessor in my controller. But its failing from all sorts of directions, and I figure its a problem with my syntax. Any whiz's know this? model attr_accessor :existing_g...