摘要:
用多态替换条件 3中交通工具public class Car : Vehicle{ public int AmountOfFuelNeededToFillTank() { return 12; }}public class Airplane : Vehicle{ public int AmountOfFuelNeededToFillLeftFuelTank() { return 3; } public int AmountOfFuelNeededToFillRightFuelTank() { retur... 阅读全文
摘要:
封装字段public class Widget{ private object _internalWidgetState; public string _widgetModelNumber;}将成员变量封装在一个字段中public class Widget{ private object _internalWidgetState; public string ModelNumber {get; private set;}} 阅读全文
摘要:
重命名变量、字段、方法和类public double GetValue(int a,int b){ var answer=(a*a)*b*p; return answer;}同一方法,采用合适的名称命名变量:public double GetVolumeOfACylinder(int radius,int height){ var volumeofACylinder=(radius*radius)*height*Pi; return volumeofACylinder;} 阅读全文
摘要:
Try/Catch 块过多public Customer GetCustomer(string customerId){ try { var command = new SqlCommand(); var reader = command.ExecuteReader(); var customer = new Customer(); while(reader) { customer.customerId=customerId; customer.CustomerNam... 阅读全文
摘要:
析取方法public string PlaceOrderForWidgets(int quantity,string customerNumber){ var invoice=new Invoice { InvoiceNumber=Guid.NewGuid().ToString(), TotalPrice=PricePerWidget*quantity, Quantity=quantity }; var customer=_customerService.GetCustomer(customerNumber); invoice.CustomerN... 阅读全文
摘要:
析取类或接口 将一个类分割为更小、针对性更强的类;从中析取出一系列更精细的接口public class InvoiceService{ public string CreateInvoice(Invoice invoice){...} public string ProcessPayment(Invoice invoice,double amount){...} public double GetAmountOwed(Invoice invoice){...} public double GetTotalAmountInvoiceLastFY(Customer cus... 阅读全文
摘要:
MSDN, 我告诉你http://msdn.itellyou.cn/挺给力的...windows系列的基本都能找到... 阅读全文