コード匂い94 -あまりに多くの輸入


あなたのクラスがあまりにも多くの他のものに依存するならば、それは結合されて、壊れます.長い輸入リストは良い指標です.

TL;DR: Don't import too much.



問題
  • カップリング
  • 一責任原則違反
  • 低粘着力

  • 解決策
  • クラスを破る
  • 中間の偶然の実施を隠してください

  • サンプルコード

    間違い
    import java.util.LinkedList;
    import java.persistence;
    import java.util.ConcurrentModificationException;
    import java.util.Iterator;
    import java.util.LinkedList;
    import java.util.List;
    import java.util.ListIterator;
    import java.util.NoSuchElementException 
    import java.util.Queue;
    import org.fermi.common.util.ClassUtil;
    import org.fermi.Data;
    //We rely on too many libraries
    
    public class Demo {
       public static void main(String[] args) {
    
       }
    }
    


    
    import org.fermi.domainModel;
    import org.fermi.workflow;
    
    //We rely on few libraries
    //and we hide their implementation
    //So maybe transitive imports are the same
    //but we don't break encapsulation
    
    public class Demo {
       public static void main(String[] args) {
    
       }
    }
    

    検出
    我々は、我々のプリンターに警告閾値をセットすることができます.

    タグ
  • カップリング
  • 波及効果

  • 結論
    リプル効果を最小にするために解決策を構築する際に依存性について考える必要がある.

    関係



    詳しい情報
  • Namespaces on Wikipedia

  • クレジット
    写真でZdeněk Macháček on Unsplash

    デイヴィッドベロン🌊 🗡
    ベロンダビド

    あまりにも多くのことをしているクラスのインジケータ-そう、それはSRPに対して-インポートされた名前空間の数です.あまりにも多くの参照された名前空間があるならば、それはあなたのクラスがすぐにあまりに多くのことをしていることを意味します.少し、より良い!
    午後18時02分- 2021年10月11日

    Fools ignore complexity. Pragmatists suffer it. Some can avoid it. Geniuses remove it.


    アランペリス


    この記事はCodesmellシリーズの一部です.