Lesson: Java Programming Class: 1351
Name: Liu Shuai Study No.: 20135104
Score: Instructor: Lou Jia Peng Experimental Date: 2015.05.05
Experiment level: Preview degree: Experiment time: 8:30~12:30
Instrument Group: Compulsory/Elective: Elective experiment number: 2
Experiment Name: Java Object-oriented programming
Experimental purposes and requirements:
1. Students who do not have a Linux base are advised to start with the Linux basics (new version) Vim Editor course
2. Complete the experiment, write the experiment Report, the experiment report is published in the blog Garden, note that the experimental report is focused on the running results, the problems encountered (tool search, installation, use, program editing, debugging, running, etc.), solutions (empty methods such as "Check Network", "Ask classmates", "reading" 0 points) as well as analysis (what can be learned from it, what gains, lessons, etc.). The report can refer to the guidance of Fan Fei Dragon Teacher
3. Plagiarism is strictly forbidden, and the results of the experiment of the perpetrator are zero, and other punitive measures are added.
4. Please first in the laboratory building in the ~/code directory with their own school number to create a directory, code and UML diagram to put in this directory, no study number will be required to redo, and then follow the following steps to practice.
First, the contents of the experiment:
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
Second, the experimental process:
(a) Unit testing
1. Take "percentile to five points" as an example, introduce three kinds of code
(1) Pseudo-code (2) Product Code (3) test code
A. First create a folder in the virtual machine named after your own, to store the code in your experiment, the results of the operation and
2. Follow the instructions in the experiment to enter the code and run the results
(2) TDD (test driven devlopment, testing-driven development)
The general steps for TDD are as follows:
Clear the current functionality to be completed and record it as a test list
Quick completion of writing test cases for this feature
Test code compilation does not pass (no product code)
Write the Product Code
Test Pass
Refactor the code and ensure the test passes (refactoring the next lab session)
Cycle through the development of all functions
About the use of test tools:
Open Eclipse, click File->new->java Project to create a new Tdddemo Java project;
In the Tdddemo project, put the mouse on the project name Tdddemo, right-click, select New->source folder in the pop-up menu to create a new test directory testing;
Put the mouse on the test directory, right-click, select the New->junit test case in the pop-up menu to create a new test cases class myutiltest;
According to the experimental code given, the experimental results are obtained:
(ii) Object-oriented three elements
(1) abstract (2) encapsulation, inheritance, polymorphism
Using the class diagram in UML to describe the class dog, first open the shell in the environment of the experimental building, enter Umbrello in the command line, open the UML modeling software Umbrello;
Click the class icon on the toolbar and then click in class diagram to pop up a Christmas box and enter the class name dog.
Put the mouse on the dog class, right-click, select Properties, in the popup dialog box in the display to remove the public only option;
Put the mouse on the dog class, right-click, select New->attribute, in the Pop-up dialog box, fill in the Type,name, and choose a good visibility;
Put the mouse on the dog class, right-click, select New->operation, in the Pop-up dialog box, fill in the Type,name, and choose visibility.
In UML, the property of a class can display its name, type, initialization value, and attributes can also display private,public,protected. The methods of the class can display their method names, parameters, return types, and the Private,public,protected property of the method. which
+ indicates public
#表示 protected
-Indicates private
The operation results are as follows:
(iii) Preliminary design pattern
S.O.L.I.D Principles
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)
OCP is one of the most important principles in Ood, and the OCP's content is:
Software entities (class, modules, function, etc) should open for extension,but closed for modification.
Software entities (classes, modules, functions, etc.) should be open to expansion and closed to modifications.
Third, the problems encountered and solutions
Problems that arise:
1. In the preparation of the unit test, because the network signal is not stable, and the virtual machine is running very slowly, so that the experiment is very time-consuming, can only step slowly
2. In this experiment, it was learned that the experimental building can only be cut 4, so choose to use your own tools
3 test code writing process because not very familiar with the program, writing so the test code has a lot of problems, spend a lot of time to modify.
Iv. Harvest of Experiments
Although the experiment took a lot of time, but I also gained a lot. When solving practical problems with a program, it is best to write three kinds of code: pseudo-code, product code, test code. This experiment has made me realize the difference between object-oriented programming tools and object-oriented programming tools, and object-oriented we can write code by encapsulating objects, so that we can devote more effort to the design of the class rather than to code writing. Although I pay a lot, but the harvest is big, well-designed experiments let me benefit greatly.
Java Experiment 220,135,104