Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
Hi Friends,

I need to implement basic Calculator by applying Design Patterns. I tried With this code. that is working fine.


Can you please suggest, which design pattern is suitable for my Calculator Program and how to choose a design pattern for any program.
Posted
Updated 8-Jan-18 13:09pm
Comments
Richard MacCutchan 3-Feb-14 9:10am    
The best design pattern is the one that solves your problem. Unfortunately you have not explained what your problem is.
Naga Sindhura 3-Feb-14 9:27am    
Hi Richard,
You are Correct.
Actually my problem is, implement a basic Calculator program using design patterns. i am new to design patterns. i don't know how to proceed.
I implemented code to develop the Calculator with the help of this link( http://code.msdn.microsoft.com/windowsdesktop/Simple-Calculator-54ec8e4a ).
Please suggest how to proceed.

If you have already implemented your calculator program, then the choice of design pattern has already been made: that is something that is considered at the beginning of a project, not at the end, because changing it now would almost certainly mean scrapping all your existing code.
 
Share this answer
 
The patterns you use depend entirely on the problem you are solving. As we don't know exactly what your requirements are, we cannot give specific details. Suppose that your calculator has to support Undo/Redo functionality - well, this could be accomplished using a Memento based pattern. How about if the calculation is displaying a running total based on the user typing? Well, you could use an Observer pattern here. Possibly you are looking for a Command pattern, with the calculation buttons acting as command triggers.

There is a common misconception that you should design systems for patterns - invariably this is a trap fallen into by people who have fallen in love with patterns without considering what problems they are actually trying to solve. Break down your problem first - then look at what fits. Frequently, you will find that your applications will end up using a great many patterns, so looking for a one-size-fits-all pattern is futile.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900