さまざまなプロジェクトのコードに、コードの臭いや悪いことのように見える何かに気づきましたが、対処できません。
「きれいなコード」を書き込もうとしている間、コードを読みやすくするためにプライベートメソッドを使いすぎる傾向があります。問題は、コードが確かにきれいであるが、テストするのが難しいことです(そう、私はプライベートメソッドをテストできることを知っています...)、一般的に私には悪い習慣のようです。
次に、.csvファイルからデータを読み取り、顧客のグループ(さまざまなフィールドと属性を持つ別のオブジェクト)を返すクラスの例を示します。
public class GroupOfCustomersImporter {
    //... Call fields ....
    public GroupOfCustomersImporter(String filePath) {
        this.filePath = filePath;
        customers = new HashSet<Customer>();
        createCSVReader();
        read();
        constructTTRP_Instance();
    }
    private void createCSVReader() {
        //....
    }
    private void read() {
        //.... Reades the file and initializes the class attributes
    }
    private void readFirstLine(String[] inputLine) {
        //.... Method used by the read() method
    }
    private void readSecondLine(String[] inputLine) {
        //.... Method used by the read() method
    }
    private void readCustomerLine(String[] inputLine) { 
        //.... Method used by the read() method
    }
    private void constructGroupOfCustomers() {
        //this.groupOfCustomers = new GroupOfCustomers(**attributes of the class**);
    }
    public GroupOfCustomers getConstructedGroupOfCustomers() {
        return this.GroupOfCustomers;
    }
}ご覧のとおり、クラスにはプライベートメソッドを呼び出してジョブを完了するコンストラクターしかありませんが、一般的には良い方法ではありませんが、メソッドをパブリックにするのではなく、クラスのすべての機能をカプセル化することを好みますクライアントは次のように動作するはずです。
GroupOfCustomersImporter importer = new GroupOfCustomersImporter(filepath)
importer.createCSVReader();
read();
GroupOfCustomer group = constructGoupOfCustomerInstance();
これは、クライアントクラスに実装の詳細を煩わせる無駄なコード行をクライアント側のコードに入れたくないため、これが好きです。
それで、これは実際に悪い習慣ですか?はいの場合、どうすればそれを回避できますか?上記は単なる例にすぎないことに注意してください。同じ状況がもう少し複雑なもので起こっていると想像してください。