Getter/setter on javascript array?

Using Proxies, you can get the desired behavior: var _arr = [‘one’, ‘two’, ‘three’]; var accessCount = 0; function doSomething() { accessCount++; } var arr = new Proxy(_arr, { get: function(target, name) { doSomething(); return target[name]; } }); function print(value) { document.querySelector(‘pre’).textContent += value + ‘\n’; } print(accessCount); // 0 print(arr[0]); // ‘one’ print(arr[1]); // …

Read more

Java method naming conventions: Too many getters

I personally don’t use getters and setters whenever it’s possible (meaning : I don’t use any framework who needs it, like Struts for instance). I prefer writing immutable objects (public final fields) when possible, otherwise I just use public fields : less boiler plate code, more productivity, less side effects. The original justification for get/set …

Read more

Java Interface Usage Guidelines — Are getters and setters in an interface bad?

I don’t see why an interface can’t define getters and setters. For instance, List.size() is effectively a getter. The interface must define the behaviour rather than the implementation though – it can’t say how you’ll handle the state, but it can insist that you can get it and set it. Collection interfaces are all about …

Read more

Allen Holub wrote “You should never use get/set functions”, is he correct? [duplicate]

I don’t have a problem with Holub telling you that you should generally avoid altering the state of an object but instead resort to integrated methods (execution of behaviors) to achieve this end. As Corletk points out, there is wisdom in thinking long and hard about the highest level of abstraction and not just programming …

Read more