(Part 1)
Dish: "What do you mean is a classification? Oh, right. Separate computing and display ."
Laruence: "To be accurate, it is to separate the business logic from the interface logic and reduce the coupling between them. It is easy to maintain or expand only when points are left ."
Dish: "Let me try it ."
Class Program
{
Static void Main (string [] args)
{
Try
{
Console. Write ("Enter the number :");
String strNumberA = Console. ReadLine ();
Console. Write ("select the operator number (+ ,-,*,/):");
String strOperate = Console. ReadLine ();
Console. Write ("Enter the number B :");
String strNumberB = Console. ReadLine ();
String strResult = "";
StrResult = Convert. ToString (Operation. GetResult (Convert. ToDouble (strNumberA), Convert. ToDouble (strNumberB), strOperate ));
Console. WriteLine ("Result:" + strResult );
Console. ReadLine ();
}
Catch (Exception ex)
{
Console. WriteLine ("your input is incorrect:" + ex. Message );
}
}
}
Public class Operation
{
Public static double GetResult (double numberA, double numberB, string operate)
{
Double result = 0d;
Switch (operate)
{
Case "+ ":
Result = numberA + numberB;
Break;
Case "-":
Result = numberA-numberB;
Break;
Case "*":
Result = numberA * numberB;
Break;
Case "/":
Result = numberA/numberB;
Break;
}
Return result;
}
}
Side dish: "I have written it. You can check it out !"
Laruence: "ha, laruence, you can teach me, :). well written. This completely separates the business from the interface ."
"You are a bird ." "If you want me to write a calculator for a Windows application, I can reuse the Operation class ."
Laruence: "It is not just a Windows program. For a Web program, you can use it for computation, PDA, mobile phone, or other software that requires a mobile system ."
Side dish: "Ha, this is not the case for Object-Oriented. I am not afraid to write similar code ."
Laruence: "Don't worry, that's all. It's really not totally object-oriented. You only use one of the three features of object-oriented. Are there two useless features ?"
Dish: "isn't the three main characteristics of object-oriented encapsulation, inheritance, and polymorphism? Here I should use encapsulation. Isn't that enough ?............ I can't see how such a small program uses inheritance. As for polymorphism, I have never been quite familiar with its advantages and how to use it ."
Laruence: "It's time to learn something. You have to think about it. I'm going to" Warcraft "and talk about it later ."
(To be continued)