软件构造期末复习08 Construction for Change

一、SOLID
1. Single Responsibility Principle

ADT中不应该有多于1个原因让其发生变化,否则就
拆分开

2. Open-Closed Principle

对扩展开放,对修改封闭

3. LSP

里氏代换原则

4. Interface Segregation Principle
  • 不能强迫客户端依赖于它们不需要的接口,只提供必需的接口
  • 避免接口污染
  • 避免胖接口
5. Dependency Inversion Principle
  • delegation的时候,要通过interface建立联系,而非具体子类
小结——OO设计的两大武器
(1) 抽象
  • LSP:对外界看来,父类和子类是“一样”的
  • DIP:对接口编程,而不是对实现编程,通过抽象接口隔离变化
  • OCP:当需要变化时,通过扩展隐藏在接口之后的子类加以完成,而不要修改接口本身
(2) 分离
  • SRP:按责任将大类拆分为多个小类,每个类完成单一职责,规避变化,提高复用度
  • ISP:将接口拆分为多个小接口,规避不必要的耦合
归纳起来,让类保持责任单一、接口稳定
二、Regular Expressions & Grammars
1. terminal与nonterminal
  • terminal : 产生式不含变元
  • nonterminal : 产生式含有变元
2. 语法产生式
  • ? ? ? 代表0次或1次
  • + + + 代表至少1次
  • m , n {m,n} m,n 代表重复闭区间 [ m , n ] [m,n] [m,n]
  • [ ] [] []方括号内部代表字母表
x ::= [a-ckx-z]    // equivalent to  x ::= 'a' | 'b' | 'c' | 'k' | 'x' | 'y' | 'z'
  • [^…] 代表补集
x ::= [^a-c]  // equivalent to  x ::= 'd' | 'e' | 'f' | ... | '0' | '1' | '2' | ... | '!' | '@'
              //                          | ... (all other possible characters)
  • ∗ * ? ? ? + + +优先级最高,连接次之,| 最低
3. 正则表达式
  • 特殊含义的符号
.   // matches any single character (but sometimes excluding newline, depending on the regex library)

\d  // matches any digit, same as [0-9]
\s  // matches any whitespace character, including space, tab, newline
\w  // matches any word character including underscore, same as [a-zA-Z_0-9]
  • 转义
\., \(, \), \*, \+, ...
escapes an operator or special character so that it matches literally

注 : 在java编程中,需要二次转义

  • 例:
Original:
    'http://' ([a-z]+ '.')+ [a-z]+ (':' [0-9]+)? '/' 
Compact:
    http://([a-z]+.)+[a-z]+(:[0-9]+)?/ 
With escape:
    http://([a-z]+\.)+[a-z]+(:[0-9]+)?/
4. 在java中使用正则表达式
  • Metacharacters: < ( [ { \ ^ - = $ ! | ] } ) ? * + . >
    Two ways to force a metacharacter to be treated as an ordinary character:
    • Precede the metacharacter with a backslash \
    • Enclose it within \Q (which starts the quote) and \E (which ends it).
  • Predefined Character Classes
.    Any character (may or may not match line terminators)
\d   A digit: [0-9]
\D   A non-digit: [^0-9]
\s   A whitespace character: [ \t\n\x0B\f\r]
\S   A non-whitespace character: [^\s]
\w   A word character: [a-zA-Z_0-9]
\W   A non-word character: [^\w]
  • Boundary Matchers
^   The beginning of a line
$   The end of a line
\b   A word boundary
\B   A non-word boundary
\A   The beginning of the input
\G  The end of the previous match
\Z  The end of the input but for the final terminator, if any
\z  The end of the input
  • Greedy, Reluctant and Possessive

    • Greedy (默认)
      匹配器被强制要求第一次尝试匹配时读入整个输入串,如果第一次尝试匹配失败,则从后往前逐个字符地回退并尝试再次匹配,直到匹配成功或没有字符可回退
    • Reluctant
      从输入串的首(字符)位置开始,在一次尝试匹配查找中只勉强地读一个字符,直到尝试完整个字符串
    • Possessive
      直接匹配整个字符串,如果完全匹配就匹配成功,否则匹配失败。效果相当于equals
  • 例1 :

[a-d[m-p]]   a through d, or m through p: [a-dm-p] (union)
  • 例2 :
[a-z&&[^m-p]]   a through z, and not m through p: [a-lq-z] (subtraction)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值