Complex classes like Dict often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Dict, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
24 | class Dict extends Fwolflib { |
||
|
|||
25 | |||
26 | |||
27 | /** |
||
28 | * Dict data array |
||
29 | * @var array |
||
30 | */ |
||
31 | public $aData = array(); |
||
32 | |||
33 | |||
34 | /** |
||
35 | * Constructor |
||
36 | * |
||
37 | * @param array $ar_cfg |
||
38 | */ |
||
39 | public function __construct ($ar_cfg = array()) { |
||
42 | |||
43 | |||
44 | /** |
||
45 | * Get relate value for given pk |
||
46 | * |
||
47 | * @param mixed $ar_pk Array or string of pk. |
||
48 | * @param mixed $col Array or string of cols for return. |
||
49 | * @return mixed |
||
50 | */ |
||
51 | public function Get ($ar_pk, $col = '') { |
||
73 | |||
74 | |||
75 | /** |
||
76 | * Get cols you want to query. |
||
77 | * |
||
78 | * If $col not assigned, assign as first col which is not pk. |
||
79 | * '*' means all cols. |
||
80 | * @param mixed $col Array or string of cols. |
||
81 | * @return mixed |
||
82 | */ |
||
83 | protected function GetCol ($col = '') { |
||
113 | |||
114 | |||
115 | /** |
||
116 | * Get data from array by assigned cols |
||
117 | * |
||
118 | * @param array $ar_data |
||
119 | * @param mixed $col |
||
120 | * @return mixed |
||
121 | */ |
||
122 | protected function GetColData ($ar_data, $col) { |
||
139 | |||
140 | |||
141 | /** |
||
142 | * Get data fit given condition |
||
143 | * |
||
144 | * In condition, use {col} and native php syntax. |
||
145 | * Delimiter can change in SetStruct(). |
||
146 | * @param string $s_cond |
||
147 | * @param string $col Wanted cols. |
||
148 | * @return array 2-dim array of result. |
||
149 | * @see SetStruct() |
||
150 | */ |
||
151 | public function GetList ($s_cond = '', $col = '*') { |
||
175 | |||
176 | |||
177 | /** |
||
178 | * Get SQL for write dict data to db |
||
179 | * |
||
180 | * @param object $o_db Adodb conn object. |
||
181 | * @param boolean $b_truncate With truncate part? |
||
182 | * @return string |
||
183 | * @see Adodb |
||
184 | */ |
||
185 | public function GetSql ($o_db, $b_truncate = true) { |
||
234 | |||
235 | |||
236 | /** |
||
237 | * Get SQL for write dict data to db, truncate part. |
||
238 | * |
||
239 | * @param object $o_db Adodb conn object. |
||
240 | * @return string |
||
241 | * @see Adodb |
||
242 | */ |
||
243 | public function GetSqlTruncate ($o_db) { |
||
260 | |||
261 | |||
262 | /** |
||
263 | * Init dict content |
||
264 | * |
||
265 | * @return object |
||
266 | */ |
||
267 | public function Init () { |
||
276 | |||
277 | |||
278 | /** |
||
279 | * Insert value to $this->aData |
||
280 | * |
||
281 | * @param array $ar_data 1 or 2-dim data array. |
||
282 | * @return object |
||
283 | */ |
||
284 | public function Set ($ar_data) { |
||
296 | |||
297 | |||
298 | /** |
||
299 | * Insert value to $this->aData |
||
300 | * |
||
301 | * @param array $ar_data 2-dim data array. |
||
302 | * @return object |
||
303 | */ |
||
304 | protected function SetData ($ar_data) { |
||
335 | |||
336 | |||
337 | /** |
||
338 | * Set data structure, usually override by sub class. |
||
339 | * |
||
340 | * @return object |
||
341 | */ |
||
342 | public function SetStruct () { |
||
353 | |||
354 | |||
355 | } // end of class Dict |
||
356 | ?> |
||
357 |
This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.