"wrapper" functions
Posted: Fri Mar 16, 2012 8:00 am
Lately i've been looking at some code i created and i noticed the following
The purpose for this is that if i extend class A i would use doSomething() instead of _doSomething() or even if class A isn't extended. This seems to correspond with what i read on wikipedia about the subject:
1. What determines the use of a wrapper function? If you create a wrapper function for each protected method this would increase the amount of code you have to check / work through at a later stage.
2. Setting the method to protected stops it from being used outside the class but inside the class, what is a better option: to wrap the protected method or use it directly (throughout the class and any classes extended from the innitial class)?
Code: Select all
<?php
class A {
//
protected function _doSomething()
{
// some code
}
//
public function doSomething()
{
$this->_doSomething();
}
}
?>I have 2 questions about this:Wikipedia wrote: A wrapper function is a function in a computer program whose main purpose is to call a second function with little or no additional computation.
1. What determines the use of a wrapper function? If you create a wrapper function for each protected method this would increase the amount of code you have to check / work through at a later stage.
2. Setting the method to protected stops it from being used outside the class but inside the class, what is a better option: to wrap the protected method or use it directly (throughout the class and any classes extended from the innitial class)?