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. Advantage Speeds u…
Use immutable classes as much as possible instead of mutable classes. Advantage Easy to design, implement and use than mutable classes. Less prone to error and more secure. Immutable objects are simple. Immutable objects are inherently thread-safe; t…
Feature Interface Abstract class Defining a type that permits multiple implementations Y Y Permitted to contain implementations. N Y The implemented class must reside the class hierarchy. N Y Single inheritance N Y Easy to evolve N Y Advantages of In…
Principle The most powerful technique for minimizing the scope of a local variable is to declare it where it is first used. Nearly every local variable declaration should contain an initializer. Note If a variable is initialized by a method that thro…
Hi guys, I am happy to tell you that I am moving to the open source world. And Java is the 1st language I have chosen for this migration. It's a nice chance to read some great books like "Effective Java 2nd Edition" and share the note for what I…
Chapter 4 Classes and Interfaces Item 13: Minimize the accessibility of classes and members 一个好的模块设计会封装所有实现细节,模块之间只能通过他们公开的API进行交流.因为这些模块互不影响(loosely coupled),所以可以进行单独测试等等.所以为了封装,我们应该把每一个class或member弄得越inaccessible越好.顶层的class和interface只能是public或者defa…
MInimize the accessibility of classes and members 这个叫做所谓的 information hiding ,这么做在于让程序耦合度更低,增加程序的健壮性等等,反正就是很有必要和有用. 四个修饰等级  private :只能当前class中调用 package-praivate 声明class,没有修饰的时候是默认 package-praivate,表示在一个 package里面使用 protect  subclass里面调用 public 任意地方…
<Effective Java>目录摘抄. 我知道这看起来很糟糕.当下,自己缺少实际操作,只能暂时摘抄下目录.随着,实践的增多,慢慢填充更多的示例. Chapter 2 Creating and Destroying Objects Consider static factory methods instead of constructors Consider a builder when faced with many constructor parameters Enforce the s…
Java写了很多年,很惭愧,直到最近才读了这本经典之作<Effective Java>,按自己的理解总结下,有些可能还不够深刻 一.Creating and Destroying Objects Consider static factory methods instead of constructors (factory方法可以拥有名称,可以避免重复创建,比如单例模式) Consider a builder when faced with many constructor parameter…
本文参考 本篇文章参考自<Effective Java>第三版第十五条"Minimize the accessibility of classes and members" Access modifiers (private, package-private, protected and public) 访问修饰符 同类 同包 不同包子类 不同包非子类 private √       package-private(默认) √ √     protected √ √ √  …