You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
healthValue는 캐릭터의 체력치를 반환하는 함수로 파생 클래스는 이 함수를 재정의 할 수 있다.
순수 가상 함수로 선언되지 않은 것으로 보아 체력치를 계산하는 기본 알고리즘이 제공된다는 사실을 알 수 있다.
너무나도 당연한 설계!
다른방법은 없을 것 인가?
비가상 인터페이스 관용구를 통한 템플릿 메서드 패턴
가상 함수는 반드시 private 멤버로 두어야 한다고 주장하는 사람들이 제안하는 설계이다.(가상 함수 은폐론)
classGameCharacter{
public:inthealthValue() const
{
// 사전 동작int retval = doHealthValue(); // 실제 동작// 사후 동작return retVal;
}
private:virtualintdoHealthValue() const// 파생 클래스는 이 함수를 재정의 할 수 있다.
{
// 캐릭터 체력 계산 로직
}
}