public interface ICommand
{
public void Process();
}
public class PatternA: ICommand
{
Transform trs;
public PatternA(Transform _trs)
{
trs = _trs
}
public void Process()
{
// 대충 왼쪽으로 이동
}
}
public class PatternB: ICommand
{
Transform trs;
public PatternB(Transform _trs)
{
trs = _trs
}
public void Process()
{
// 대충 오른쪽으로 이동
}
}
public Jako : Monobehaviour
{
public ICommand pattern;
void FixedUpdate()
{
if(pattern != null) pattern.Process();
}
}
Jako JakoA;
Jako JakoB;
JakoA.pattern = new PatternA(JakoA.transform);
JakoB.pattern = new PatternB(JakoB.transform);
이럴꺼면 상속이 좋은가?
상속쓰면 변수랑 생성자 상속받으면 되니까 4줄 이득이네
겁쟁이면 둘다써라 ㅋ
인터페이스는 무조건 내용 구현하라고 정의할때 또는 여러곳에서 여러 타입으로 접근할때 쓰면 좋은거같음