0

Possible Duplicate:
Understanding Model-View-Controller

If I was for example building a calculator application how would I go about splitting functionality so as to follow the MVC design pattern?

Am I right in thinking the following:

View -Contains all buttons and textfields

Model -Contains all operations (e.g. add subtract etc)

Controller Contains all the functions for handling operations and updating display based on user input Essentially the model acts as a library to the controller in this instance..

If anyone can explain better please do so, but I am struggling to fully grasp the concept..

Community
  • 1
  • 1
user559142
  • 12,279
  • 49
  • 116
  • 179
  • Is this related to iPhone/ObjectiveC/Xcode/Xcode4 in any way? I think this would better go on programmers.stackexchange.com... – jv42 Jun 09 '11 at 15:28
  • The thing is : is good idea to use MVC for a calculator? – llazzaro Jun 09 '11 at 15:28
  • See also: http://stackoverflow.com/questions/129921/what-is-mvc-model-view-controller and http://stackoverflow.com/search?q=model+view+controller – Kev Jun 29 '11 at 00:37

1 Answers1

0

While you do not technically need to separate an application into MVC, it is more logical to do so. What you have written is essentially correct. The View is your interface to the user. It can be buttons on an iphone or a console on a computer screen. It is independent of the actual function of the application, which is generally in your model, although real basic apps might put some or all functionality in their view controller. A calculator is complicated enough to warrant an independent model class, as you have suggested. The controller is the bridge between the view and the model. So if someone presses a plus button in the view, the controller takes this and sends it to the model.

johnbakers
  • 24,158
  • 24
  • 130
  • 258
  • hi thanks for the reply. Does it "send" it to the model or does the controller use the model to perform the plus? I mean where should the actual processing occur? – user559142 Jun 09 '11 at 16:33
  • the model would theoretically hold the data and have the methods for the calculator's operations – johnbakers Jun 24 '11 at 00:56