|
-
July 24th, 2006, 02:45 AM
#1
Get/Set neccessary
I have a little class. I have some variables which I would like to access from other classes. IS there any point in writing get/set for this? Why not only make the attribut public and skip the get/set method.
-
July 24th, 2006, 02:56 AM
#2
Re: Get/Set neccessary
use it as a property, in your class..
you can set each variable property to accept or only return values.
// am assuming here that you know how to make them into a property
-
July 24th, 2006, 03:19 AM
#3
Re: Get/Set neccessary
Because of encapsulation, the fundamental property of OOP. There is big difference between the class's protocol - how it looks out, which methods exposes to outer world, and the class implementation - which fields it contains and how it deals with them. Nothing outside you class, including other your class, have not to take care about the class implementation.
Believe us, this is not only academic excercise. If you would use getter/setter rather then public fields, you will avoid many problems in future.
- Make it run.
- Make it right.
- Make it fast.
Don't hesitate to rate my post. 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|