12 2013 档案

.NET 垃圾回收与内存泄漏
摘要:> 前言相信大家一定听过,看过甚至遇到过内存泄漏。在 .NET 平台也一定知道有垃圾回收器,它可以让开发人员不必担心内存的释放问题,因为它会自定管理内存。但是在 .NET 平台下进行编程,绝对不会发生内存泄漏的问题吗?答案是否定的,就算有了自动内存管理的垃圾回收器,也会发生内存泄漏。本文就讨论下 .NET 平台的垃圾回收器是如何工作的,进而当我们在编写 .NET 程序时避免发生内存泄漏的问题。> 垃圾回收的基本概念“垃圾”指的是事先分配过但后来不再被使用的内存。垃圾回收背后的一个基本观念是:“无限访问的内存”,但是从来没有无限的内存,当机器需要分配内存但不够的时候,就需要把之前不再 阅读全文

posted @ 2013-12-27 14:17 backslash112 阅读(4261) 评论(7) 推荐(2) 编辑

重构的步骤
摘要: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) 编辑

导航

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