Reply to Re: Getting and Setting and best practise

Your name:

Reply:


Posted by Steve on 04/20/07 19:18

|| > private static myBar as string
|| > public static property bar() as string
|| > get
|| > return myBar
|| > end get
|| > set(byval value as string)
|| > ' add some validation
|| > ' maybe throw some errors
|| > ' else, if all is well
|| > myBar = value
|| > end set
|| > )
|| >
||
|| Yes, I've done plenty of .NET programming, but do you see what you did
|| there? You created a Getter/Setter specifically for the variable
|| MyBar, you didn't rely on a "magic" (again, the *actual term*) method
|| to interpret which private variable you wanted. You specifically
|| defined that to get myBar, you need to call bar().

__set is a reserved word as is __get...nothing bad about it.

what i think you fail to understand here is that we are getting the same
result as the above doing this:

<?
class foo
{
public static $bar = '';
public static $fighter = '';
private function __construct()
{
// uh oh...is this magic? lol
}
function __get(...)
{
switch (var name)
{
case 'bar' : return self::getBar();
break;
case 'fighter' : return self::getFighter();
break;
default : throw an error here;
}
}
function __set(...)
{
switch (var name)
{
case 'bar' : self::setBar(__set's value param);
break;
case 'fighter' : self::setFighter(__set's value param);
break;
default : throw an error here;
}
}
private function getBar(){ return self::$bar; }
private function getFighter{ return self::$fighter; }
private function setBar($params)
{
// validate
// if not good, throw an error
// else
self::$bar = $params;
}
private function setFighter($params)
{
// validate
// if not good, throw an error
// else
self::$fighter = $params;
}
}
?>

so, how is this different than vb's get/set other than php give ONE place to
handle it (__get/__set). you'd just prefer the gets/sets would be grouped
together with the property def? guess what, it is php...a scripting
language. we don't get properties. we have scoped variables and functions.
that's all.

at least this functionality would make php seem more like an oop instead of
a hacked simulation...using getSomething or setSomething. i wonder what
other languages would use? in english both get/set are short. however in
most other languages, they both are quite long. :) this technique handles
that too, since you don't have to fuck with anything.

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация