는 원래 코드는 다음과 같다 : 여기서 제네릭을 사용하는 것이 합리적입니까?
public interface IApplicableSystem
{
string Name { get; }
void Apply ();
}
public class Effector
{
public string Name { get; set; }
}
public class EffectSystem : IApplicableSystem
{
Effector Internal { get; set; }
public string Name
{
get { return this.Internal.Name; }
}
RelayCommand applyCommand;
public ICommand ApplyCommand
{
get
{
if (applyCommand == null)
applyCommand = new RelayCommand (p => this.Apply ());
return applyCommand;
}
}
public void Apply ()
{
}
public EffectSystem (Effector value)
{
this.Internal = value;
}
}
그래서
IApplicableSystem
을 구현하는 다양한 종류가 있습니다, 그들의
Name
재산,
Apply
방법 및 클래스 내에서 사용되는 민간
Internal
재산의 유형입니다 다른 모든 곳.
나는이
이 합리적이다? :처럼 그들을 만들기 위해 일반적인 사용해야합니까? 주로 IApplicableSystem
을 구현하는 다른 유형의 코드를 줄입니다.
public abstract class GenericSystem<T> : IApplicableSystem
{
protected T Internal { get; set; }
public virtual string Name
{
get { return String.Empty; }
}
RelayCommand applyCommand;
public ICommand ApplyCommand
{
get
{
if (applyCommand == null)
applyCommand = new RelayCommand (p => this.Apply ());
return applyCommand;
}
}
public virtual void Apply ()
{
}
public GenericSystem (T value)
{
this.Internal = value;
}
}
public class EffectSystemGeneric : GenericSystem<Effector>
{
public override string Name
{
get { return GetUniqueName (base.Internal.Name); }
}
public override void Apply ()
{
Console.WriteLine ("Do something");
}
}
감사합니다. –