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() { ... }
    }
    生命中真正重要的不是你遭遇了什么,而是你记住了哪些事,又是如何铭记的。
  • 相关阅读:
    性能分析一:查看程序占用系统的内存 .
    Winform中ToolTip的用法
    30岁的程序员
    序列化
    CMD中可执行的结束进程命令
    数据库设计规范与技巧
    判断字符串编码思路
    字符串加密思路
    在同一个页面施用多个不同的jQuery版本而不冲突的方法
    mysql 数据库设计
  • 原文地址:https://www.cnblogs.com/nbwzyzngyl/p/14979429.html
Copyright © 2011-2022 走看看