getter

Simple Getter/Setter comments

喜夏-厌秋 提交于 2019-11-27 04:10:07
问题 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 getSalary(); I always find I'm pretty much writing the exact same thing for 1a/b and 2a/b, something like 1a) Sets the salary of the employee, 1b) the salary of the employee. It just seems so

Magic __get getter for static properties in PHP

拜拜、爱过 提交于 2019-11-27 04:09:44
public static function __get($value) does not work, and even if it did, it so happens that I already need the magic __get getter for instance properties in the same class. This probably is a yes or no question, so, it is possible? No, it is not possible. Quoting the manual page of __get : Member overloading only works in object context. These magic methods will not be triggered in static context. Therefore these methods can not be declared static. In PHP 5.3, __callStatic has been added ; but there is no __getStatic nor __setStatic yet ; even if the idea of having/coding them often comes back

Conventions for accessor methods (getters and setters) in C++

陌路散爱 提交于 2019-11-27 03:03:16
Several questions about accessor methods in C++ have been asked on SO, but none was able satisfy my curiosity on the issue. I try to avoid accessors whenever possible, because, like Stroustrup and other famous programmers, I consider a class with many of them a sign of bad OO. In C++, I can in most cases add more responsibility to a class or use the friend keyword to avoid them. Yet in some cases, you really need access to specific class members. There are several possibilities: 1. Don't use accessors at all We can just make the respective member variables public. This is a no-go in Java, but

yii2

无人久伴 提交于 2019-11-27 00:22:26
yii2 内部规定了 __construct 函数的构造形式,以键值对儿数组作为参数,进行属性的初始化,但要注意给属性赋值的工作是转交给基类 yii\base\Yii::configure 方法的,故无法直接访问本类的私有属性进行初始化工作 ,但我们可以使用属性的 setter/getter 方法来完成 yii\base\Object yii2 在实例化一个类时可以将此类的属性以 key=>value 的数组形式传参初始化本类的一些属性 所有的组件的构造函数都继承至 yii\base\Object::__construct() 这里需要注意的是,yii2 以安全为原则,并没有将类的私有属性开放给初始化的参数数组,原因是 __construct 中的初始工作是调用的 yii\base\Yii::configure() 方法,上下文切换到本类外部,无法访问私有变量(这里便引出了 php 的私有变量访问域和 __set/__get魔术方法) /** * Constructor. * The default implementation does two things: * * - Initializes the object with the given configuration `$config`. * - Call [[init()]]. * * If this method is

Please explain Getter and Setters in Objective C [duplicate]

房东的猫 提交于 2019-11-27 00:07:15
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Setters and Getters (Noobie) - iPhone SDK I am a beginner here. I have just started learning iOS for the last two months and I do not have any programming background. (Little bit of Java though). Can anyone please explain what is getter and setter in Objective C? What is the use of them? Why do we use @property and @synthesize ? 回答1: Getter is a method which gets called every time you access (read value from) a

Looking for a short & simple example of getters/setters in C#

久未见 提交于 2019-11-27 00:00:36
问题 I am having trouble understanding the concept of getters and setters in the C# language . In languages like Objective-C, they seem an integral part of the system, but not so much in C# ( as far as I can tell ). I have read books and articles already, so my question is, to those of you who understand getters & setters in C#, what example would you personally use if you were teaching the concept to a complete beginner ( this would include as few lines of code as possible )? 回答1: I think a bit

Java setters and getters

烂漫一生 提交于 2019-11-26 23:31:41
问题 I have been struggling with setters and getters in java for quite a long time now. For instance, if I want to write a class with some information as name, sex, age etc with appropriate set and get methods. Then in a another class I want to test my set and getters with this as a example: personInfo = myInfo() = new Personinfo("Anna", "female", "17"); How do I do that? I know that I can have a printout like: public void printout() { System.out.printf("Your name is: " + getName() + " and you are

Monitor All JavaScript Object Properties (magic getters and setters)

懵懂的女人 提交于 2019-11-26 22:29:46
How do I emulate PHP-style __get() and __set() magic getter/setters in JavaScript? A lot of people say that this is currently impossible. I am almost certain that it is possible because projects like nowjs ( http://nowjs.com ) do something like this. I know that you can utilize get and set , but these don't work when you're not sure what the property name will be. For example, what if you wanted an event handler to execute when a new property is created ? Example of what I'd want to do: var obj = {}; notify(obj, function(key, value) { //key is now the name of the property being set. //value is

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

扶醉桌前 提交于 2019-11-26 21:40:46
This question already has an answer here: Why use getters and setters/accessors? [closed] 38 answers 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 instance variables (member fields that aren't constants), should always be private. Period. No exceptions. Ever. I mean it. (You can occasionally use protected methods

DatabaseException: Found two getters or fields with conflicting case sensitivity

♀尐吖头ヾ 提交于 2019-11-26 21:21:25
问题 Every time I try to retrieve data from my database, I get com.google.firebase.database.DatabaseException: Found two getters or fields with conflicting case sensitivity for property: n for any of my fields that are a single letter. Googling this issue gives 0 results and I can find no case incongruities in my code. I don't know if this is a bug in Firebase or if I have to do something special for any fields with names 1 character long. Here is the rest of the error report if it makes a