"트레이트"의 두 판 사이의 차이

 
(사용자 2명의 중간 판 5개는 보이지 않습니다)
6번째 줄: 6번째 줄:
==예시: PHP==
==예시: PHP==
* 템플릿  
* 템플릿  
<source lang="php">
<syntaxhighlight lang="php">
trait TSingleton {
trait TSingleton {
     private static $_instance = null;
     private static $_instance = null;
22번째 줄: 22번째 줄:
     use TSingleton;
     use TSingleton;
}
}
</source>
</syntaxhighlight>
* [[다중 상속]]
* [[다중 상속]]
<source lang="php">
<syntaxhighlight lang="php">
trait TBounding {
trait TBounding {
     public $x, $y, $width, $height;
     public $x, $y, $width, $height;
44번째 줄: 44번째 줄:
     }
     }
}
}
</source>
</syntaxhighlight>


==같이 보기==
==같이 보기==
{{z컬럼3|
* [[위임 (OOP)]]
* [[UFCS]]
* [[믹스인]]
* [[PHP trait]]
* [[인터페이스]]
* [[인터페이스]]
* [[확장 메소드]]
* [[확장 메소드]]
* [[UFCS]]
}}
* [[PHP trait]]


==참고 자료==
==참고==
* https://en.wikipedia.org/wiki/Trait_(computer_programming)
* {{영어위키백과|Trait (computer programming)}}


[[분류: 객체지향]]
[[분류: 객체지향]]
[[분류: 프로그래밍]]
[[분류: 프로그래밍]]

2022년 3월 31일 (목) 12:29 기준 최신판

1 개요[ | ]

trait
트레이트
  • 클래스 기능을 확장하기 위해 사용하는 메소드들의 집합

2 예시: PHP[ | ]

  • 템플릿
trait TSingleton {
    private static $_instance = null;
    public static function getInstance() {
        if (null === self::$_instance) {
            self::$_instance = new self();
        }
        return self::$_instance;
    }
}
class FrontController {
    use TSingleton;
}
class WebSite extends SomeClass {
    use TSingleton;
}
trait TBounding {
    public $x, $y, $width, $height;
}
trait TMoveable {
    public function moveTo($x, $y) {
        // ...
    }
}
trait TResizeable {
    public function resize($newWidth, $newHeight) {
        // ...
    }
}
class Rectangle {
    use TBounding, TMoveable, TResizeable;
    public function fillColor($color) {
        // ...
    }
}

3 같이 보기[ | ]

4 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}