accessors

what are the tradeoffs of using accessor methods vs public variables in php

I'm looking for advice/experience on using public variables vs private variables with accessor methods in php. eg $obj->foo = 'a'; echo $obj->foo; vs $obj->setFoo('a'); echo $obj->getFoo(); What I like about public variables is the shorter syntax - just seems less work to use. I understand that it could make refactoring more diffic...

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

What is the best way to set up a form to get a temp var?

I am making a photo upload form. Before they begin, they have two choices. They can create a new gallery, OR they can choose from an existing gallery. I was thinking the best way to lay this out would be two have two forms. One for the create one that would take them to the create page. That's easy, and practically done. But the second...

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 I write a const accessor that returns a reference to a member object, so it might be edited?

Here is the problem. I wrote this function to return a reference to the i element of a member vector, so this element could be edited. Here is the code: Letter& Literal::get (int i) const { return lit_m.at (i); //Vector of Letter objects } But g++ won't let me assign that element to a non-const reference: g++ -o literal.o -c lite...

Is there a technical reason why an automatic property must define both a get and set accessor

I know that automatic properties must define a get and set accessor method, I also know that it is possible for either of these accessors to be made invisible by means of an access modifier. Is there a technical reason why the compiler is happy with public object Property { get; set; } but not public object Property { get; } My (p...

Getting the error code from an IOException

Getting the (hex) error code from an IOException, or regular Exception! Is this possible? i know it HAS a error code, (HResult) but the get accessor is private. I would do some sort of ComException thing, but im not sure about the pros/cons of doing this, and if its even possible/the same. ...

initializer, properties, accessors and copy/retain/readonly

I want to understand how to set the parameters of properties (accessors). I took the following code from an example of Kal calendar. // Holiday.h @interface Holiday : NSObject { NSDate *date; NSString *name; NSString *country; } @property (nonatomic, retain, readonly) NSDate *date; @property (nonatomic, retain, readonly) NSStri...