2014-06-19 2 views
1

도메인 객체가 TrainingPlan 인 경우를 가정 해 봅시다. TrainingPlan 오브젝트과 같이, 다른 도메인의 오브젝트들로 구성되어webforms 및 .ascx 컨트롤이있는 MVP 패턴

DelegateInfo.ascx

Test.ascx (단일 테스트 도메인 오브젝트의 정보를 표시)

: I 3 개 .ascx 제어 작성한

public class TrainingPlan 
{ 
    public DelegateInfo DelegateInfo { get; set; } // name, assessor, course name 
    public IEnumerable<Test> Tests { get; set; }  // tests delegate undertook 
    public IEnumerable<Comment> Comments { get; set; } // comments by assessor 
} 

Comment.ascx (단일 설명 도메인 개체에 대한 정보 표시)

ascx 컨트롤은 전망 선언 :

public class TestPresenter: ITestPresenter 
{ 
    ITestView _view; 
    ITest _domainObj; 

    // Test object in domain implements ITest 
    public TestPresenter(ITestView view, ITest domainObj) 
    { 
     // removed: checks for null etc 

     _view = view; 
     _domainObj = domainObj; 
    } 

    // etc etc 

} 

도메인 객체에 데이터를 제공 할 것입니다 개체입니다 :

public partial class TestControl : System.Web.UI.UserControl, ITestView 
{  
    // ... implementation of view interface here. Simple properties 
} 

내 발표자보기 및 도메인 객체 사이의 중간 사람입니다 발표자를 통해보기에서 업데이트 된 입력을받습니다. 그것은 (따라서 이유는이 도메인 층 인치) 데이터의 유효성을 검사

질문 :

  1. MVP에 올바른 도메인 오브젝트에 직접 말하기 발표자인가? 내가 봤 거든 샘플 발표자에서 모델에 직접 액세스하지만 inbuilt 비즈니스 로직과 도메인 개체는 어떨까요?

  2. 아래의 논리는 MVP 패턴과 일치합니까?

// Page_Load of PageThatDisplaysTrainingPlan.aspx: 
// load full trainingPlan object 
var trainingPlan = repository.LoadTrainingPlan(idOfPlan); 
// populate test controls 
foreach(var test in trainingPlan.Tests) 
{ 
    // create test.acx control on this line. Code not added as it is unnecessary 
    var pres = new TestPresenter(controlJustAdded, test);     
    // ... add pres to some collection somewhere 
} 

어떤 조언 또는 코드 오신 것을 환영합니다 샘플에 대한 링크.

답변

0

예, MVP 패턴에서 발표자가 모델과 직접 작업하는 것은 절대적으로 정상입니다. 그리고 inbuilt 비즈니스 로직을 가진 도메인 객체도 정상입니다.

두 번째 질문 - TestPresenter는 데이터베이스에서 trainingPlan 개체를로드하고 새로 만든 컨트롤로 UI를 업데이트해야합니다. Page_Load 이벤트 핸들러에이 코드를 넣은 것처럼 보입니다. 이것은 좋은 생각이 아니라고 생각합니다. SmartUI 반 패턴처럼 보입니다.

관련 문제