Android: Is it good practice to store Views as global variable in class?
By : Юрий Корзун
Date : March 29 2020, 07:55 AM
I wish this helpful for you If what you mean is static variable by global variable, then never ever do that! If you keep views as static variables, the activities holding the views will leak. All the views that you see on the screen are attached to a certain activity, and they hold a reference to the activity, if you keep a static reference to one of the views, the activity will never be garbage collected when the activity is killed(either by pressing the BACK key or you call the finish() method on the activity).
|
Is it good practice to define a getter which does not return a specific field?
By : user2329192
Date : March 29 2020, 07:55 AM
should help you out The method is fine, although I can understand that you wouldn't want to call it getRandomSite() because it looks like a getter method. Building on Gio's answer, I suggest you call the method fetchRandomSite() because as you said, this method does not generate the random site, it simply picks (or fetches) it out of a NavigableMap.
|
Java return method good practice when filling an object
By : rookie26
Date : March 29 2020, 07:55 AM
hope this fix your issue The problem with your code is that User class exposes its internals through the setter methods, breaking the information hiding principle. Your approach could lead to an unmaintainable code base, i.e. it will be difficult to trace all the components that could modify a User object. I think a better approach is to have a constructor that takes directly the information needed to build a User. code :
public class User {
private String surname;
private String name;
public User(String name, String surname) {
this.name = name;
this.surname = surname;
}
public String getSurname() {
return surname;
}
public String getName() {
return name;
}
}
public User getUser() {
User user = new User(getNameFromSomewhere(),
getSurnameFromSomewhere());
return user;
}
|
Is making module method variables global good practice in Python?
By : Deepak bisht
Date : March 29 2020, 07:55 AM
To fix this issue What I normally do when I need such kind of global variables is to make a class and define them there. So for example a Configuration class with values stored in them. This has the following advantages (not an ending list):
|
Why is it good practice to return at the end of a method
By : user3763675
Date : March 29 2020, 07:55 AM
Hope this helps There is a school of thought that says that you should have a single point of entry, and a single point of exit. If you have more, you should refactor the code to be clearer. I don't subscribe to that thought though, and frequently use guard clauses, like this:
|