3

I have a new-employee form.

When the "Save" button is pressed, a SavingRequested event is raised. The Presenter gets an Employee object from the View and passes it to the Model for further processing.

Should the Employee object created by the View be passed to the Presenter via the event arguments:

public event EventHandler<SavingRequestedEventArgs> SavingRequested;
private void OnSavingRequested()
{
 SavingRequested?.Invoke(this, new SavingRequestedEventArgs(employeeObject);
}

or should the View have an Employee property that the Presenter will access?

asked Nov 21, 2017 at 12:19

1 Answer 1

3

The event data approach will keep you a little closer to the observer pattern, but you should probably not create (or instantiate) Employee from within the view. It's almost like you're directly coupling the view with the model as explained here.

Find a bare data structure that supports properties, and pass that to the Presenter (controller?) instead via a regular object

answered Nov 21, 2017 at 15:50
3
  • Thanks. Why shouldn't the View get access to the domain objects? Commented Nov 21, 2017 at 15:53
  • There's a lot of articles on the subject, but generally you'll end up with a view layer that's easier to maintain, test and reuse. Commented Nov 21, 2017 at 16:05
  • Thanks. I asked a new question about this topic so you could elaborate if you wish: softwareengineering.stackexchange.com/questions/361064/… Commented Nov 21, 2017 at 16:06

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.