Ferreteria/v0.6/fx/From*
< Ferreteria | v0.6 | fx
Jump to navigation
Jump to search
About
Beginning a method-name with "From" is a Woozalien coding convention.
The general idea is that these are static "pseudoconstructors" used as an alternative to __construct() so as to suggest that certain parameters are expected.
- The default
__construct()method will usually (but not always) be markedprotected, in order to minimize incorrect construction. - Its return-type is always the clade's interface.
- Its contents should be simple and straightforward:
- creates a blank object (always called
$oThis) - calls that object's corresponding protected
With*()method written for this purpose, or other pre-existing initialization methods as appropriate. - returns the created object (
$oThis)
- creates a blank object (always called
Example
interface iExample {
static function FromArray(array $ar) : iExample;
}
class cExample implements iExample {
public static function FromArray(array $ar) : iExample {
$oThis = new static; // creates an object of this class or whatever podling was used to invoke it
$oThis->WithArray($ar);
return $oThis;
}
protected function WithArray(array $ar) : void {
// Actual initialization takes place here; can be more involved/complicated.
}
}