user interface - How to separate business logic from the UI -


I am creating a calculator application, and I am trying to isolate the code by separating business logic from the UI Allow for better unit tests

I have created a calculator UI class what happens when a user clicks on different buttons in the application.

I have created a calculator class that makes math, and does some recognition on the results of calculations based on the needs of users. Calculator UI calculator creates an example of class and the calculator calls the function in class so that users can click. In my question, calculator class, how can I write code that clears the text box and displays a message box to make the user aware of the invalid result?

I'm new to programming, and according to one of my colleagues (a senior level programmer), the best practice is to keep UI away from business logic and database.

The error that I am receiving is not present in 'txtDisplay' and 'resultValue' in the current context ... Besides, how do I use the bool variable?

Here is my code in the calculator class:

  class calculator {public double plus (double value 1, double value 2) {double result = 0; Result = value1 + value2; Return result; } Public double subtraction (double value 1, double value 2) {double result = 0; Result = value1 - value2; Return result; } Public double multiplication (double value 1, double value 2) {double result = 0; Result = value1 * value2; Return result; } Public Double Division (double value 1, double value 2) {double result = 0; Result = value1 / value2; Return result; } Public bool calculation validation (double result) {bool isValid; Bull is flasher; // determine if the initial result is within the specified range ((result & lt; -4000000000) || (Results> 40,00000000)) {Messagebox.Show ("The result is too big or small"); TxtDisplay.text = "0"; Result value = 0; Return; } // If the result is required then string test = result Toasting (); If (test.Contains (".") {Test = (Mathematics round (Double Percy (test), 10 - test.Split ('.') [0]. Cunt ())). ToString (); } Else if (test.Length & gt; 10) {test = (Math.Round (double Percy (test), 10) ostring ()); } TxtDisplay.Text = test; You can increase the exception in the calculator class, and then hold it. Reset your UI and show the message. Showing the message and displaying 0 has the UI argument. This is a good way to be different in this case  

In this way, your UI is dependent on the business logic (calculator class), but the calculator class has no information about the UI, its purpose should be All dependencies should point inside to your domain objects.

To separate more complex domains, I see in the mask, command, and observant patterns.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -