The MVC design pattern, albeit a very simplified one, can be applied directly to the Currency Converter application. Currency Converter is a simple application that converts US dollars to another currency based on an exchange rate entered by the user. Though it’s a very simple application, it can still be used to convey the fundamental elements of Cocoa application development using the MVC design pattern.
The underlying functionality, which is the model, converts US dollars to another currency based on an exchange rate. For this, there is a single function, convertCurrency, which multiplies the amount in US dollars by the exchange rate to get the amount in the other currency.
All graphical applications have a user interface that the user interacts with. This is the view. Here, the user inputs the exchange rate in one text field, the amount of dollars to convert in the next text field, and clicks the convert button, or presses Return, to perform the calculation. The final result appears in the last text box, which is the amount of the other currency.
The view needs to send the data the user entered to the model somehow. This is done by creating a controller, which gathers the exchange rate and amount in US dollars from the view, sends the values to the model, and writes the result into the view.
Last updated: 2007-10-31