Page 1 of 1

General class/function question

Posted: Sun Oct 09, 2005 3:53 pm
by legendaryfox
Hey all...kinda new to the forums, although I think I've asked a question here before...

So here's my question...I've just started to use/apply OOP in PHP, and I've got to say, it's made it so easy for me to code, that there was this one time when I wrote an entire if-then block around 100-ish lines when I could've used the function I built inside the object...

Anyways, anecdotes aside, i have a question about creating functions in classes - it's actually more a question of good practice/reference. When creating functions inside classes, should they be created in an active- or passive- voice?

Example: I'm currently developing a web game, which will have spies to steal estimated information about each player's empire. Should I make a function like

$player_object->spied_on($spyer_id), which would basically get the info of that player, "spy-hash" it so that it's not complete accurate, then return the info to $spyer_id

OR

$player_object->spy($player_id), which would get the info on $player_id, "spy-hash" it, then return to $player_object

I personally would go with the second one, and that both basically do the same thing, but I'm not sure if there's a difference in coding practice...

Thanks!

Posted: Sun Oct 09, 2005 3:59 pm
by feyd
I'd say having a spy class where you can call a method to do the spying may be better... however, if you want to hold to you constraints, the latter is my personal preference.