|
-
June 21st, 2007, 04:41 PM
#20
Re: What's with all the Get/Set lines?
that link you provided was for OOP in PHP. PHP isn't quite the same as C++, C# or even java. it has a much more limited context and I'm not totally convinced that it works best in a strict OOP implementation. I love OOP and PHP but split OOP and standard PROC coding in it to about 50/50.
in .net having public members isn't going to hurt anything. it's definitely against what most consider "best practice" and it will limit some things that you can do with your object, but hey, its your baby, ignore or use anything you want to.
I always found it annoying to create getter / setter methods for member access.
It always felt awkward to me to reference a variable like a method. I really like the interface provided by .net properties because accessing an object's members "like" a public member feels a bit more logical in my eyes. there are things that you can do with properties that you cannot do with public members, but I cant think of one thing you can do with a public variable that you cannot do with a property.
things you cannot do with public variables that you can do with properties:
1. validate input / output
2. lazy initialization
3. access to read / write
4. virtualized members (mark the "variable" as virtual or abstract to allow for inheritors to implement their own functionality of what that member does for the concrete class).
4. notify observers on access (trigger events on get or set)
there are probably many more but these are what come to mind.
like I said, do what you want, but don't miss the forest for the trees.
Last edited by MadHatter; June 21st, 2007 at 04:47 PM.
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
|