Challenge: MVP Pattern
In this challenge, you have to implement the MVP pattern to solve the given problem.
Problem statement
In this challenge, you need to implement sending and displaying a sent email using the MVP pattern. You have already been given the dummy code for the classes you need to implement.
In the Model class should contain the following:
-
The properties: sender’s name, receiver’s name, and the email title.
-
The get and set functions to access and set the values of each property.
In the View class, you need to do the following:
- Define the
sendEmailfunction to send an email.
In the Presenter class, you need to do the following:
-
Define the
setModelfunction that sets the model. -
Define the
getViewfunction to return the view. -
Define the
sendEmailfunction that sets the properties of the email and displays the email information.
Input
The sendEmail function is called
Output
The information of the email is displayed
Sample input
var model = new Model()
var view = new View()
var presenter = new Presenter(view)
presenter.setModel(model)
view.registerWith(presenter)
presenter.getView().sendEmail("Rachel", "Joey", "Rent Discussion")
presenter.getView().sendEmail("Monica", "Phoebe", "Smelly Cat Draft")
Sample output
"Email From: Joey To: Rachel Title: Rent Discussion"
"Email From: Phoebe To: Monica Title: Smelly Cat Draft"
Challenge #
Take a close look and design a step-by-step solution before jumping on to the implementation. This problem is designed for your practice, so try to solve it on your own first. If you get stuck, you can always refer to the solution provided. Good Luck!
Let’s discuss the solution in the next lesson.