20165323 Experiment 2 Java Object-Oriented Programming

The cover of the lab report

Course: Java Programming Class: Class 1653 Name: Yang Jinchuan Student ID: 20165323

Instructor: Lou Jiapeng Experiment Date: April 16, 2018

Experiment time: 13:45 - 15:25 Experiment number: 2

Experiment Name: Java Object-Oriented Programming

2. Experimental content

  1. Getting started with unit testing and TDD
  2. Understand and master the three elements of object-oriented: encapsulation, inheritance, polymorphism
  3. Preliminary mastery of UML modeling
  4. Become familiar with SOLID principles
  5. Learn about design patterns

3. Experimental steps

Commit point one using JUnit, test case

Knowledge points:
1. The general steps of TDD are as follows:

Clarify the current function to be completed and record it as a test list
Quickly complete the writing of test cases for this function If the
test code fails to compile (if there is no product code),
write the product code After the
test passes
, refactor the code and ensure that the test passes (refactoring) The next experimental exercise)
cycle to complete the development of all functions
2. The three elements of Object-Oriented include: encapsulation, inheritance, and polymorphism.
3. Encapsulation is the packaging of data and related behaviors to achieve information hiding. Classes are used for encapsulation in Java.

4. Inheritance means that the definition of a class can be based on another existing class, that is, the subclass is based on the parent class, so as to realize the reuse of the parent class code. Inheritance is the foundation of realizing software reusability and the main way to improve the scalability and maintainability of software systems.
Submission point requirements:
Submit screenshots of the last three JUnit test cases (normal conditions, error conditions, and boundary conditions) that have passed. The screenshots must be drawn and watermarked. Enter your student ID
to check whether JUnit will be used or not. Test Use cases should at least include tests for normal, error, and edge cases.
Screenshot of results:

code hosting

Submission point 2 Research and learn StringBuffer in the way of TDD

Knowledge point:
learn to use API
to master TDD
submission point requirements:
study and learn StringBuffer in TDD way to
submit your unit test cases and screenshots of test passing, the screenshots should be watermarked with the student number;
test whether you can write JUnit test cases
. Screenshots of the results:

code hosting

Submission point 3 Understand the application of OCP principles and DIP principles, and have a preliminary understanding of design patterns

Knowledge points:
OCP (Open-Closed Principle, Open-Closed Principle)
DIP (Dependency Inversion Principle, Dependency Inversion Principle)
Submission point requirements:
let the system support the Double class, and add test code to the MyDoc class to indicate that the addition is correct, submit the test code And screenshot of running knot, plus student number watermark
Results screenshot:

code hosting

Commit point 4 develop a complex class Complex in a TDD way

Submission point requirements:
Develop a complex class Complex in the way of TDD,
submit your unit test cases and screenshots that pass the test, and add the student number watermark to the screenshots;
Result screenshot:

code hosting

Submit point 5 to understand design patterns

Submission point requirements:
Use StarUML to model the code in the second experiment, send a screenshot of the class diagram, plus the student number watermark
. There are only two classes in the class diagram.
Class, inheritance, interface implementation, and combination are expressed in UML.
Screenshot of the result:

Problems encountered in the experiment

Question 1: The TestCase in the code is red, the

solution: you need to put junit.jar, and junit 4-12.jar into the project.

Question 2: The use of StarUML is in a blank state, and it will not be used for modeling
Solution: Search the tutorials found on the Internet ( https://blog.csdn.net/monkey_d_meng/article/details/5995610/ ), use them after learning

Experimental summary

This experiment gave me a preliminary understanding of the use of junit, and also gave me a preliminary understanding of modeling, and also gained some understanding of design patterns, which is very helpful for me to build a framework, and maybe I have a lot more in writing code. What is lacking, but through this experiment, I have deepened the application and understanding of java content

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324582503&siteId=291194637