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 ...
I'm new to Java, but have some OOP experience with ActionScript 3, so I'm trying to migrate relying on stuff I know.
In ActionScript 3 you can create getters and setters using ...
I am writing some immutable types in Java and wonder about how to name the accessor methods.
The Java Bean specification says that the names of accessors should be getX or isX, ...
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 ...
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 ...
I have some questions about java. There are two questions in the code (I left them as comments).
Also what is the purpose of using setting and getting methods? Could you please ...
Good day!
I created two classes namely Setting and Game; In my game access the Setting class first.
In my setting class, I call the setter method from Game which is .setDifficulty. ...
Could somebody please provide an example where getters and setters are not required?
I still do not get the idea, I guess a very huge class with lots of attributes must have ...
I got used to writing enum-style singleton when all of a sudden, someone reviewing my code asked me change it because it is not in the project's coding convention. He asked ...
It is always recommended to use getter/setter for accessing private variables. Why would it not be a better idea to declare them as public and access them. Anyway we are accessing ...
In C++ a getter & setter for a private data member is very useful due to the ability to control mutability via a const return value.
In Java, if I understand correctly ...
is it possible to configure Doxygen to exclude my getter and setter? We're using beans Extensivly, and for the internal documentation there is really no need to have the getter and ...
I have been going through clean code book which states that the class should not expose the internal state of its data and only should be exposing the behavior. In case ...
I know this might be a stupid question to many but I usually like to stick to correct/better implementation. In Java, when writing a getter/setter, would it be better to refer ...
I'm fairly confident that there's no way this could work, but I wanted to ask anyway just in case I'm wrong:
I've heard many times that whenever you have a certain number ...
I have a private inner class that encapsulates some functionality. It populates two ArrayLists. I have getters for the ArrayLists that just return the private variable. Are the getters needed? Can ...
I'm in the need of do some clean up of some invisible characters (\r\n) and html tags for specific getters on my entities.
I've been trying to use mixIns to modify what's ...
what is the name of your property , is it length or m_length cause you are appearing to set the value of m_length. and secondly why do you need the isLength() method It appeares from your code that the name of our property is m_length and not length youe method reads m_length = length so you are setting the value of ...
For getters and setters I'm usually happy with the default doc generated when I do nothing at all. It's a good exercise to try to name other methods and their arguments so well that readers don't need any further doc. If you can write a short description of the method, make that the name!
Did you read what the page that Jelle Klap linked to says on using final on methods? It says this: For Performance? Since a final method is only implemented in the declaring class, there is no need to dynamically dispatch a call to a final method, and static invocation can be used instead. The compiler can emit a direct call to ...
I need to put the data in the variable that I have setters and getters for into a vector, then write it back out. How would I use or would I use the getters to put the data into the vector? If not, how would I get the data to the vector. Would this be a separate class?
I am a newbie and trying to learn, I have a type & service table type t_id t_name blah blah service s_id t_id (fk) blah blah For a Add Screen, I have Type in a text field & JTable for the service (can be multiple for one type). Now normally when it is recommended to have getters & setters for everything, ...
The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - ...
Hello Everybody, Back to basics. A getter method return a value for an instance variable. For example the following getter method returns a price public float getPrice( ) { return price; } Now if I wish this get method to return a formated price, is it suitable here to have the getter method return the formated value or it is better ...
to put it a bit simpler: the main idea behind it is _encapsulation_ what you want is that only the dog-class cares about details of dogs. whoever works with dogs is not supposed to have (say: need) any knowledge about how dogs works. okay, it might seem a bit trivial to protect a private string field with getters and setters. but ...
Your current code will not compile. It looks like you closed the class right after you defined your instance variables and then you are defining funtions after this that dont go into a class body. Also... ClassInstructor does not extend from any class so you are not using the instance variables of any other class. I suggest you extend from both ...
One of the reasons is to protect access to the attribute, making the attribute a private and then only allowing access via getter and setter methods restricts users. e.g. maybe the attribute is only suppose to be readOnly, then by only adding a getter method the class creator can restrict access to that attribute. Also getters and setters are a good ...
Hi All, When Mutable objects such as Date objects are having getters and setters, is it a good practice to clone the objects. ex: Instead of this; public Date getDate() { return dateObj; } have some thing like this; public Date getDate() { Date date = null; if (this.date != null) { date = (Date) this.date.clone(); } return date; } Thanks ...
Business Logic is a term used to describe logic which "runs" your application. It's generally spoken about when people are describing a common design pattern -- MVC, where the objective is to separate business logic from presentation logic (separate the complex bulk of the code from the more simplistic template which displays the results). Business Logic is a board term for ...
Hey all, please consider the situation: I have 1 class that stores customer info with getters and setters I would like access the customer class with a GUI class and pump data into it by creating an instance of the customer class (works fine up to here) Now i have a third GUI class that i would like to retrieve my ...
The reason why it's considered bad to expose the member variables directly by making them public is because of the concepts of encapsulation and low coupling. If you would directly make the member variables of a class visible to the outside world, you're really showing the inside of the class to the outside world. If you need to change the implementation ...
Difficult to read because you haven't preserved indentation. Confusing. You are adding 20% in the calculate class (that should start with a capital letter) but you are never passing the money back. You are creating a new customer (should read Customer) object, setting the 48000000 on that, then it isn't used because it is in a different class.
Hello, I got a question about getters and setters, I'm wondering for some time now, about the best approach of setting/getting private or protected fields in the class' code to which those fields belong. (in the constructor for example) I used to go about this by just using the fields directly like this: public class MyClass { private int a; private ...
Yes it's possible to modify private fields when using getters. Look at this example below in which an element is being added to list retrieved from getter package org.vivek.java.references; import java.util.ArrayList; import java.util.List; public class ModifyClassFieldsUsingGetter { private List
hi there, I've come to the point where, in the 2 books I am using right now, the authors are mentioning the getters and setters as a way to "enforce" control over the variables. It doesnt quite make sense to me... the couple of examples I foudn online do not make much sense either... can someone shed some light on this ...
I am creating a program where I need to pass different parameters into a single getter and have it print out different valaues based on the paramter. So far I have one string which I used substrings to divide the string into different chunks then convert them to ints. so now I need to assign these different ints to paramter numbers ...
To augment to that, even if your setter/getter does not implement any logic and plainly sets/gets the values, you reserve the possibility to do so later. If you expose instance variables to the outside world, you are forced to do so forever and are hardly able to change your implementation later. Also, there is no way to control the state of ...
Hi All, As part of a requirement, I had to have an instance variable in a Singleton class(whose instance is created at the start of app). I have getters and setters for the variable. Somewhere, I have to access the variable where I dont have a hold of the singleton object. Is it a good practice to make the getters and ...
my class Recipes has a getter to take various data, in a window i create an instance of Recipes and i try to get the "name", but if i create the file with those value, there is no value. the file is created, but empty /* * To change this template, choose Tools | Templates * and open the template in ...
Hi all, i have a doubt, In below class class employeeVO { private String name; public void setName(String name) { this.name=name; } public String getName() { return name; } } We are using POJO class like this, but why we are keeping variable scope as private, In setter & getter we are not doing anything, then we can keep variable as ...
Absolutely new to Java. :c Introduced to Eclipse a few weeks back, and I'm getting really confused with the Strings class. Anyone care to post how getters and setters are used with doubles? Say I want to make a simple program where the user inputs a length and height, and using getters and setters, the program computes for the area of ...
Hey I'm programming a game that is divided into squares, like a grid. Therefore I have positions such as (x,y) in that grid. Now I want to give some of these positions a certain int value, so I created a new class called Field, that had both the position arguments and my int value: (x, y, value) - that part works ...
public class Counter { private int currentCount; private int counterAdd; private int counterSubtract; //Mutators public void setCurrentCount() {this.currentCount = currentCount; } public void setCounterAdd() {this.counterAdd = currentCount++; } public void setCounterSubtract() {if(counterSubtract >0) currentCount--; } //Accessor public int getCurrentCount() {return currentCount; } public void outputCurrentCount() {System.out.println("The count is " + currentCount); } }
While doing a little research before answering you I found multiple articles that debated whether setters/getters were "evil/necessary" as far as a design standpoint. I realize your question doesn't go that in depth so I continued searching. I have been programming for less than 6 months so I didn't just want to run away with this one. On yahoo forums I ...
private void processArguments(String[] args) { assigns private boolean trimWhiteSpace = true; (private boolean trimWhiteSpace is declared on a class level) private void updateESGDatabase() { attempts to access trimWhiteSpace via public boolean getWhitespace() { in the following manner: classname.getWhitespace This only works when object of that class is created inside the same method that is calling getWhitespace Above seems strange. If i ...
1) if you see some code that gets data from another object, processes it, and then puts it back into the same object 2) if the data retrieved is big -- not just a single field, but a large collection -- and the operations on it are non-trivial 3) (lesser indicator) if the data retrieved is non-final. (So, Math.PI doesn't count; ...
As noted you appear to have three constructors, including a default (package level accessible) one. And the way you called your constructor that was the one that was being called. I would remove that constructor, it appears to be a mistake. Or at the very least finish it by assigning the values correctly.
I typed in the first Name: John then middle name: P then last name: Doe the program reads the first scanner out but shoots an error on the input line. I am confused as to why I am getting the error. I tried the application with out the setter method and it worked as it should but now that I am ...
Not sure how good eclipse is, coming from a Visual Studio background I haven't found an editor that is as good as that if I was honest but the transition isn't bad at all. I am using something called JCreator. My University unfortunately wants me to use some rubbish called BlueJ which is rather annoying but I'm just programming in JCreator ...
This is a general OOP question. There is a ClassA with a private instance variable consisting of an array of ClassB objects. ClassB has a private instance variable x. ClassA objects need to know something about the value of x for their array of ClassB objects; e.g x might be an int, and ClassA objects might need to know the sum ...
First, nobody said that you should use getters and setters in the first place. The only thing that's worse than dumb mutators/accessors would be the exposure of the attribute itself. Second, you certainly don't need mutators "internally". Third: consider you redesigning your class to store a person's birthdate instead of its age - makes sense if one thinks about it, doesn't ...
**** Error Thu Feb 28 10:33:56 GMT 2008 1204194836644 /atg/dynamo/servlet/pipeline/RequestScopeManager/RequestScope-28244/rmg/authentication/RMGLoginFormHandler Exception while performing lookup on LDAP atg.repository.RepositoryException: The supplied constant value is null **** debug Thu Feb 28 10:33:57 GMT 2008 1204194837957 /rmg/registration/profile/po/PoProfileFormHandler Value of Postcode in getPostcode method = null **** debug Thu Feb 28 10:34:17 GMT 2008 1204194857537 /atg/dynamo/servlet/pipeline/RequestScopeManager/RequestScope-28297/rmg/registration/profile/po/PoProfileFormHandler Value of Postcode in getPostcode method = null **** debug ...
I have a class which has public members and another class which directly access the first class's members. Now i want to change my first class in such a way that all its variables are private which has to be accessed by any other class using getters only. I want to write a new class which will change my second class ...
hi, thanks for your reply so quick. because i need to find out the solution in a short time. you might be able to direct me to search for it on the right way, let make myself clearer first. let's say i have xml configuration file looks like java.lang.Stringjava.lang.String and with this xml file, i want to create ...
"If we are reading data from different sheets in an excel sheet, is it a best practice to use getters and setters?" if original sheets are conceptually the same, is not important to use getters and setters, but if they are different types of data contained in sheets you can abstract the data container object, use interface to generalize operations needed, ...