getter

Are getters and setters poor design? Contradictory advice seen [duplicate]

喜欢而已 提交于 2019-11-25 22:32:20
问题 This question already has answers here : Why use getters and setters/accessors? (38 answers) Closed 4 years ago . I\'m currently working on a simple game in Java with several different modes. I\'ve extended a main Game class to put the main logic within the other classes. Despite this, the main game class is still pretty hefty. After taking a quick look at my code the majority of it was Getters and Setters (60%) compared to the rest that is truly needed for the logic of the game. A couple of

Why JSF calls getters multiple times

僤鯓⒐⒋嵵緔 提交于 2019-11-25 22:11:26
问题 Let\'s say I specify an outputText component like this: <h:outputText value=\"#{ManagedBean.someProperty}\"/> If I print a log message when the getter for someProperty is called and load the page, it is trivial to notice that the getter is being called more than once per request (twice or three times is what happened in my case): DEBUG 2010-01-18 23:31:40,104 (ManagedBean.java:13) - Getting some property DEBUG 2010-01-18 23:31:40,104 (ManagedBean.java:13) - Getting some property If the value

How and when should I load the model from database for h:dataTable

只谈情不闲聊 提交于 2019-11-25 21:59:08
问题 I\'ve a data table as below: <h:dataTable value=\"#{bean.items}\" var=\"item\"> I\'d like to populate it with a collection from the database obtained from a service method so that it is immediately presented when the page is opened during an initial (GET) request. When should I call the service method? And why? Call it before page is loaded. But how? Call it during page load. How? Call it in the getter method. But it is called multiple times. Something else? 回答1: Do it in bean's

How do getters and setters work?

寵の児 提交于 2019-11-25 21:47:41
问题 I\'m from the php world. Could you explain what getters and setters are and could give you some examples? 回答1: Tutorial is not really required for this. Read up on encapsulation private String myField; //"private" means access to this is restricted public String getMyField() { //include validation, logic, logging or whatever you like here return this.myField; } public void setMyField(String value) { //include more logic this.myField = value; } 回答2: In Java getters and setters are completely

View&#39;s getWidth() and getHeight() returns 0

一个人想着一个人 提交于 2019-11-25 21:43:52
问题 I am creating all of the elements in my android project dynamically. I am trying to get the width and height of a button so that I can rotate that button around. I am just trying to learn how to work with the android language. However, it returns 0. I did some research and I saw that it needs to be done somewhere other than in the onCreate() method. If someone can give me an example of how to do it, that would be great. Here is my current code: package com.animation; import android.app