zoukankan      html  css  js  c++  java
  • java 学习笔记 AF&RI

    Abstraction function——抽象函数
    抽象函数是表示值到其对应的抽象值的映射——AF: R->A。
    对于抽象函数来说,仅仅宽泛的说抽象域表示了什么并不够。抽象函数的作用是规定合法的表示值会如何被解释到抽象域。作为一个函数,我们应该清晰的知道从一个输入到一个输入是怎么对应的。
    Rep invariant——表示不变量
    注明抽象值的合法区域。
    说明合法/不合法的原因。
    代码示例

    // Immutable type representing a tweet.
    public class Tweet {
    
    private final String author;
    private final String text;
    private final Date timestamp;
    
    // Rep invariant:
    // author is a Twitter username (a nonempty string of letters, digits, underscores)
    // text.length <= 140
    // Abstraction function:
    // AF(author, text, timestamp) = a tweet posted by author, with content text, 
    // at time timestamp 
    // Safety from rep exposure:
    // All fields are private;
    // author and text are Strings, so are guaranteed immutable;
    // timestamp is a mutable Date, so Tweet() constructor and getTimestamp() 
    // make defensive copies to avoid sharing the rep's Date object with clients.
    
    // Operations (specs and method bodies omitted to save space)
    public Tweet(String author, String text, Date timestamp) { ... }
    public String getAuthor() { ... }
    public String getText() { ... }
    public Date getTimestamp() { ... }
    }
    生命中真正重要的不是你遭遇了什么,而是你记住了哪些事,又是如何铭记的。
  • 相关阅读:
    ZJU_1145 OR POJ_1100 Dreisam Equations
    数据结构基础之队列
    The New Villa
    Mission Impossible 6
    数据结构基础之栈
    POJ_1185_炮兵阵地 dp+状态压缩
    (转载)Dig命令的用法
    (转载)服务发现系统etcd介绍
    golang 导入包
    1.4方程求根之弦截法
  • 原文地址:https://www.cnblogs.com/nbwzyzngyl/p/14979429.html
Copyright © 2011-2022 走看看