随笔分类 -  面向对象

重构的步骤
摘要:1. 找到壞味道:透過靜態程式碼分析等工具,找到需要重構的部份。2. 確認人不是我殺的:確定現行程式碼可以正常運作,我們目標只是在重構,不是在 bug fix 或需求異動。3. 錄影存證:針對可正常運作的網頁,建立 selenium test ,並且針對希望驗證的部分,加上 Assert 。4. 說人話:打開程式碼,靜下心來了解這段程式碼的目的與意義,抽象地來思考每一段程式碼代表的每一件事,並進行排版、重新命名以及增加註解,提昇可讀性,讓自己下次可以快速了解這段程式碼的意義。5. 垃圾分類:針對程式碼所代表的每一件事,透過重構技巧:擷取方法,依據人話來定義 function 名稱。讓 cont 阅读全文

posted @ 2013-12-18 14:58 backslash112 阅读(485) 评论(0) 推荐(0) 编辑

如何隔離物件之間的相依性
摘要:public interface IAccountDao{ string GetPassword(string id);}public interface IHash{ string GetHashResult(string password);}public class AccountDao : IAccountDao{ public string GetPassword(string id) { throw new NotImplementedException(); }}public class Hash : IHash{ public ... 阅读全文

posted @ 2013-12-17 09:27 backslash112 阅读(258) 评论(0) 推荐(0) 编辑

Replace Temp with Query
摘要:double GetPrice(){ int basePrice = _quantity * _itemPrice; double discountFactor; if (basePrice > 1000) { discountFactor = 0.95; } else { discountFactor = 0.98; } return basePrice * discountFactor;}double GetPrice(){ return BasePrice() * DiscountFactor();}... 阅读全文

posted @ 2013-12-09 15:02 backslash112 阅读(184) 评论(0) 推荐(0) 编辑

Replace conditional with Polymorphism
摘要:namespace RefactoringLib.Ploymorphism.Before{ public class Customer { } public class Employee : Customer { } public class NonEmployee : Customer { } public class OrderProcessor { public decimal ProcessOrder(Customer customer, IEnumerable products) { ... 阅读全文

posted @ 2013-12-06 14:49 backslash112 阅读(294) 评论(0) 推荐(0) 编辑

Switch to strategy
摘要:namespace RefactoringLib.SwitchToStrategy.Before{ public class ClientCode { public decimal CalculateShipping() { ShippingInfo shippingInfo = new ShippingInfo(); return shippingInfo.CalculateShippingAmount(State.Alaska); } } public enum State ... 阅读全文

posted @ 2013-12-06 10:56 backslash112 阅读(202) 评论(0) 推荐(0) 编辑

说一下我对Mvvm模式的理解
摘要:使用WPF+Mvvm开发一年多,期间由于对Mvvm模式的理解不足,遇到了很多问题,也绕了很多弯子;网上提供的Mvvm的示例比较简单,实际项目中的需求也各种各样。不过经过几个项目,也有了一些对Mvvm模式的理解:1. Mvvm是什么,Mvvm是怎么来的?Mvvm模式广泛应用在WPF项目开发中,使用此模式可以把UI和业务逻辑分离开,使UI设计人员和业务逻辑人员能够分工明确。Mvvm模式是根据MVP模式来的,可以简单的说,Mvvm模式就是WPF版的MVP模式。MVP模式,MVC模式,这几个模式都是为了抽离出UI逻辑和业务逻辑。2. 使用Mvvm模式可以参考的主流框架及简单介绍。主流开源框架:Simp 阅读全文

posted @ 2012-11-28 22:00 backslash112 阅读(103450) 评论(29) 推荐(25) 编辑

导航

点击右上角即可分享
微信分享提示