考点总结

本文详细介绍了软件构造的多维度视图,包括内部和外部的质量指标,强调了正确性、可扩展性、可重用性等关键因素。此外,还探讨了软件配置管理SCM、版本控制系统VCS,特别是Git的使用。文章深入讨论了静态与动态类型检查、线程安全策略、并发控制中的死锁预防和同步机制,以及Java中的多态、异常处理和内存管理。
摘要由CSDN通过智能技术生成

软件构造的多维度视图

  • By phases: build- and run-time views
  • By dynamics: moment and period views
  • By levels: code and component views


内部/外部的质量指标

External quality factors: qualities such as speed or ease of use, whose presence or absence in a software product may be detected by its users. Other qualities applicable to a software product, such as being modular, or readable, are internal factors. In the end, only external factors matter. But the key to achieving these external factors is in the internal ones.

External quality factors:
  1. Correctness: perform their exact tasks, as defined by their specification, the prime quality. Approaches of ensuring correctness: Conditional, Testing and debugging, Defensive programming such as typing and assertions, Formal approach.
  2. Robustness: react appropriately to abnormal conditions. the system does not cause catastrophic(灾难性的) events; it should produce appropriate error messages, terminate its execution cleanly, or enter a so-called “graceful degradation(毁坏)” mode.

  1. Extendibility: the ease of adapting software products to changes of specification. Two principles are essential for improving extendibility: Design simplicity, Decentralization.
  2. Reusability: serve for the construction of many different applications.
  3. Compatibility: the ease of combining software elements with others. Approaches: Standardized.
  4. Efficiency: place as few demands as possible on hardware resources. Efficiency does not matter much if the software is not correct.
  5. Portability (可移植性 ): the ease of transferring software products to various hardware and software environments.
  6. Ease of use.
  7. Functionality: the extent of possibilities provided by a system.
  8. Timeliness: the ability of a software system to be released when or before its users want it.
  9. Verifiability. Integrity. Repairability. Economy


Internal quality factors:

Internal quality factors are usually used as partial measurement of external quality factors.

  1. Source code related factors such as Lines of Code (LOC), Cyclomatic Complexity, etc
  2. Architecture-related factors such as coupling, cohesion, etc
  3. Readability, understandability and clearness
  4. Complexity
  5. Size


Necessary as tradeoffs between quality factors may be, one factor stands out from the rest: correctness.


软件配置管理SCM与版本控制系统VCS

SCM is the task of tracking and controlling changes in the software. SCM practices include revision control and the establishment of baselines.

A baseline is an agreed description of the attributes of a product, at a point in time, which serves as a basis for defining change.

Local VCS; Centralized VCS; Distributed VCS


Git/GitHub

A Git repository has three parts: – .git directory (a repository storing all version control data) – Working directory (local file system) – Staging area (in memory)

Each file belongs to one of the following three states: – Modified (the file in working directory is different from the one in git repository, but is not in staging area) – Staged (the file is modified and has been added into the staging area) – Committed (the file keeps same in working directory and git directory)

Git 教程


软件构造的阶段划分、各阶段的构造活动




基本数据类型、对象数据类型

基本数据类型的包装类:Boolean, Integer, Short, Long, Character, Float, Double (immutable)


静态类型检查、动态类型检查

精度损失为静态错误(类型无法隐式转化,需要cast)。

static checking
  1. Syntax errors
  2. Wrong names
  3. Wrong number of arguments
  4. Wrong argument types
  5. Wrong return types
dynamic checking
  1. Illegal argument values
  2. Unrepresentable return values
  3. Out-of-range indexes
  4. Calling a method on a null object reference

Static checking tends to be about types, errors that are independent of the specific value that a variable has. Dynamic checking, by contrast, tends to be about errors caused by specific values.


Mutable/Immutable


值的改变、引用的改变


防御式拷贝


Snapshot diagram

Immutable objects (intended by their designer to always represent the same value) are denoted in a snapshot diagram by a double border.

In a snapshot diagram, an immutable reference (final) is denoted by a double arrow.


Specification、前置/后置条件

If the effects do not explicitly say that an input can be mutated, then we assume mutation of the input is implicitly disallowed.

Exceptions that signal a special result are always documented with a Javadoc @throwsclause, specifying the conditions under which that special result occurs. Furthermore, if the exception is a checked exception, then Java requires the exception to be mentioned in a throws declaration in the method signature. For example, suppose NotPerfectSquareException were a checked exception. You would need to mention it in both @throws in the Javadoc and throws in the method signature

For unchecked exceptions that signal a special result, Java allows but doesn’t require the throws clause. But it is better to omit the exception from the throws clause in this case, to avoid misleading a human programmer into thinking that the exception is checked. For example, suppose you defined EmptyQueueException as an unchecked exception. Then you should document it with @throws, but not include it in the method signature


行为等价性


规约的强度

A specification S2 is stronger than or equal to a specification S1 if – S2’s precondition is weaker than or equal to S1’s – S2’s postcondition is stronger than or equal to S1’s, for the states that satisfy S1’s precondition.

If S3 is neither stronger nor weaker than S1, there specs. might overlap (such that there exist implementations that satisfy only S1, only S3, and both S1 and S3) or might be disjoint. In both cases, S1 and S3 are incomparable.


ADT操作的四种类型


表示独立性

This means that the use of an abstract type is independent of its representation (the actual data structure or data fields used to implement it), so that changes in representation have no effect on code outside the abstract type itself.


表示泄露


不变量、表示不变量RI


表示空间、抽象空间、AF

Every abstract value is mapped to by some rep value (surjective, 满射). Some abstract values are mapped to by more than one rep value (not injective, 未必单射). Not all rep values are mapped (not bijective, 未必双射).


以注释的形式撰写AF、RI

checkrep:Although you don’t need to state it in a rep invariant comment, you still must implement the x != null check, and make sure that your checkRep() correctly fails when x is null.


接口、抽象类、具体类

An interface can extend one or more others 一个接口可以扩展其他接口

A class can implement multiple interfaces 一个类可以实现多个接口

From Java 8,interfaces are allowed to contain static methods, so we can implement the creator operation valueOf as a static factory method in the interface MyString. Hiding the implementation completely is a tradeoff, because sometimes the client wants a choice of implementations with different characteristics.


继承、override

In Java methods are rewriteable by default, i.e. there is no special keyword.

The subclass can only add new methods to the superclass, it cannot overwrite them – If a method cannot be overwritten in a Java program, it must be prefixed with the keyword final.

Cannot reduce the visibility of the inherited method from super-type.

A final field: prevents reassignment to the field after initialization

A final method: prevents overriding the method

A final class: prevents extending the class


多态、overload

Three Types of Polymorphism:

  1. Ad hoc polymorphism(function overloading )
  2. Parametric polymorphism(generic programming )
  3. Subtyping (when a name denotes instances of many different classes related by some common superclass )

Overloaded methods let you reuse the same method name in a class, but with different arguments(返回类型不属于签名)

Rules in function overloading: the overloaded function must differ either by the arity(参数数量) or data types


泛型

Generic programming is a style of programming in which data types and functions are written in terms of types to-be-specified-later that are then instantiated when needed for specific types provided as parameters.

generic class declarations, generic interface declarations, generic method declarations, and by generic constructor declarations. (范型的四种使用方式)

Suppose we want to implement the generic Set interface. – Way 1: Generic interface, non-generic implementation: to implement Set for a particular type E . Way 2: Generic interface, generic implementation. – We can also implement the generic Set interface without picking a type for E . – In that case, we write our code blind to the actual type that clients will choose for E . – Java’s HashSet does that for Set


等价性equals()和==


equals()的自反、传递、对称性

If you redefine the equals method, you will also need to redefine the hashcode method for objects that users might insert into a hash table.


hashCode()

Equal objects must have equal hash codes – If you override equals you must override hashCode  Unequal objects should have different hash codes – Take all value fields into account when constructing it .


Hash code must not change unless object mutated


可变对象的观察等价性、行为等价性

observational equality means that two references cannot be distinguished by code that doesn’t change the state of either object, i.e., by calling only observer, producer, and creator methods. This tests whether the two references “look” the same in the current state of the program.

behavioral equality means that two references cannot be distinguished by any code, even if a mutator is called on one but not the other

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值