Real Inspection report
Course: Mobile Platform Application development Practice class: 201592 Name: Wang Hechong No.: 20159202
Score: Instructor: Lou Jia Peng Experimental Date: 2015.10.3
Experiment level: Preview degree: Experiment time:
Instrument Group: Compulsory/Elective: Elective experiment number: 1
Lab name: Familiarity with the Java development environment
Experimental purposes and requirements:
1. Initial mastery of unit testing and TDD
2. Understanding and mastering the object-oriented three elements: encapsulation, inheritance, polymorphism
3. Initial mastery of UML modeling
4. Familiarity with S.O.L.I.D principles
5. Understanding Design Patterns
Lab Device: A computer with a Java development environment
Experimental content, steps
(a) Unit testing
When using the program to solve the problem, you will write three kinds of code: pseudocode, Product code, test code
In order to achieve a percentile result into the "excellent, good, medium, pass, fail" five-grade system performance as an example:
1. Pseudo-code
If the score is less than 60, turn into "fail"
If the score is between 60 and 70, turn into "pass"
If the score is between 70 and 80, turn into "medium"
If the score is between 80 and 90, turn into "good"
If the score is between 90 and 100, turn into "good"
Other, turn into "error"
2. Test code
3. Product Code
The compiled test code has no syntax errors and runs junit.test, such as:
The test results showed a red bar stating that the test failed, modifying the Myutil.java before running the test, as shown in:
Test success!
Add Boundary value Test
Found that the test failed, and then modify Myutil.java, add to the score of less than 0 and equal to 100 of the judgment, run the program, the green bar shows that the test succeeded, as shown in:
(ii) object-oriented three elementsthe three elements of object-oriented (object-oriented) include: encapsulation, inheritance, polymorphism. Object-oriented thinking involves all aspects of software development, such as object-oriented analysis (OOA), Object-oriented design (OOD), and object-oriented programming (OOP).
In Java, a class is encapsulated and a dog class is built, and Dog classes are hidden by using classes and access control (private,public), color Open interfaces setColor() , getColor() bark() and toString . The Dog class is a module that tests the code and runs the result as follows:
Ood Modeling uses the graphical Modeling language UML (Unified Modeling Language), which is inherited from UML class diagrams, which demonstrate the static relationship between classes, in which AnimalTest class-dependent classes Dog and Cat classes:
The above UML diagram abstracts the classes Dog bark() and classes Cat meow() into an abstract method, which overrides the method in the class shout() and class Dog Cat , and the corresponding test code and run results are as follows:
(iii) Preliminary design pattern
(1) S.O.L.I.D principle
Object-oriented three elements are "encapsulation, inheritance, polymorphism", and any object-oriented programming language will support these three elements syntactically. It is very difficult to use the three elements, especially polymorphism, with the help of abstract thinking, and the S.O.L.I.D design principle is a good guide:
- SRP (Single Responsibility Principle, sole responsibility principle)
- OCP (open-closed Principle, open-closed principle)
- LSP (Liskov substitusion Principle,liskov substitution principle)
- ISP (Interface segregation Principle, interface separation principle)
- DIP (Dependency inversion Principle, dependency inversion principle)
(2) mode and design mode
A pattern is the usual solution to a particular problem (problem) under an external environment (context).
The position of design patterns in object-oriented mode can be comparable to the status of data structures in process-oriented programming.
(iv) Practice
1. Use TDD to design the complex to implement the plural class.
One, pseudo-code:
First, a complex class complex is designed to define three construction methods:
- No input---The real part of the complex number is 0 and the imaginary part is 0
- Enter a parameter---the real part of the plural is the number entered and the imaginary part is 0
- Enter two parameters---the real part of the complex number and the imaginary part correspond to the two numbers of the corresponding input.
- Addition---the real part and the real part of the complex, the imaginary part and the imaginary part, namely the output a.x+b.x,a.y+b.y
- Subtraction---The real part of the complex number is subtracted from the real part, and the imaginary part is subtracted from the imaginary part, that is, the output a.x-b.x,a.y-b.y
- Multiply---Two complex numbers, similar to two polynomial multiplication, expanded: ac+adi+bci+bdi^2
- Division---Multiply the numerator denominator by the conjugate of the denominator. Expanded: (AC+BD)/(c^2+d^2) + (BC-AD)/(c^2+d^2) I.
Second, the test code:
Third, the product code
The results of the operation are as follows:
Experiment PSP Time
|
Steps |
Take |
Percentage |
|
Demand analysis |
5min |
5.6% |
|
Design |
20min |
22.2% |
|
Code implementation |
30min |
33.4% |
|
Test |
5min |
5.6% |
|
Analysis Summary |
30min |
33.4% |
Experiment Summary and Harvest
1. Know the general steps of TDD: clear the current functions to be completed, log into a test list, quickly finish writing test cases for this function, test code compilation does not pass (no product code), write product code, test pass, code refactoring, and ensure the test pass.
2. Write the program first write three kinds of code: pseudo-code, product code, test code, such a program has practical significance.
Problems encountered and their solutions
Complex pseudo-code does not know how to classify. Query the construction method of the plural class, know that can be defined three categories, the subtraction method of the complex number of some forgotten, after the query related information learned.
Java Lab report (Experiment II)