这个东西主要是为了提供一个统一的接口,然后为了解耦用的。 同时也同时也带来了代码的复杂度。
使得代码的流水线长,wrapper太多,实际干活的代码不好找。
usage in jvm:
in javax.faces.context, ExternalContext internally use ServletContext, HttpSession,
HttpServletRequest, HttpServletResponse, etc, It allow the Faces API to be unaware of the nature
of its containing application environment.
code:
-
package facadepattern;
-
-
class C1{
-
public int doSomething(int x){
-
//return a int's cube
-
return x*x*x;
-
}
-
}
-
-
class C2{
-
public int doAnotherThing(C1 c1, int x){
-
//double the cube
-
return 2*c1.doSomething(x);
-
}
-
}
-
-
class C3{
-
public int doMoreThing(C1 c1, C2 c2, int x){
-
//multiply C1 and C2
-
return c1.doSomething(x) * c2.doAnotherThing(c1, x);
-
}
-
}
-
-
class Facade{
-
public int cubeX(int x){
-
C1 c1 =new C1();
-
return c1.doSomething(x);
-
}
-
-
public int cubeXTimes2(int x){
-
C1 c1 = new C1();
-
C2 c2 = new C2();
-
return c2.doAnotherThing(c1, x);
-
}
-
-
public int MultiplyBoth(int x){
-
C1 c1 = new C1();
-
C2 c2 = new C2();
-
C3 c3 = new C3();
-
return c3.doMoreThing(c1, c2, x);
-
}
-
}
-
-
public class FacadePatternDemo {
-
public static void main(String[] args){
-
Facade fc= new Facade();
-
-
int x= 3;
-
System.out.println("Cube of x :"+fc.cubeX(x));
-
System.out.println("Cube of x * times 2:"+fc.cubeXTimes2(x));
-
System.out.println("multiply C1 and C2 :"+fc.MultiplyBoth(x));
-
}
-
}
-----------------------------------------------------------------------------------------------------
最近发现在Vmware 上的Win2k8的虚拟机加了第二块ISCSI的硬盘后显示为offline.
需要按照这个先来把硬盘online.
阅读(619) | 评论(0) | 转发(0) |