コード嗅覚95 -早熟な分類


我々は一般化している.十分なコンクリートを見るまでは抽象化を起こすべきではない.

TL;DR: Don't guess what the future will bring you.



文脈
アリストテレス分類は計算機科学の大きな問題である.
我々は、十分な知識と文脈を集める前に、分類して、名前をつける傾向があります.

問題
  • 未来学
  • 不良設計

  • 解決策
  • 具体的に待つ
  • リファクタ

  • サンプルコード

    間違い
    class Rectangle 
     { 
           int length; 
           int breadth; 
    
           int area() 
           {
             return length * breadth;
           } 
     } 
    //We are creating a premature abstraction 
    //And misusing is-a relation since a Square "is a" Rectangle
    
    class Square extends Rectangle
     { 
           int length;  
    
           int area() 
           {  
             return length * length; 
           } 
     } 
    


    class Rectangle 
     { 
           int length; 
           int breadth; 
    
           int area() 
           {
             return length * breadth;
           } 
     }  
    
    class Square 
    { 
           int length;  
    
           int area() 
           {  
             return length * length; 
           } 
     } 
    //Square might-be a Rectangle
    //But it does not follow behaves-like relation so we won't go ahead
    //and create a strong relation between them
    //Maybe they are shapes. We don't have enough examples and protocol yet
    //We will not guess until further knowledge
    
    

    検出
    つのサブクラスを持つ抽象クラスは、早期分類の指標である

    タグ
  • 不良設計
  • 分類

  • 結論
    クラスで作業するとき、我々は彼らが現れるとすぐに、抽象化を命名します.
    私たちのルールは行動の後に選ぶことです.
    具体的なサブクラスに名前を付けるまでは、抽象化の名前をつけてはいけません.

    関係



    詳しい情報


  • クレジット
    写真でFaye Cornish on Unsplash

    Let us change our traditional attitude to the construction of programs: Instead of imagining that our main task is to instruct a computer what to do, let us concentrate rather on explaining to human beings what we want a computer to do.


    ドナルド・E


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