代码改变世界

阅读排行榜

JavaScript Patterns 7.1 Singleton

2014-07-23 22:53 by 小郝(Kaibo Hao), 660 阅读, 收藏,
摘要: The idea of the singleton pattern is to have only one instance of a specific class. This means that the second time you use the same class to create a new object, you should get the same object that was created the first time. 阅读全文

Effective Java 30 Use Enums instead of int constants

2014-03-24 20:13 by 小郝(Kaibo Hao), 650 阅读, 收藏,
摘要: Enums are far more readable, safer, and more powerful than int constants. Enums can benefit from associating data with each constant sand providing methods whose behavior is affected by this data. When enums benefit from assocating multiple behaviors with a single method perfer constant-specific methods to enums that switch on their own values. Consider the strategy enum pattern if multiple enum constants share common behaviors. 阅读全文

Effective Java 58 Use checked exceptions for recoverable conditions and runtime exceptions for programming errors

2014-04-22 08:46 by 小郝(Kaibo Hao), 647 阅读, 收藏,
摘要: Use checked exceptions for recoverable conditions and runtime exceptions for programming errors. Of course, the situation is not always black and white. 阅读全文

Effective Java 32 Use EnumSet instead of bit fields

2014-03-26 19:25 by 小郝(Kaibo Hao), 642 阅读, 收藏,
摘要: Because an enumerated type will be used in sets, there is no reason to represent it with bit fields. The EnumSet class combines the conciseness and performance of bit fields with all the many advantages of enum types described in Item 30. You can wrap an EnumSet with Collections.unmodifiable Set, but conciseness and performance will suffer. 阅读全文

NHibernate学习(6)—使用缓存

2009-10-07 23:52 by 小郝(Kaibo Hao), 637 阅读, 收藏,
摘要: 一级缓存1. 使用ISession.Get()方法立即把对象实例保存到缓存中,使用ISession.Load()方法当你需要使用的时候再访问数据库把这个实例保存在缓存中。2. NHibernate一级缓存管理  ISession.Evict(object):从缓存中删除指定实例。  ISession.Clear():清空缓存。  ISession.Contains(object):检查缓存中是否包... 阅读全文

Effective Java 43 Return empty arrays or collections, not nulls

2014-04-06 19:44 by 小郝(Kaibo Hao), 621 阅读, 收藏,
摘要: There is no reason ever to return null from an array or collection-valued method instead of returning an empty array or collection. 阅读全文

Effetive Java 22 Favor static member classes over nonstatic

2014-03-16 09:53 by 小郝(Kaibo Hao), 621 阅读, 收藏,
摘要: If a nested class needs to be visible outside of a single method or is too long to fit comfortably inside a method, use a member class. If each instance of the member class needs a reference to its enclosing instance, make it nonstatic; otherwise, make it static. Assuming the class belongs inside a method, if you need to create instances from only one location and there is a preexisting type that characterizes the class, make it an anonymous class; otherwise, make it a local class. 阅读全文

Effective C# 学习笔记(四十五)减少装箱拆箱行为

2011-08-06 10:35 by 小郝(Kaibo Hao), 620 阅读, 收藏,
摘要: 值类型用来存储数据,引用类型用来表现多态,而所有.net framework中的类型都继承自System.Object。这看起来有些冲突。.NET framework 用装箱和拆箱来解决两类类型间的转换。但是这种操作是十分消耗资源且影响性能的。 装箱:把一个值类型放入一个未命名的引用类型中,以使得该类型可被当作引用类型使用。 拆箱:从一个引用类型中将值类型的值Copy取出。 阅读全文

Effective Java 28 Use bounded wildcards to increase API flexibility

2014-03-22 22:06 by 小郝(Kaibo Hao), 617 阅读, 收藏,
摘要: Using wildcard types in your APIs, while tricky, makes the APIs far more flexible. If you write a library that will be widely used, the proper use of wildcard types should be considered mandatory. Remember the basic rule: producer-extends, consumer-super(PECS). And remember that all comparables and comparators are consumers. 阅读全文

Effective C# 学习笔记(四十九)创建符合CLS标准的程序集

2011-08-20 22:38 by 小郝(Kaibo Hao), 615 阅读, 收藏,
摘要: 符合CLS(Common Language Subsystem)标准的程序集可以被其他跑在CLR的语言公用,这是.NET的一个引以为傲的特性,这样你用一种语言编写的程序集就可以被其他在CLR同样支持的程序调用了。要实现这个效果,要求更多的时间来设计构建你的程序集。主要要求两点:1. 所有public和protected的成员方法的参数和返回值必须是符合CLS标准的。2. 所有不符合CLS标准的public和protected成员方法,都应有符合CLS标准的方法来代替。实现CLS标准的程序集可以被其他运行在CLR平台的语言调用,但是要付出一点设计和构建的努力。当然,也不是说你所有的程序集都要为了这个目标去构建,你只需在需要多语言交互的接口使用符合CLS标准来构建就可以了,把转换封装到接口中,这样产出比还是很可以接受的。 :) 阅读全文
上一页 1 2 3 4 5 6 7 ··· 21 下一页