ドメインモデルのアイテムのリストにMVPを実装しています。
私の質問は、一般的に、具体的なビューとプレゼンターの型パラメーターの重複をどのように(または私は)取り除くことができるかということです。
私は限界に達したと思う傾向があり、重複に耐えるか、クラスを再設計する必要があります。もう1つの選択肢は、明らかな何かが欠けていることです。とにかく、それが私がここで尋ねている理由です。
具体的には、次の場合:
interface IA<T2, T3> { }
class C<T1, T2, T3> where T1 : IA<T2, T3>
タイプパラメータT2とT3を推測するコンパイルを取得して、次のようにすることはできますか?
interface IB : IA<int, string>
class D : C<IB> { } // can't do this
これはコンパイルされます。重複するパラメータはとNote, string
ですAttachment, string
。
// Abstract View
public interface IView<TItem, TKey>
{
void Fill(TItem[] items);
event SelectEvent<TKey> SelectionChanged;
event MessageEvent Add;
}
// Event Delegates
public delegate void SelectEvent<TKey>(TKey selectedValue);
public delegate bool MessageEvent();
// Model Entities
public class Note { }
public class Attachment { }
// Abstract Presenter
public abstract class Presenter<TView, TItem, TKey> where TView : IView<TItem, TKey>
{
protected TKey SelectedValue { get; private set; }
protected TView View { get; set; }
public Presenter(TView view)
{
View = (TView)view;
View.SelectionChanged += OnSelectionChangedInternal;
View.Add += OnAdd;
}
void OnSelectionChangedInternal(TKey selectedValue) {
this.SelectedValue = selectedValue;
OnSelectionChanged(selectedValue);
}
protected abstract void OnSelectionChanged(TKey selectedVaule);
protected abstract bool OnAdd();
}
// Concrete Views
public interface INotes : IView<Note, string> { }
public interface IAttachments : IView<Attachment, string> { }
// Concrete Presenters
public class NotesPresenter : Presenter<INotes, Note, string> {
public NotesPresenter(INotes view) : base(view) { }
protected override void OnSelectionChanged(string publisherName) { }
protected override bool OnAdd() { return false; }
}
public class AttachmentsPresenter : Presenter<IAttachments, Attachment, string> {
public AttachmentsPresenter(IAttachments view) : base(view) { }
protected override void OnSelectionChanged(string publisherName) { }
protected override bool OnAdd() { return false; }
}