scala实现设计模式之外观模式
来源:互联网 发布:口袋妖怪淘宝买精灵 编辑:程序博客网 时间:2024/04/28 00:23
package com.linewell.modeldesgin.patternimport java.io.{FileNotFoundException, IOException}import scala.io.Source/** * 读文件,子系统类 * Created by ctao on 2015/8/28. */class FileReader { def read(fileNameSrc: String): String = { println("读取文件,获取明文:") /** * 读入文件 */ var target = "" try { for(s<- Source.fromFile(fileNameSrc)){ target += s.toString } } catch { case io: IOException => io.printStackTrace() case noFile: FileNotFoundException => noFile.printStackTrace() } target }}
package com.linewell.modeldesgin.pattern/** * 加密文件,子系统类 * Created by ctao on 2015/8/28. */class CipherMachine { def encrypt(plainText: String): String = { println("数据加密,将明文转化为密文:") var es = "" for (i <- 0 until plainText.length) { es += String.valueOf(plainText.charAt(i) % 7) } print(es) es }}
package com.linewell.modeldesgin.patternimport java.io.{FileNotFoundException, IOException, PrintWriter}/** * 写文件,子系统类 * Created by ctao on 2015/8/28. */class FileWriter { def write(encryptStr: String, fileNameDes: String): Unit = { print("保存密文,写入文件:") try { val out = new PrintWriter(fileNameDes) out.print(encryptStr) out.close() } catch { case io: IOException => io.printStackTrace() case noFile: FileNotFoundException => noFile.printStackTrace() case _ => println("其他异常") } }}
package com.linewell.modeldesgin.pattern/** *加密外观类 * Created by ctao on 2015/8/28. */class EncryptFacade { private val fileReader = new FileReader private val cipherMachine = new CipherMachine private val fileWriter = new FileWriter def fileEncrypt(fileNameSrc: String, fileNameDes: String): Unit = { fileWriter.write(cipherMachine.encrypt(fileReader.read(fileNameSrc)), fileNameDes) }}
package com.linewell.modeldesgin.pattern/** * 测试客户端 * Created by ctao on 2015/8/28. */object Client extends App { val encryptFacade = new EncryptFacade encryptFacade.fileEncrypt("hello", "des")}
0 0
- scala实现设计模式之外观模式
- 设计模式之外观模式 c++实现
- Java实现设计模式之外观模式
- scala实现设计模式之原型模式
- scala实现设计模式之适配器模式
- scala实现设计模式之组合模式
- scala实现设计模式之代理模式
- scala实现设计模式之命令模式
- scala实现设计模式之备忘录模式
- scala实现设计模式之迭代器模式
- scala实现设计模式之状态模式
- scala实现设计模式之观察者模式
- scala实现设计模式之访问者模式
- 设计模式之外观
- 设计模式之外观
- 设计模式 之 外观
- 设计模式之外观
- 设计模式之外观模式
- Linux内核同步机制之(五):Read/Write spin lock
- OC基础-零基础学习Objective-C:第一部分.类和对象
- 一些常用iOS第三方库以及XCode插件介绍
- 利用数据挖掘实现电信行业客户流失分析
- Android程序设计:多线程同步数据的三种方法的调用代码
- scala实现设计模式之外观模式
- 流失分析中需要注意的问题
- C# 统计代码时间
- vim基础
- HDU 2662 Coin && HDU 1792 A New Change Problem (互质数最大不能生成数)
- Sping-AOP
- 数据挖掘-客户倾向分析
- 关于 U-BOOT 中 SPL 的移植 二
- hdu5387 Clock(数学水题)