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 |
||
| 13 | class Profile extends User |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var int |
||
| 17 | */ |
||
| 18 | protected $allow; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * QQ号. |
||
| 22 | * |
||
| 23 | * @var int |
||
| 24 | */ |
||
| 25 | protected $account; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * 邮箱. |
||
| 29 | * |
||
| 30 | * @var string |
||
| 31 | */ |
||
| 32 | protected $email; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * 个性签名. |
||
| 36 | * |
||
| 37 | * @var string |
||
| 38 | */ |
||
| 39 | protected $lnick; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * 生日. |
||
| 43 | * |
||
| 44 | * @var Birthday |
||
| 45 | */ |
||
| 46 | protected $birthday; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * 未知. |
||
| 50 | * |
||
| 51 | * @var string |
||
| 52 | */ |
||
| 53 | protected $occupation; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * 电话. |
||
| 57 | * |
||
| 58 | * @var string |
||
| 59 | */ |
||
| 60 | protected $phone; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * 学院. |
||
| 64 | * |
||
| 65 | * @var string |
||
| 66 | */ |
||
| 67 | protected $college; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * 未知. |
||
| 71 | * |
||
| 72 | * @var int |
||
| 73 | */ |
||
| 74 | protected $constel; |
||
| 75 | |||
| 76 | /** |
||
| 77 | * @var int |
||
| 78 | */ |
||
| 79 | protected $blood; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * 主页. |
||
| 83 | * |
||
| 84 | * @var string |
||
| 85 | */ |
||
| 86 | protected $homepage; |
||
| 87 | |||
| 88 | /** |
||
| 89 | * 未知. |
||
| 90 | * |
||
| 91 | * @var int |
||
| 92 | */ |
||
| 93 | protected $stat; |
||
| 94 | |||
| 95 | /** |
||
| 96 | * vip_info. |
||
| 97 | * |
||
| 98 | * @var int |
||
| 99 | */ |
||
| 100 | protected $vipInfo; |
||
| 101 | |||
| 102 | /** |
||
| 103 | * 国家. |
||
| 104 | * |
||
| 105 | * @var string |
||
| 106 | */ |
||
| 107 | protected $country; |
||
| 108 | |||
| 109 | /** |
||
| 110 | * 省 |
||
| 111 | * |
||
| 112 | * @var string |
||
| 113 | */ |
||
| 114 | protected $province; |
||
| 115 | |||
| 116 | /** |
||
| 117 | * 城市 |
||
| 118 | * |
||
| 119 | * @var string |
||
| 120 | */ |
||
| 121 | protected $city; |
||
| 122 | |||
| 123 | /** |
||
| 124 | * 简介. |
||
| 125 | * |
||
| 126 | * @var string |
||
| 127 | */ |
||
| 128 | protected $personal; |
||
| 129 | |||
| 130 | /** |
||
| 131 | * @var string |
||
| 132 | */ |
||
| 133 | protected $nick; |
||
| 134 | |||
| 135 | /** |
||
| 136 | * 生肖. |
||
| 137 | * |
||
| 138 | * @var int |
||
| 139 | */ |
||
| 140 | protected $shengXiao; |
||
| 141 | |||
| 142 | /** |
||
| 143 | * female|male. |
||
| 144 | * |
||
| 145 | * @var string |
||
| 146 | */ |
||
| 147 | protected $gender; |
||
| 148 | |||
| 149 | /** |
||
| 150 | * 手机号. |
||
| 151 | * |
||
| 152 | * @var string |
||
| 153 | */ |
||
| 154 | protected $mobile; |
||
| 155 | |||
| 156 | /** |
||
| 157 | * @return int |
||
| 158 | */ |
||
| 159 | public function getAllow() |
||
| 163 | |||
| 164 | /** |
||
| 165 | * @param int $allow |
||
| 166 | */ |
||
| 167 | public function setAllow($allow) |
||
| 171 | |||
| 172 | /** |
||
| 173 | * @return int |
||
| 174 | */ |
||
| 175 | public function getAccount() |
||
| 179 | |||
| 180 | /** |
||
| 181 | * @param int $account |
||
| 182 | */ |
||
| 183 | public function setAccount($account) |
||
| 187 | |||
| 188 | /** |
||
| 189 | * @return string |
||
| 190 | */ |
||
| 191 | public function getEmail() |
||
| 195 | |||
| 196 | /** |
||
| 197 | * @param string $email |
||
| 198 | */ |
||
| 199 | public function setEmail($email) |
||
| 203 | |||
| 204 | /** |
||
| 205 | * @return string |
||
| 206 | */ |
||
| 207 | public function getLnick() |
||
| 211 | |||
| 212 | /** |
||
| 213 | * @param string $lnick |
||
| 214 | */ |
||
| 215 | public function setLnick($lnick) |
||
| 219 | |||
| 220 | /** |
||
| 221 | * @param Birthday $birthday |
||
| 222 | */ |
||
| 223 | public function setBirthday(Birthday $birthday) |
||
| 227 | |||
| 228 | /** |
||
| 229 | * @return Birthday |
||
| 230 | */ |
||
| 231 | public function getBirthday() |
||
| 235 | |||
| 236 | /** |
||
| 237 | * @param string $occupation |
||
| 238 | */ |
||
| 239 | public function setOccupation($occupation) |
||
| 243 | |||
| 244 | /** |
||
| 245 | * @return string |
||
| 246 | */ |
||
| 247 | public function getOccupation() |
||
| 251 | |||
| 252 | /** |
||
| 253 | * @param string $phone |
||
| 254 | */ |
||
| 255 | public function setPhone($phone) |
||
| 259 | |||
| 260 | /** |
||
| 261 | * @return string |
||
| 262 | */ |
||
| 263 | public function getPhone() |
||
| 267 | |||
| 268 | /** |
||
| 269 | * @param string $college |
||
| 270 | */ |
||
| 271 | public function setCollege($college) |
||
| 275 | |||
| 276 | /** |
||
| 277 | * @return string |
||
| 278 | */ |
||
| 279 | public function getCollege() |
||
| 283 | |||
| 284 | /** |
||
| 285 | * @param int $constel |
||
| 286 | */ |
||
| 287 | public function setConstel($constel) |
||
| 291 | |||
| 292 | /** |
||
| 293 | * @return int |
||
| 294 | */ |
||
| 295 | public function getConstel() |
||
| 299 | |||
| 300 | /** |
||
| 301 | * @param int $blood |
||
| 302 | */ |
||
| 303 | public function setBlood($blood) |
||
| 307 | |||
| 308 | /** |
||
| 309 | * @return int |
||
| 310 | */ |
||
| 311 | public function getBlood() |
||
| 315 | |||
| 316 | /** |
||
| 317 | * @param string $homepage |
||
| 318 | */ |
||
| 319 | public function setHomepage($homepage) |
||
| 323 | |||
| 324 | /** |
||
| 325 | * @return string |
||
| 326 | */ |
||
| 327 | public function getHomepage() |
||
| 331 | |||
| 332 | /** |
||
| 333 | * @param int $stat |
||
| 334 | */ |
||
| 335 | public function setStat($stat) |
||
| 339 | |||
| 340 | /** |
||
| 341 | * @return int |
||
| 342 | */ |
||
| 343 | public function getStat() |
||
| 347 | |||
| 348 | /** |
||
| 349 | * @param int $vipInfo |
||
| 350 | */ |
||
| 351 | public function setVipInfo($vipInfo) |
||
| 355 | |||
| 356 | /** |
||
| 357 | * @return int |
||
| 358 | */ |
||
| 359 | public function getVipInfo() |
||
| 363 | |||
| 364 | /** |
||
| 365 | * @param string $country |
||
| 366 | */ |
||
| 367 | public function setCountry($country) |
||
| 371 | |||
| 372 | /** |
||
| 373 | * @return string |
||
| 374 | */ |
||
| 375 | public function getCountry() |
||
| 379 | |||
| 380 | /** |
||
| 381 | * @param string $province |
||
| 382 | */ |
||
| 383 | public function setProvince($province) |
||
| 387 | |||
| 388 | /** |
||
| 389 | * @return string |
||
| 390 | */ |
||
| 391 | public function getProvince() |
||
| 395 | |||
| 396 | /** |
||
| 397 | * @param string $city |
||
| 398 | */ |
||
| 399 | public function setCity($city) |
||
| 403 | |||
| 404 | /** |
||
| 405 | * @return string |
||
| 406 | */ |
||
| 407 | public function getCity() |
||
| 411 | |||
| 412 | /** |
||
| 413 | * @param string $personal |
||
| 414 | */ |
||
| 415 | public function setPersonal($personal) |
||
| 419 | |||
| 420 | /** |
||
| 421 | * @return string |
||
| 422 | */ |
||
| 423 | public function getPersonal() |
||
| 427 | |||
| 428 | /** |
||
| 429 | * @param string $nick |
||
| 430 | */ |
||
| 431 | public function setNick($nick) |
||
| 435 | |||
| 436 | /** |
||
| 437 | * @return string |
||
| 438 | */ |
||
| 439 | public function getNick() |
||
| 443 | |||
| 444 | /** |
||
| 445 | * @param int $shengXiao |
||
| 446 | */ |
||
| 447 | public function setShengXiao($shengXiao) |
||
| 451 | |||
| 452 | /** |
||
| 453 | * @return int |
||
| 454 | */ |
||
| 455 | public function getShengXiao() |
||
| 459 | |||
| 460 | /** |
||
| 461 | * @param string $gender |
||
| 462 | */ |
||
| 463 | public function setGender($gender) |
||
| 467 | |||
| 468 | /** |
||
| 469 | * @return string |
||
| 470 | */ |
||
| 471 | public function getGender() |
||
| 475 | |||
| 476 | /** |
||
| 477 | * @param string $mobile |
||
| 478 | */ |
||
| 479 | public function setMobile($mobile) |
||
| 483 | |||
| 484 | /** |
||
| 485 | * @return string |
||
| 486 | */ |
||
| 487 | public function getMobile() |
||
| 491 | } |
||
| 492 |