Bir yöntem refactor zaman

0 Cevap php

This is intended to be more of a discussion than an outright question, hence I've made it community wiki. When do you choose to break a method into smaller methods.

Ben bir amacı vardır bir yöntemi var demek, yani bir yapılandırma dosyasını yüklemek için

public function configure($file){
    $info = path_info(file);
    $ext = $info['extension'];

    switch($ext){
    case 'ini':
    //code to parse ini files
    break;

    case 'xml':
    //code to parse xml files
    break;

    case 'php':
    //code to parse php files
    break;
}

}

Şahsen, ben anahtarı sonucuna bağlı olarak dahili yöntemleri kırmak istiyorum - ama daha sıralı yöntem, bir dizi adım var demek - yani

public function doSequence(){
    $stepOne = //some database access to retrieve values
    $stepTwo = //the result of some interpretation of values
    $stepThree = //a fresh database interaction based on the interpreted values
    $stepFour = //prep values for return
    return $values
}

Yani, ayrıntı uygun seviyeye yöntemleri üstlenmeden için yol gösterici ilke nedir?

0 Cevap