I've been programming in Java for about 6 months, and I thought a good and challenging test of my skills would be to build a GUI calculator. I have very recently heard about this MVC idea, and I thought (perhaps foolishly) that it would be a good fit for this pet project. But I'm running into trouble during the design, and I'm not sure how to proceed.
So I have a
Controller class. The
Model is responsible for all the actual calculation; the
View draws the calculator and the display; and the
- passes button clicks to
- gets the display value from
Modeland passes it to
Ah, but the buttons! I want to have a
Button interface, where a
Button instance has:
- (unique) ID number;
Then I would have my
Controller build up a collection of
Buttons, and [not sure how to do this] let both the
Model use those buttons:
View for drawing,
Model for calculating. Thus I have the revised list for
- pass clicks to
- get display value from
Modeland pass it to
But the more I work on this, the more I can't figure out how this would all come together. So I have several related questions:
Viewreally be responsible for sorting out which
Buttona click corresponds to? Should that be done in
- Should I have more than one type of
Button? Is it necessary to distinguish between numbers, operators, equals, etc.? Which of the three MVC classes needs to know the difference?
- Is MVC even the right way to go here? Is there a more fundamental, accepted way of building an OOP calculator?
- If MVC is indeed appropriate, what am I doing wrong? I think adding in the
Buttons has really thrown me off.