- 浏览: 798596 次
- 性别:
- 来自: 上海
最新评论
-
心存高远:
谢谢作者分享,刚好看到这里不太明白,现在茅塞顿开。不过runt ...
关于 Maven的传递依赖的理解 -
sxlkk:
851228082 写道甚至在某次技术会议现场遇到《Maven ...
关于 Maven的传递依赖的理解 -
851228082:
851228082 写道a----compile----b-- ...
第五章 坐标和依赖 -
851228082:
a----compile----b-----provided- ...
第五章 坐标和依赖 -
851228082:
甚至在某次技术会议现场遇到《Maven in action》的 ...
关于 Maven的传递依赖的理解
文章列表
1) An array has a fixed size, and in the more general case, you won’t know at the time you’re writing the program how many objects you’re going to need.
2) The java.util library has a reasonably complete set of container classes to solve this problem, the basic types of which are List, Set, Que ...
1) It’s possible to place a class definition within another class definition. This is called an inner class.
2) If you want to make an object of the inner class anywhere except from within a method of the outer class, you must specify the type of that object as OuterClassName.InnerClassName.
...
1) An abstract method is a method that is incomplete. It has only a declaration and no method body. Here is the syntax for an abstract method declaration: abstract void f();
2) A class containing abstract methods is called an abstract class. If a class contains one or more abstract methods, the ...
1) Polymorphism is the third essential feature of an object-oriented programming language, after data abstraction and inheritance. It provides another dimension of separation of interface from implementation, to decouple what from how. Polymorphism allows improved code organization and readability ...
1) You have two ways to use the classes without soiling the existing code:
a. you simply create objects of your existing class inside the new class. This is called composition, because the new class is composed of objects of existing classes. You’re simply reusing the functionality of the code ...
1) Java provides access specifiers to allow the library creator to say what is available to the client programmer and what is not. The levels of access control from “most access” to “least access” are public, protected, package access (which has no keyword) and private.
2) A package contains a ...
1) In Java, the class designer can guarantee initialization of every object by providing a constructor. If a class has a constructor, Java automatically calls that constructor when an object is created, before users can even get their hands on it. So initialization is guaranteed. The name of the co ...
1) Java doesn’t allow you to use a number as a boolean.
2) The if-else statement is the most basic way to control program flow. The else is optional, so you can use if in two forms:
if(Boolean-expression)
statement;
or
if(Boolean-expression)
statement;
else
statement;
...
1) An operator takes one or more arguments and produces a new value. The arguments are in a different form than ordinary method calls, but the effect is the same. All operators produce a value from their operands. In addition, some operators change the value of an operand. This is called a side eff ...
1) All programming languages provide abstractions. It can be argued that the complexity of the problems you’re able to solve is directly related to the kind and quality of abstraction. By “kind” I mean, “What is it that you are abstracting?”
2) The programmer must establish the association bet ...
适用情况:系统要求某个类在整个系统中只能有一个实例存在,并且有统一的地方获取这个实例。
解决方案:由这个类来维护其实例的个数,确保整个系统中只有单一实例存在
类图:
实际应用:比如struts1中的ActionServelet。
与其它设计模式的比较:TBD
适用情况:当一个系统要生产很多种产品(这些产品可能构成复杂的层次结构)时,想避免生成和产品种类个数(以及产品层次结构)相同的实体工厂。或者说某些种产品会临时加入到生产线,当前没有一个工厂知道怎么生产这种产品(初始化产品)或者生产一次产品的代价很大。
解决方案:将每一种产品的一个实例(或者多个实例,每个实例代表这种产品的一种初始化状态)作为一个prototype,所有产品都有一个clone()接口用来复制产品实例本身。 这样当系统需要一种产品时,只要调用这种产品对应的prototype的clone()方法就行了。
类图:
GOF中的例子:
实际 ...
适用情况:当一个抽象工厂要生产某种产品时,他只知道要生产的产品的接口,而不知道其实现是怎样的。产品可能有很多种实现。
解决方案:只定义抽象工厂生产该种产品的接口,而将实现留给实体工厂。不同的实体工厂知道怎样生产对应的产品。
类图:
GOF中的例子:
实际应用:实际应用太多了,个人觉得这个模式太普通,其实就是接口与实现相分离的OO思想以及多态的体现,没什么特别之处,系统(使用者)还是要自己构建具体工厂类来生产,只不过操作的引用是抽象工厂类而已。比如说Collection类的iterator()方法,就是工厂方法,它只是一个接口, ...
适用情况:当系统中要生成一个复杂对象,而这个复杂对象的各种零件又有不同的式样且零件的装配过程比较复杂时,希望装配过程对系统来说是透明的,变更装配顺序或装配用到的零件对系统也是透明的。同时希望不同式样零件的生产与零件的装配是分离的。
解决方案:首先,有一个负责装配零件的Director,它实现了如何组装零件,并且也只有它知道需要什么零件。其次定义一个生产零件的抽象Builder,它定义了生产各种零件的接口。最后有一系列具体的Builder来实现这个抽象Builer,用于生产不同样式的零件。
类图:
GOF中的例子:
交互图:
...
阅读了 Guidelines for using the Java 2 reference classes
与 Understanding Weak References
之后,发现两篇文章关于 WeakReference 和 PhantomReference 何时被加入到 ReferenceQueue有些出入。也就是说到底是在引用的对象没有强引用时还是在引用的对象真正被回收时。于是写了如下程序进行验证:
package mypackage;
import java.lang.ref.PhantomReference;
import java.lang.ref.Referenc ...