|
This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. -- [ Picked text/plain from multipart/alternative ] I do prefer use getter and setter inside the class too. I can then ensure validity checking. We might be several people modifying the same class in a team. We have to make sure that a variable is assigned correctly. The only way to make sure it is assigned correctly is to use the setter. In the future you may have to assign a validity checking in your code. If you have not used the setters, but set the variables directly you will have to check all your code ! I have extended that to the class/subclass problem. I never declare a variable as protected, but always as private. The subclass access it through getter and setter. I think that the consistency of the variables must be ensured at the class level. (NB: this is the way it is done in Smalltalk too). Hope this help Gilles -----Original Message----- From: Eyers, Daniel [mailto:daniel.eyers@honeywell.com] Sent: lundi, 8. avril 2002 19:43 To: 'java400-l@midrange.com' Subject: Java Style Question Something I've been thinking about.... For a class that has instance variables, I tend to use private variables and getter/setter methods for access. In the class itself, however, I'm wondering which makes sense, to use the getter/setters within the class itself, *or* to access the variables directly. I guess I'm sort of torn because I can make a case for each method. Obviously, using the getter/setters creates additional overhead *but* using them within the class seems to be more roboust. Additionally, I tend to consider creating a generic method to add a certain functionality, then create methods that overload by adding (or removing) parameters. Here what I mean.... Let's say I have a right justification method (much like Aaron's, actually ;-) ) and for a certain type of data, the data is expected to be 8 characters. So..... <code> public String rightJustify(String s, int length) { (insert your favorite code here) } </code> and then <code> public String rightJustify(String s) { return rightJustify(s,8); } </code> Any comments on either technique would be welcome... I'd like to some different points of view to help me decide the merits of these techniques.... thanks dan _______________________________________________ This is the Java Programming on and around the iSeries / AS400 (JAVA400-L) mailing list To post a message email: JAVA400-L@midrange.com To subscribe, unsubscribe, or change list options, visit: http://lists.midrange.com/cgi-bin/listinfo/java400-l or email: JAVA400-L-request@midrange.com Before posting, please take a moment to review the archives at http://archive.midrange.com/java400-l. ********************************************************************** This E-mail and any files transmitted with it are confidential and intended for the exclusive use of the addressee(s) only. You should not disclose its contents to any other person. If you are not the intended recipient please notify the sender immediately. **********************************************************************
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.