Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1743422
  • 博文数量: 297
  • 博客积分: 285
  • 博客等级: 二等列兵
  • 技术积分: 3006
  • 用 户 组: 普通用户
  • 注册时间: 2010-03-06 22:04
个人简介

Linuxer, ex IBMer. GNU https://hmchzb19.github.io/

文章分类

全部博文(297)

文章存档

2020年(11)

2019年(15)

2018年(43)

2017年(79)

2016年(79)

2015年(58)

2014年(1)

2013年(8)

2012年(3)

分类: Java

2017-02-12 10:05:31

这个东西主要是为了提供一个统一的接口,然后为了解耦用的。 同时也同时也带来了代码的复杂度。
使得代码的流水线长,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:

点击(此处)折叠或打开

  1. package facadepattern;

  2. class C1{
  3.     public int doSomething(int x){
  4.         //return a int's cube
  5.         return x*x*x;
  6.     }
  7. }

  8. class C2{
  9.     public int doAnotherThing(C1 c1, int x){
  10.         //double the cube
  11.         return 2*c1.doSomething(x);
  12.     }
  13. }

  14. class C3{
  15.     public int doMoreThing(C1 c1, C2 c2, int x){
  16.         //multiply C1 and C2
  17.         return c1.doSomething(x) * c2.doAnotherThing(c1, x);
  18.     }
  19. }

  20. class Facade{
  21.     public int cubeX(int x){
  22.         C1 c1 =new C1();
  23.         return c1.doSomething(x);
  24.     }

  25.     public int cubeXTimes2(int x){
  26.         C1 c1 = new C1();
  27.         C2 c2 = new C2();
  28.         return c2.doAnotherThing(c1, x);
  29.     }

  30.     public int MultiplyBoth(int x){
  31.         C1 c1 = new C1();
  32.         C2 c2 = new C2();
  33.         C3 c3 = new C3();
  34.         return c3.doMoreThing(c1, c2, x);
  35.     }
  36. }

  37. public class FacadePatternDemo {
  38.     public static void main(String[] args){
  39.         Facade fc= new Facade();

  40.         int x= 3;
  41.         System.out.println("Cube of x :"+fc.cubeX(x));
  42.         System.out.println("Cube of x * times 2:"+fc.cubeXTimes2(x));
  43.         System.out.println("multiply C1 and C2 :"+fc.MultiplyBoth(x));
  44.     }
  45. }

-----------------------------------------------------------------------------------------------------
最近发现在Vmware 上的Win2k8的虚拟机加了第二块ISCSI的硬盘后显示为offline. 
需要按照这个先来把硬盘online. 

阅读(568) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~