1 | <?php |
||
13 | class Holding extends LazyResource |
||
14 | { |
||
15 | /* @var string */ |
||
16 | public $holding_id; |
||
17 | |||
18 | /* @var Bib */ |
||
19 | public $bib; |
||
20 | |||
21 | /* @var Items */ |
||
22 | public $items; |
||
23 | |||
24 | /* @var MarcRecord */ |
||
25 | protected $_marc; |
||
26 | |||
27 | public function __construct(Client $client, Bib $bib, $holding_id) |
||
34 | |||
35 | /** |
||
36 | * Get the model data. |
||
37 | */ |
||
38 | protected function fetchData() |
||
42 | |||
43 | /** |
||
44 | * Check if we have the full representation of our data object. |
||
45 | * |
||
46 | * @param $data |
||
47 | * |
||
48 | * @return bool |
||
49 | */ |
||
50 | protected function isInitialized($data) |
||
54 | |||
55 | /** |
||
56 | * Update the MARC record on this holding object. Chainable method. |
||
57 | * |
||
58 | * @param string $xml |
||
59 | * |
||
60 | * @return Holding |
||
61 | */ |
||
62 | public function setMarcRecord($xml) |
||
68 | |||
69 | /** |
||
70 | * Called when data is available to be processed. |
||
71 | * |
||
72 | * @param mixed $data |
||
73 | */ |
||
74 | protected function onData($data) |
||
78 | |||
79 | /** |
||
80 | * Generate the base URL for this resource. |
||
81 | * |
||
82 | * @return string |
||
83 | */ |
||
84 | protected function urlBase() |
||
88 | |||
89 | /** |
||
90 | * Get the MARC record for this holding object. |
||
91 | */ |
||
92 | public function getRecord() |
||
96 | |||
97 | /** |
||
98 | * Get the items for this holding. |
||
99 | */ |
||
100 | public function getItems() |
||
104 | } |
||
105 |
If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.
Let’s take a look at an example:
Our function
my_function
expects aPost
object, and outputs the author of the post. The base classPost
returns a simple string and outputting a simple string will work just fine. However, the child classBlogPost
which is a sub-type ofPost
instead decided to return anobject
, and is therefore violating the SOLID principles. If aBlogPost
were passed tomy_function
, PHP would not complain, but ultimately fail when executing thestrtoupper
call in its body.