E D R , A S I H C RSS

Collection Parameter

Collecting Parameter

λͺ‡λͺ‡ λ©”μ†Œλ“œμ˜ 결과와 ν˜‘λ ₯ν•˜λŠ” μ½œλ ‰μ…˜μ„ μ–΄λ–»κ²Œ 리턴할것인가?(?)

ComposedMethod의 단점쀑 ν•˜λ‚˜λŠ”, μž‘μ€ λ©”μ†Œλ“œλ“€ μ‚¬μ΄μ˜ μ—°κ΄€λ•Œλ¬Έμ΄λ‹€. 큰 λ©”μ†Œλ“œ ν•˜λ‚˜μ—μ„œ κ³΅μœ λ˜μ—ˆλ˜ μž„μ‹œ λ³€μˆ˜λ“€μ΄, μ΄μ œλŠ” μž‘μ€ λ©”μ†Œλ“œλ“€ 사이에 κ³΅μœ λœλ‹€. κ°€μž₯ ν•΄κ²°ν•˜κΈ° μ‰¬μš΄ 방법은 ComposedMethodλΌ μ—†μ• κ³  λ‹€μ‹œ ν•˜λ‚˜μ˜ 큰 λ©”μ†Œλ“œμ— λ‹€ λ•Œλ €λ„£λŠ” κ²ƒμ΄μ§€λ§Œ, μ•ˆμ’‹λ‹€. 또 λ‹€λ₯Έ ν•΄κ²°μ±…μœΌλ‘œλŠ” 이 μž‘μ€ λ©”μ†Œλ“œλ“€ μ‚¬μ΄μ—μ„œ κ³΅μœ λ˜λŠ” μž„μ‹œ λ³€μˆ˜λΌ λ©€λ²„λ³€μˆ˜μ— λ„£λŠ” 것이닀. 이것은 객체의 생λͺ…κΈ°κ°„ λ™μ•ˆ μœ νš¨ν•œκ²Œ μ•„λ‹ˆλΌ, μ € λ©”μ†Œλ“œλ“€μ΄ μ‹€ν–‰λ λ•Œμ—λ§Œ μœ νš¨ν•˜λ‹€. μ—­μ‹œ μ•ˆμ’‹λ‹€.

우리의 해결책은, λ©”μ†Œλ“œλ“€λ§ˆλ‹€ ν•„μš”ν•œ νŒŒλΌλ©”ν„°λ“€μ„ λ„˜κ²¨μ£ΌλŠ” 것이닀. 이것도 μ€ λ§μ„μ—¬μ§€λŠ” 방법이긴 ν•˜λ‚˜, λ‹€λ₯Έ 것듀보단 λ‚«λ‹€.

μ–΄λ–€ μ½œλ ‰μ…˜μ˜ κΈ°ν˜Όλ‚¨κ³Ό λΈν˜Όλ…€λΌ μΆ”μΆœν•΄λ‚΄λŠ” μ½”λ“œλΌ λ³΄μž.
~cpp 
vector<People> marriedMenAndUnmarriedWomen()
{
	vector<People> result;
	for(vector<People>::iterator it = result.begin() ; it != result.end() ; ++it)
	{
		if(it->isMarried() and it->isMan())
			result.add(*it);
	}
	for(vector<People>::iterator it = result.begin() ; it != result.end() ; ++it)
	{
		if(it->isUnmarried() and it->isWoman())
			result.add(*it);
	}
	return result;
}
ComposedMethodλΌ μ μš©ν•΄λ³΄μž.
~cpp 
vector<People> marriedMen()
{
	vector<People> result;
	for(vector<People>::iterator it = result.begin() ; it != result.end() ; ++it)
	{
		if(it->isMarried() and it->isMan())
			result.add(*it);
	}
	return result;
}
vector<People> unmarriedMen()
{
	vector<People> result;
	for(vector<People>::iterator it = result.begin() ; it != result.end() ; ++it)
	{
		if(it->isUnmarried() and it->isWoman())
			result.add(*it);
	}
	return result;
}
vector<People> marriedMenAndUnmarriedWomen()
{
	return marriedMen() + unmarriedMen();	// 될지 μ•ˆλ μ§€λŠ” λͺ¨λ₯΄κ² μ§€λ§Œ λœλ‹€κ³  κ°€μ •ν•˜μž.
}

μ½œλ ‰μ…˜μ„ λ¦¬ν„΄ν•˜μ§€ 말고 각각을 μ½œλ ‰μ…˜μ— λ”ν•˜μž.
~cpp 
vector<People> marriedMenAndUnmarriedWomen()
{
	vector<People> result;
	addMarriedMenTo(result);
	addUnmarriedWomenTo(result);
	return result;
}

void addMarriedMen(vector<People>& aCollection)
{
	for(vector<People>::iterator it = result.begin() ; it != result.end() ; ++it)
	{
		if(it->isMarried() and it->isMan())
			aCollection.add(*it);
	}
}
void addUnmarriedMen(vector<People>& aCollection)
{
	for(vector<People>::iterator it = result.begin() ; it != result.end() ; ++it)
	{
		if(it->isUnmarried() and it->isWoman())
			aCollection.add(*it);
	}
}

즉, 두 λ©”μ†Œλ“œμ˜ κ²°κ³ΌλΌ λͺ¨μœΌλŠ” 경우인데, 그리 ν”ν•œ κ²½μš°λŠ” μ•„λ‹ˆμ˜€λ˜κ±Έλ‘œ κΈ°μ–΅. 약간은 λ‹€λ₯΄κΈ΄ ν•˜μ§€λ§Œ λ‚˜μ˜ 경우 CollectionParameter 의 μ„±κ²©μœΌλ‘œ ν•„μš”ν•œ κ²½μš°κ°€ read/write λ“± I/O κ°€ λ‚΄λΆ€μ μœΌλ‘œ ν•„μš”ν• λ•Œ λ˜λŠ” Serialization λ“±μ˜ 일이 ν•„μš”ν• λ•Œ. κ·Έ 경우 I/O 뢀뢄은 Stream 클래슀둜 λ§Œλ“€κ³ (C++ 의 Stream 을 μ“°λ˜μ§€ λ˜λŠ” 직접 Stream 클래슀 λ§Œλ“€μ–΄ μ“°λ˜μ§€) parameter 둜 λ„˜κ²¨μ£Όκ³  κ·Έ νŒŒλΌλ©”ν„°μ˜ λ©”μ†Œλ“œλΌ μ‚¬μš©ν•˜λŠ” ν˜•νƒœμ˜€μŒ. --1002


Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:22:57
Processing time 0.0293 sec