Food Programming growth notes (four business packages)

Source: Internet
Author: User

(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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.