I'm trying to solve my earlier-posted dilemma of a class attribute 
(array) that is "remembering" elements that should have been unset().  
The good news is that, according to some testing I've been doing (I have 
separated the relevant code and am directly testing it), it looks like 
PHP is behaving as expected -- I really hope that it's just an error on 
my part, so that I can fix it.

But out of this exercise I have begun to wonder something.  If someone 
who is better-schooled than I in object oriented programming style could 
respond I would be very grateful.

I have a method in my class that essentially unsets an array element.  
The frequency with which this method is called varies depending on the 
circumstances, so i can't "hard-code" the solution to this problem.  But 
after the method is done being called (however many times it need be 
called), a second method needs to be called.  Think of this second one 
as a "clean up" method, that needs to be called anytime the first method 
is called, but ONLY ONCE per script instance, no matter how many times 
the first method was called.  This means that I can't just call method 
#2 every time I call method #1.

Now, originally I was doing all of this method calling from the script 
itself.  For each variable POSTed by the user, I call the first method.  
But now that I have a second "clean-up" method that needs to be called, 
how should I go about it?  Should I have one "master" method in the 
class that is called from the script, and itself does all the work?  
This keeps all of the work in the class, and out of the calling script.


Should I keep the class free of code that only executes according to 
POST variables from the user, and keep this kind of thing in the calling 
script.  That way, the object's class is more flexible, and can be used 
in more contexts.

Again, this is really a question of style -- I can get it to work either 
way.  I'm just wondering if a class should be written to handle ALL CODE 
related to its class, and keep most of the work in "private" methods 
(not really enforced in PHP but whatever), or whether the class should 
be written so that it has a lot of public methods that can be called 
from the script, which means that the class is more flexible in the long 

A question of encapsulation vs modularity, it would seem.

Your thoughts are gratefully accepted.



Erik Price
Web Developer Temp
Media Lab, H.H. Brown

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to