getters

How to encapsulate an array in Java

Hi, i'm starting with Java and i'm learning about setters,getters and encapsulation. I have a very simple program, 2 classes: Container has a private int array (numArray) with his setter & getter. Main creates a Container object and uses it in totalArray method. public class Container { private int numArray[]= {0,0,0}; pub...

tutorial on getters and setters?

im from the php world. are there good tutorials explaining what getters and setters are and could give you some examples? ...

Why stick to get-set and not car.speed() and car.speed(55) respectively?

Apart from unambiguous clarity, why should we stick to: car.getSpeed() and car.setSpeed(55) when this could be used as well : car.speed() and car.speed(55) I know that get() and set() are useful to keep any changes to the data member manageable by keeping everything in one place. Also, obviously, I understand that car.speed() and car.s...

Is object creation in getters bad practice ?

Let's have an object created in a getter like this : public class Class1 { public string Id { get; set; } public string Oz { get; set; } public string Poznamka { get; set; } public Object object { get { // maybe some more code return new Ob...

Java: return static nested class

Hi, I have a static nested class, which I would like to return via a static accessor (getter). public class SomeClass { public static class Columns<CC> { ... public static int length = 5; } public static Columns<?> getColumnEnumerator() { int x = Columns.length; //no problems retur...

Passing getter function, or tricky pointer in AS3

So I know as3 doesn't have pointers, but I thought there might be a way to use object variables as pointers. Right now I'm relying on passing a function that gets the get function, it's not a very elegant solution something like this: myvar = function():int{return objectName.getVarValue}; The other option would be to change all the g...

What are getter and setters? PHP5

What are getters and setters in PHP5? Can someone give me a good example with an explanation? ...

How do input field methods (text_area, text_field, etc.) get attribute values from a record within a form_for block?

I have a standard Rails 2.3.5 app with a model called Post. Post has an attribute called url, and the following getter is defined: def url p = 'http://' u = self[:url] u.starts_with?(p) ? u : "#{p}#{u}" end If I load up script/console, I can do Post.first.url and get the desired result (e.g. it returns http://foo.com if the attr...

getter , setter c#

Hi i have got various custom datatypes in my web application to map some data from the database. something like: Person Id Name Surname and i need a List of persons in most of my application's pages i was thinking to create a getter property that gets the list of persons from the database and store into cache in this way i do not ha...

Replacement for C style struct in OOP

Hey all, I am a student with a mainly electronics background getting into programing. The more I get into it, the more I realize how bad I am at it. I am trying to get better at OO design. One thing I have been reading about is the use of Getters and Setters. http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html?page=1 ...

What is array portability?

From this page: http://www.doctrine-project.org/documentation/manual/1_2/en/working-with-models#dealing-with-relations:creating-related-records You can see that it says $obj['property']; is the recommended way of referring to an object's property in Doctrine for array portability purposes. I never heard about this term before and goog...

Java design: too many getters

After writing a few lesser programs when learning Java the way I've designed the programs is with Model-View-Control. With using MVC I have a plethora of getter methods in the model for the view to use. It feels that while I gain on using MVC, for every new value added I have to add two new methods in the model which quickly get all clu...

Value object getter

Hi, I've got a value object, which stores info for example amount. The getAmount() getter returns amount in cents. However in various places, we need to get amount in dollar. There are 2 approaches I can think of: write a convert method and place it in a utility class. add a getAmountInDollar() getter in the value object. I prefer ...

Ambiguous reference when getter/setter have different visibilities

The following code raises an ambiguous reference to value at compile time: import flash.display.Sprite; public class Main extends Sprite { private var _value : Number = 0.; public function get value() : Number { return _value; } private function set value(v : Number) : void { _value = v; } public function...

What does it means? [c#]

If we define a property as public property and in this property we have a protected getter. what does it means? if property is public, what does defining a protected getter for that, means? please see below code: public ISessionFactory SessionFactory { protected get { return sessionFactory; } set { sessionFactory...

What is a good practice to access class attributes in class methods?

I always wonder about the best way to access a class attribute from a class method in Java. Could you quickly convince me about which one of the 3 solutions below (or a totally different one :P) is a good practice? public class Test { String a; public String getA(){ return this.a; } public setA(String a){ ...

Change field access to getter / setter method access

Hi everyone, is it possible to change external class field accesses in Java to getter / setter calls automatically, and also hide the exposed fields? I'm using Javabeans and I want change notifications when a field property changes (this is important). I've found cglib which can automatically insert the property change call to the Prope...

Why can't I initialize a class through a setter?

If I have a custom class called Tires: #import <Foundation/Foundation.h> @interface Tires : NSObject { @private NSString *brand; int size; } @property (nonatomic,copy) NSString *brand; @property int size; - (id)init; - (void)dealloc; @end ============================================= #import "Tires.h" @implementation Tir...

What are the benefits of using properties internally?

Encapsulation is obviously helpful and essential when accessing members from outside the class, but when referring to class variables internally, is it better to call their private members, or use their getters? If your getter simply returns the variable, is there any performance difference? ...

What Getters and Setters should and shouldn't do.

Possible Duplicate: Convention question: When do you use a Getter/Setter function rather than using a Property I've run into a lot of differing opinions on Getters and Setters lately, so I figured I should make it into it's own question. A previous question of mine received an immediate comment (later deleted) that stated set...