zoukankan      html  css  js  c++  java
  • 【Java】NO.120.JDK.1.JDK8.1.001-【Java8实战】

     Style:Mac

    Series:Java

    Since:2018-09-26

    End:2018-09-26

    Total Hours:1

    Degree Of Diffculty:5

    Degree Of Mastery:5  

    Practical Level:5

    Desired Goal:5

    Archieve Goal:3

    Gerneral Evaluation:3

    Writer:kingdelee

    Related Links:

    http://www.cnblogs.com/kingdelee/

    1.把方法当做参数/值进行传递,将函数作为值的思想

    第2章 行为参数化 

    谓词

    2.2 行为参数化

    你在上一节中已经看到了,你需要一种比添加很多参数更好的方法来应对变化的需求。让 我们后退一步来看看更高层次的抽象。一种可能的解决方案是对你的选择标准建模:你考虑的 是苹果,需要根据 Apple 的某些属性(比如它是绿色的吗?重量超过150克吗?)来返回一个 boolean值。我们把它称为谓词(即一个返回boolean值的函数)。让我们定义一个接口来对选 择标准建模:

    public interface ApplePredicate{ boolean test (Apple apple); }

    现在你就可以用ApplePredicate的多个实现代表不同的选择标准了,比如(如图2-1所示):

    public class AppleHeavyWeightPredicate implements ApplePredicate{ public boolean test(Apple apple){ return apple.getWeight() > 150; } } public class AppleGreenColorPredicate implements ApplePredicate{ public boolean test(Apple apple){ return "green".equals(apple.getColor()); } }

    3.

    中间操作和终端操作

     

     

     

  • 相关阅读:
    网络诊断工具:[tcpdump]
    网络诊断工具:iproute
    C语言编译全过程
    (Ruby)Ubuntu12.04安装Rails环境
    (Life)牛人的学习方法(转译文)
    (WPF)WPF事件要点WPF宝典笔记
    (WPF)依赖属性要点WPF宝典笔记
    (DP)降低代码重构的风险(转载)
    (WPF)路由事件要点WPF宝典笔记
    JDBC,MYBATIS,Hibernate性能对比!
  • 原文地址:https://www.cnblogs.com/kingdelee/p/9714575.html
Copyright © 2011-2022 走看看