E D R , A S I H C RSS

Self Delegation

Self Delegation

μ•žμž₯에 λ‚˜μ˜¨ 두가지 μ§ˆλ¬Έμ„ μƒκΈ°ν•΄λ³΄μž. μœ„μž„ν•œ 객체의 주체성이 ν•„μš”ν•œκ°€? μœ„μž„ν•œ 객체의 μƒνƒœκ°€ ν•„μš”ν•œκ°€? 이 두가지에 yes라고 λŒ€λ‹΅ν•˜λ©΄ Simple Delegation을 μ“Έμˆ˜ μ—†λ‹€.
----
μœ„μž„λœ 객체가 μœ„μž„ν•˜λŠ” 객체에 μ ‘κ·Όν•˜λ €λ©΄ κ°€μž₯ μ‰¬μš΄ ν•œκ°€μ§€ 방법이 μžˆκΈ°λŠ” ν•˜λ‹€. λ°”λ‘œ μœ„μž„ν•˜λŠ” 객체의 μ°Έμ‘°λ₯Ό κ°€μ§€κ³  있으면 λœλ‹€. ν•˜μ§€λ§Œ λ³΅μž‘ν•΄μ§€κ³ , κΉ¨μ§ˆμˆ˜λ„ μžˆλ‹€.
----
μ—¬κΈ°μ„œ μ œμ‹œν•˜λŠ” 방법은, μœ„μž„ν•˜λŠ” 객체λ₯Ό 좔가적인 νŒŒλΌλ©”ν„°λ‘œ λ„˜κΈ°λŠ” 것이닀. forλΌλŠ” μ΄λ¦„μ˜ 좔가적인 νŒŒλΌλ©”ν„°λ‘œ μœ„μž„ν•˜λŠ” 객체λ₯Ό λ„˜κΈ°μž.
----
Self Delegation의 κ°€μž₯ λ›°μ–΄λ‚œ μ˜ˆμ œλŠ” Visual Smalltalk 3.0의 Dictionaryκ΅¬ν˜„μ΄λ‹€. DictionaryλŠ” 각각의 μƒνƒœμ— λŒ€ν•΄ μ΅œμ ν™”λœ HashTable을 μ—¬λŸ¬κ°œ κ°€μ§€κ³  μžˆλ‹€. μ΄λ•Œ, 자기 μžμ‹ (Dictionary)λ₯Ό λ„˜κ²¨μ£Όκ²Œ λœλ‹€.
~cpp 
class Dictionary
{
...
	void put(const T1& keyObject, const T2& valueObject) {
		hashTable.put(keyObject, valueObject, this); // 문법 μ•ˆλ§žλŠ”κ±° κ°™λ‹€. κ·Έλƒ₯ κ·ΈλŸ°κ°€ 보닀 ν•˜μž.
	}
};
HashTable은 Collection으둜 보낸 λ©”μ„Έμ§€κ°€ 뱉어낸 값을 기반으둜 해쉬값을 κ³„μ‚°ν•œλ‹€.
~cpp 
void HashTable::put(const T1& keyObject, const T2& valueObject, Dictionary* collection)
{
	hash = collection->hashOf(keyObject);
	...
}
이제 hashOfλ₯Ό 폴리λͺ¨ν”Όμ¦˜μœΌλ‘œ κ΅¬ν˜„ν•  수 μžˆλ‹€.
~cpp 
HashTable& Dictionary::hashOf(const T& object) {
	return object.hash();
}
HashTable& IdentityDictionary::hashOf(const T& object) {
	return object.basisHash();
}
----
μ–΄μ§Έ C++이 점점 λ―Έμ›Œμ§„λ‹€.
----
SBPPSummary
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:28:00
Processing time 0.0084 sec