関数とOOP(3)


オブジェクト向けプログラミング
1.抽象化
  • 技術
  • 分類
  • モデリング
  • パケット(集約)
  • 2.オブジェクト向け言語とプログラム
  • 代替性:インプリメンテーションは抽象クラスおよびインタフェース
  • を代替できる必要がある.
  • 内同質性
  • 出生身分
  • を維持する
  • 親、抽象クラス内のインプリメンテーションメソッド呼び出しの場合は、子メソッドとインプリメンテーションメソッドを実行する必要があります.
  • 親クライザータイプ生成子
  • 親インスタンス
  • =真の代替
  • サブアイテムインスタンス
  • =真内同質性
  • メソッドは、すべて上書きサブメソッドで
  • 実行される.
    3.対象分析
  • 抽象化技術を用いる対象(事物)を分類し、対象候補群
  • を設定する.
  • は独立オブジェクト
  • に分類する.
  • 単一権限と責任設計
  • 依存一方向簡略化設計
  • 4. HTML parser
    // 재귀 코드 by me
    const parser = (input, curParent, prevParent) => {
      input = input.trim();
      if(input.length < 1) return curParent
      if(input[0] === '<'){
        const idx = input.indexOf('>');
        console.log(input)
        if(input[idx -1] === '/'){ 
          curParent.text = input.split('/')[0]
          parser(input.split('>')[1], curParent, prevParent)
        }
        else if(input[input.indexOf('<')+1] === '/'){
            curParent.child.push({ name : input.substring(1, idx-1), child :[] });
            parser(input.substring(idx+1). curParent, prevParent);
        }
        else{
          const newParent = { name : input.substring(1,idx), child : [] };
          curParent.child.push(newParent);
          parser(input.substring(idx+1), newParent, curParent);
        }
      }
      return curParent
    }
    
    let res = parser(inp, { name : 'Root', child : [] },{ name : 'Root', child : [] })
    console.log(res)
    //reference code
    let inp = `<div>
            a
            <a>b</a>
        </div>`;
    
    
    const parser = input => {
      input = input.trim();
      const result = { name : 'ROOT', type : 'node', children : [] }; 
      let i = 0, j = input.length;
      let curr = {  tag: result , parent : 'body'} ; 
    
      while(i < j){
        const cursor = i ; 
        if(input[cursor] === '<'){
          let name, isClose;
          const idx = input.indexOf('>', cursor);
          name = input[idx - 1]=== '/'  
            ? input.subString(cursor + 1, idx-1)
            : input.subString(cursor )  
        }
        else{
          const idx = input.indexOf('<', cursor);
          curr.text = input.subString(cursor, idx);
          i = idx;      
        }
      }
    }
    NOTE
    JavaScriptは通常、100回の再帰呼び出しを制限し、スタックオーバーフローエラーを放出します.

    関数とOOP-3