Complex classes like Profile 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 Profile, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
8 | class Profile extends User |
||
9 | { |
||
10 | /** |
||
11 | * @var int |
||
12 | */ |
||
13 | protected $allow; |
||
14 | |||
15 | /** |
||
16 | * QQ号 |
||
17 | * @var int |
||
18 | */ |
||
19 | protected $account; |
||
20 | |||
21 | /** |
||
22 | * 邮箱 |
||
23 | * @var string |
||
24 | */ |
||
25 | protected $email; |
||
26 | |||
27 | /** |
||
28 | * 个性签名 |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $lnick; |
||
32 | |||
33 | /** |
||
34 | * 生日 |
||
35 | * @var Birthday |
||
36 | */ |
||
37 | protected $birthday; |
||
38 | |||
39 | /** |
||
40 | * 未知 |
||
41 | * @var string |
||
42 | */ |
||
43 | protected $occupation; |
||
44 | |||
45 | /** |
||
46 | * 电话 |
||
47 | * @var string |
||
48 | */ |
||
49 | protected $phone; |
||
50 | |||
51 | /** |
||
52 | * 学院 |
||
53 | * @var string |
||
54 | */ |
||
55 | protected $college; |
||
56 | |||
57 | /** |
||
58 | * 未知 |
||
59 | * @var int |
||
60 | */ |
||
61 | protected $constel; |
||
62 | |||
63 | /** |
||
64 | * @var int |
||
65 | */ |
||
66 | protected $blood; |
||
67 | |||
68 | /** |
||
69 | * 主页 |
||
70 | * @var string |
||
71 | */ |
||
72 | protected $homepage; |
||
73 | |||
74 | /** |
||
75 | * 未知 |
||
76 | * @var int |
||
77 | */ |
||
78 | protected $stat; |
||
79 | |||
80 | /** |
||
81 | * vip_info |
||
82 | * @var int |
||
83 | */ |
||
84 | protected $vipInfo; |
||
85 | |||
86 | /** |
||
87 | * 国家 |
||
88 | * @var string |
||
89 | */ |
||
90 | protected $country; |
||
91 | |||
92 | /** |
||
93 | * 省 |
||
94 | * @var string |
||
95 | */ |
||
96 | protected $province; |
||
97 | |||
98 | /** |
||
99 | * 城市 |
||
100 | * @var string |
||
101 | */ |
||
102 | protected $city; |
||
103 | |||
104 | /** |
||
105 | * 简介 |
||
106 | * @var string |
||
107 | */ |
||
108 | protected $personal; |
||
109 | |||
110 | /** |
||
111 | * @var string |
||
112 | */ |
||
113 | protected $nick; |
||
114 | |||
115 | /** |
||
116 | * 生肖 |
||
117 | * @var int |
||
118 | */ |
||
119 | protected $shengXiao; |
||
120 | |||
121 | /** |
||
122 | * female|male |
||
123 | * @var string |
||
124 | */ |
||
125 | protected $gender; |
||
126 | |||
127 | /** |
||
128 | * 手机号 |
||
129 | * @var string |
||
130 | */ |
||
131 | protected $mobile; |
||
132 | |||
133 | /** |
||
134 | * @return int |
||
135 | */ |
||
136 | public function getAllow() |
||
140 | |||
141 | /** |
||
142 | * @param int $allow |
||
143 | */ |
||
144 | public function setAllow($allow) |
||
148 | |||
149 | /** |
||
150 | * @return int |
||
151 | */ |
||
152 | public function getAccount() |
||
156 | |||
157 | /** |
||
158 | * @param int $account |
||
159 | */ |
||
160 | public function setAccount($account) |
||
164 | |||
165 | /** |
||
166 | * @return string |
||
167 | */ |
||
168 | public function getEmail() |
||
172 | |||
173 | /** |
||
174 | * @param string $email |
||
175 | */ |
||
176 | public function setEmail($email) |
||
180 | |||
181 | /** |
||
182 | * @return string |
||
183 | */ |
||
184 | public function getLnick() |
||
188 | |||
189 | /** |
||
190 | * @param string $lnick |
||
191 | */ |
||
192 | public function setLnick($lnick) |
||
196 | |||
197 | /** |
||
198 | * @param Birthday $birthday |
||
199 | */ |
||
200 | public function setBirthday(Birthday $birthday) |
||
204 | |||
205 | /** |
||
206 | * @return Birthday |
||
207 | */ |
||
208 | public function getBirthday() |
||
212 | |||
213 | /** |
||
214 | * @param string $occupation |
||
215 | */ |
||
216 | public function setOccupation($occupation) |
||
220 | |||
221 | /** |
||
222 | * @return string |
||
223 | */ |
||
224 | public function getOccupation() |
||
228 | |||
229 | /** |
||
230 | * @param string $phone |
||
231 | */ |
||
232 | public function setPhone($phone) |
||
236 | |||
237 | /** |
||
238 | * @return string |
||
239 | */ |
||
240 | public function getPhone() |
||
244 | |||
245 | /** |
||
246 | * @param string $college |
||
247 | */ |
||
248 | public function setCollege($college) |
||
252 | |||
253 | /** |
||
254 | * @return string |
||
255 | */ |
||
256 | public function getCollege() |
||
260 | |||
261 | /** |
||
262 | * @param int $constel |
||
263 | */ |
||
264 | public function setConstel($constel) |
||
268 | |||
269 | /** |
||
270 | * @return int |
||
271 | */ |
||
272 | public function getConstel() |
||
276 | |||
277 | /** |
||
278 | * @param int $blood |
||
279 | */ |
||
280 | public function setBlood($blood) |
||
284 | |||
285 | /** |
||
286 | * @return int |
||
287 | */ |
||
288 | public function getBlood() |
||
292 | |||
293 | /** |
||
294 | * @param string $homepage |
||
295 | */ |
||
296 | public function setHomepage($homepage) |
||
300 | |||
301 | /** |
||
302 | * @return string |
||
303 | */ |
||
304 | public function getHomepage() |
||
308 | |||
309 | /** |
||
310 | * @param int $stat |
||
311 | */ |
||
312 | public function setStat($stat) |
||
316 | |||
317 | /** |
||
318 | * @return int |
||
319 | */ |
||
320 | public function getStat() |
||
324 | |||
325 | /** |
||
326 | * @param int $vipInfo |
||
327 | */ |
||
328 | public function setVipInfo($vipInfo) |
||
332 | |||
333 | /** |
||
334 | * @return int |
||
335 | */ |
||
336 | public function getVipInfo() |
||
340 | |||
341 | /** |
||
342 | * @param string $country |
||
343 | */ |
||
344 | public function setCountry($country) |
||
348 | |||
349 | /** |
||
350 | * @return string |
||
351 | */ |
||
352 | public function getCountry() |
||
356 | |||
357 | /** |
||
358 | * @param string $province |
||
359 | */ |
||
360 | public function setProvince($province) |
||
364 | |||
365 | /** |
||
366 | * @return string |
||
367 | */ |
||
368 | public function getProvince() |
||
372 | |||
373 | /** |
||
374 | * @param string $city |
||
375 | */ |
||
376 | public function setCity($city) |
||
380 | |||
381 | /** |
||
382 | * @return string |
||
383 | */ |
||
384 | public function getCity() |
||
388 | |||
389 | /** |
||
390 | * @param string $personal |
||
391 | */ |
||
392 | public function setPersonal($personal) |
||
396 | |||
397 | /** |
||
398 | * @return string |
||
399 | */ |
||
400 | public function getPersonal() |
||
404 | |||
405 | /** |
||
406 | * @param string $nick |
||
407 | */ |
||
408 | public function setNick($nick) |
||
412 | |||
413 | /** |
||
414 | * @return string |
||
415 | */ |
||
416 | public function getNick() |
||
420 | |||
421 | /** |
||
422 | * @param int $shengXiao |
||
423 | */ |
||
424 | public function setShengXiao($shengXiao) |
||
428 | |||
429 | /** |
||
430 | * @return int |
||
431 | */ |
||
432 | public function getShengXiao() |
||
436 | |||
437 | /** |
||
438 | * @param string $gender |
||
439 | */ |
||
440 | public function setGender($gender) |
||
444 | |||
445 | /** |
||
446 | * @return string |
||
447 | */ |
||
448 | public function getGender() |
||
452 | |||
453 | /** |
||
454 | * @param string $mobile |
||
455 | */ |
||
456 | public function setMobile($mobile) |
||
460 | |||
461 | /** |
||
462 | * @return string |
||
463 | */ |
||
464 | public function getMobile() |
||
468 | } |
||
469 |