Lab2 experiment Summary

The experimental training abstract data types (ADT) design, statute, test, and implement the ADT using object oriented programming (OOP) techniques. Specifically:

⚫ problem for a given application, the desired ADT from the problems identified in the description;

⚫ design ADT Statute (pre-condition, post-condition) and to assess the quality of the statute;

The statute ⚫ ADT test cases;

⚫ ADT generified;

⚫ statute implemented according to many different designs of the ADT; for each implementation, which represents design (representation), represents invariance (invariant REP), abstraction (abstraction function)

⚫ achieved using OOP ADT, and determine whether express invariance violation, implementations of whether there is a leak representation (rep exposure);

⚫ ADT test implementation and evaluation of the test coverage;

⚫ using ADT and its implementation, for the application of the development process;

⚫ in the test code, it is possible to write testing strategy and design the test cases.

To realize the function itself is not difficult, but this new design ideas feel very challenging. In the process of completion of the experiment, we spent a lot of time to understand the experimental requirements and curriculum knowledge links, writing comments on such things. But generally speaking, the work is meaningful, serious thought about mutability / immutability, AF, RI after written code more readable and easy to understand, logical, inexplicable error a lot less.

The following recording problems encountered in writing experiments and solutions

  • How to write immutable class
    1. All variables should be private, the final (and sometimes not final can)
    2. The final object should be to avoid inheritance (but I do not consider this experiment)
    3. does not provide any mutator
    4. for the members of the mutable, you need defensive copy to ensure safe return, which is to ensure safety from rep exposure

  • What is the AF, RI
    the AF value is mapped space used in the realization of the need to support the value space. Because of the need to support the value of the space must be met, so the AF must be surjective.
    RI layman's terms is a collection of legal representation. So you want to write checkrep function always returns before checking whether to satisfy the requirements of RI. Doing so in favor of the correctness of the guarantee program.

  • About generic programming
    generics of this experiment is very simple, find + replace to get away. But also people feel the benefits of generic programming for code reuse. Written chart ADT can support a variety of data types.
    Only generic information exists in the compilation stage, it will be erased during operation, or alternatively to define the type of Object, as shown:
    Type erasure

  • Writing the spec
    override method does not need to re-write the spec. Use / ** logo write spec, easy to generate Javadoc.

  • About test
    equivalence class method described in application programs written test, try to ensure that each case is tested. Plug EclEmma eclipse with the test code coverage can help, and shows which lines are not to run.
    The program can be modified to improve test coverage based on the operating results.

  • Chess
    this first experiment started doing some running around in circles. Lead piece, player class which wrote to the fundamental method useless, a waste of their time. Looking back, I feel should identify each class is mutable or immutable, otherwise no way to determine the safety rep, and when the write method parameters and return value type is not good to determine, because it will use each other between classes difficult to guarantee safety from exposure. Next redistribution specific functions of each class, first written name of the method further implementation, to avoid back and overthrow their own design. This also can be seen how important the written spec.
    In addition, written chess class function to be a good package, separated, can not be part of the task of training and preparation user, unit testing is not good to do so.

Guess you like

Origin blog.csdn.net/qq_43351085/article/details/89285662