get/set methods should be used judiciously. As it is, you could simply make your members public, remove the get/set methods, and the effect would be the same with less code.
Narue
Bad Cop
15,460 posts since Sep 2004
Reputation Points: 6,464
Solved Threads: 1,401
AS Narue says, use get/set judiciously. The greatest power of Java (and any OO programming language that is,) is the ability to 'encapsulate' data (members) to better control how to use that data.
A good example in your above code is if you wish to make the course member 'read-only' you can exclude the set method. This would prevent anyone from making unwanted changes to the course member data. You can still set the course member data internally to the class, but not outside the class (since it would still be a private member variable.)
jerbo
Junior Poster in Training
84 posts since Sep 2004
Reputation Points: 11
Solved Threads: 1
brilliant
that you can't read dates? mwa, not so astonishing.
about Sandwiches99, if you know you're 4 years late... why still post?
stultuske
Posting Sensei
3,135 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
JAnd I love you.
you consider that to be Java related? :D
stultuske
Posting Sensei
3,135 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
public class Pearson {
private String name;
// likely a setter somewhere in here
// your getter method here
}
ehm... yup, that's bout it ...
except: I don't see a getter, I don't see a setter and I don't see an explanation or a question in your post.
if you have a question about it, it's easier for us to answer it if we know you have a question and if we know what that question is.
stultuske
Posting Sensei
3,135 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
And neither of you guys think it is fishy that nobody with over 10 posts on this forum cares? But that two people with one post each happen to come in this thread and co-sign? Fooled us.
BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354
Unless this is already well known from you programmers, removing the get/set methods and making variables public would defeat the purpose of 'Object-Oriented' Programming.
not necessarilly, but you would need a good explanation as to the why of the omission to convince me of it being a good design decision.
For example when creating something where the extra overhead (call stack creation...) of using getters and setters would yield unacceptable performance (think a raytracer or 3D animation package) you might want to have some class members in the core of that system that are called at extremely high rate to be publicly accessible.
jwenting
duckman
8,392 posts since Nov 2004
Reputation Points: 1,662
Solved Threads: 337
Most everything you said above is wrong. You can only implement interfaces not other classes. You can extend other classes in an inheritance hierarchy. Or if you want access to another classes public members you can simply instantiate a new Object of that classtype and then say object.variable
BestJewSinceJC
Posting Maven
2,772 posts since Sep 2008
Reputation Points: 874
Solved Threads: 354