I have a java class. it has many getter/stter methods and some other business logics methods. Shall I put those getter/setter methods in front of business methods or shall I put business methods first ?
If your company has a policy, follow that. if you are doing this for yourself, then you can decide what you want - but stick with it in all your code. Oracle's web site has the "java" standard, but you are not forced to go by their recommendations.
Other programmers might mock you if you don't follow their guidance without a reason, though, so you have been warned.
There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Note that the Sun/Oracle code conventions don't really address the specific question asked in this thread. The closest it comes is here:
These methods should be grouped by functionality rather than by scope or accessibility. For example, a private class method can be in between two public instance methods. The goal is to make reading and understanding the code easier.
It's open to interpretation whether you this means the getters and setters should be put together or not, and it gives no guidance at all whether they would be before or after other methods. It's up to each individual or group to decide that.
Mike Simmons wrote:It's open to interpretation whether you this means the getters and setters should be put together or not, and it gives no guidance at all whether they would be before or after other methods. It's up to each individual or group to decide that.
What I tried to say is that, as Fred said, if the company has a policy, follow it. These conventions can be used. This way, as Jesper said, it doesn't really matter if a business method comes before or after a getter/setter method.