代码改变世界

阅读排行榜

Effective C# 学习笔记(二十六)防止返回类内部的对象引用

2011-07-15 20:02 by 小郝(Kaibo Hao), 436 阅读, 收藏,
摘要: 有些时候,你不希望你的类型的属性因为外部引用而更改状态,对外只保持只读或有限的更改权限,这时有四种方法可以防止类内部对象被外部对象引用而引起更改。 1. 值类型 2. 不可变类型 3. 接口 4. 封装 阅读全文

Effective C# 学习笔记(十七)标准析构模式的实现

2011-07-08 22:13 by 小郝(Kaibo Hao), 432 阅读, 收藏,
摘要: 标准的析构模式的实现要点如下: 1. 每个使用非托管资源的类都应实现IDisposable接口 2. 每个使用非托管资源的类都应实现finalizer 3. 对于子类的析构,需重载其父类的Dispose方法,并在其方法中析构自己的托管和非托管对象,并且不要忘记调用父类的析构方法。 4. 不要在析构方法里添加与析构无关的代码,否则会引起严重的问题 阅读全文

Effective C# 学习笔记(二十三)理解接口方法和虚方法的区别

2011-07-13 16:14 by 小郝(Kaibo Hao), 428 阅读, 收藏,
摘要: 接口和虚方法的使用的场景各有所指,总的来说实现接口要比重载virtual方法更具有灵活性。你可以sealed、virtual实现的方法或用abstract来定义方法契约,甚至可以在实现接口的方法中调用virtual方法来获取子类对父类方法重载的多态控制,和父类对自己实现的统一控制。父类的虚方法可以提供所有子类对该方法的默认实现,而接口提供了多种方法定义组合(因为可以被多继承),对外提供了更加灵活的暴露契约的方式。 阅读全文

JavaScript Patterns 5.5 Sandbox Pattern

2014-06-28 12:09 by 小郝(Kaibo Hao), 427 阅读, 收藏,
摘要: This post introduces Sandbox pattern to avoid the namespace drawbacks(1. Reliance on a single global variable to be the application’s global. 2. Long, dotted names to type and resolve at runtime, for example, MYAPP.utilities.array.). 阅读全文

Effective Java 57 Use exceptions only for exceptional conditions

2014-04-21 23:57 by 小郝(Kaibo Hao), 426 阅读, 收藏,
摘要: Exceptions are designed for use in exceptional conditions. Don't use them for ordinary control flow, and don't write APIs that force others to do so. 阅读全文

Effective Java 55 Optimize judiciously

2014-04-18 22:46 by 小郝(Kaibo Hao), 426 阅读, 收藏,
摘要: Do not strive to write fast programs—strive to write good ones; speed will follow. Do think about performance issues while you're designing systems and especially while you're designing APIs, wire-level protocols, and persistent data formats. When you've finished building the system, measure its performance. If it's fast enough, you're done. If not, locate the source of the problems with the aid of a profiler, and go to work optimizing the relevant parts of the system. The first step is to exami 阅读全文

Effective C# 学习笔记(十五)使用Using和Try/Finally 进行资源清理

2011-07-08 22:03 by 小郝(Kaibo Hao), 425 阅读, 收藏,
摘要: 使用Using和Try/Finally语法来管理你的非托管资源,请注意二者的使用场景... 阅读全文

Effective Java 09 Always override hashCode when you override equals

2014-03-04 19:31 by 小郝(Kaibo Hao), 424 阅读, 收藏,
摘要: Failure to do so will result in a violation of the general contract for Object.hashCode, which will prevent your class from functioning properly in conjunction with all hash-based collections, including HashMap, HashSet, and Hashtable. 阅读全文

Effective Java 13 Minimize the accessibility of classes and members

2014-03-08 09:24 by 小郝(Kaibo Hao), 423 阅读, 收藏,
摘要: Information hiding is important for many reasons, most of which stem from the fact that it decouples the modules that comprise a system, allowing them to be developed, tested, optimized, used, understood, and modified in isolation. 阅读全文

Effective C# 学习笔记(十三)对静态类成员使用合适的初始化方式

2011-07-05 22:52 by 小郝(Kaibo Hao), 419 阅读, 收藏,
摘要: 静态成员变量的构造会引起某些麻烦,若其初始化失败会引起CLR终止你的应用程序,所以最好在静态构造函数中用异常处理机制保证其正确初始化,即使出错也有处理方法 阅读全文
上一页 1 ··· 7 8 9 10 11 12 13 14 15 ··· 21 下一页