Experiment two Java object-oriented programming

Source: Internet
Author: User

Lesson: Java Programming Experiment class: 1352 name: Yu Jiacen No.: 20135206

Score: Instructor: Lou Jia Peng Experiment Date and time: 2015.05.05

Seat number: compulsory/elective: Elective experiment number: 02

Lab name: Familiarity with the Java development environment

Laboratory Equipment:

Experimental instrument:

Name

Model

Number

Computer

1

Laboratory Building

1

Experimental content:

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

Steps

Take

Percentage

Demand analysis

20min

10%

Design

50min

25%

Code implementation

50min

25%

Test

30min

10%

Analysis Summary

50min

60g

Experimental steps:

(a) Unit testing

(1) Three kinds of code

Pseudo-code: Pseudo-code is independent of the specific programming language, do not write statements related to specific programming language syntax

Product Code: Translating pseudo-code in a specific programming language

Test code: No problem proving your own code

Pseudo Code and product code

Simple test

Compare Complete Tests

For the wrong input test, find the problem!

Solve the problem

For the edge number test, find the problem!

Solve the problem and get a good program

(2) TDD

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

Create Source Folder

To create a junit Test case

Enter test code with error (because there is no product code yet)

The test strip is red and failed.

Write the complete code, the test strip is green, and the test passes

Tested in a variety of ways, all through

(ii) Object-oriented ternary

(1) Abstract

(2) encapsulation, inheritance and polymorphism (ternary)

Animal Class (Final program)

Dog Class (Final program)

Cat Class (Final program)

Test Class (Final program)

The experiment introduces how to use Umbrello:

Create a small box called Dog (Class)

In display, delete public only

Create a private feature

Create public functions

Final full version, corresponding to the above program, with a triangular straight line parent class, representing inheritance

(iii) Preliminary design pattern

S.O.L.I.D Class Design principles:

    • 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)

Patterns can be seen as expert solutions to a problem that can be reused

The most important thing here is the design pattern , the position of design pattern in object-oriented can be equal to the position of data structure in process programming.

(iv) design and implement the plural class complex using TDD method

Pseudo code:

Product Code:

Test code:

Test result: Through calculation, test pass (think better test method)

The benefits of unit testing:

1, after the unit test code, quality can be guaranteed
2, unit test found that the problem is easy to locate.
3, change the code to make mistakes, after unit testing easy to find
4. Unit tests can detect performance problems early on

The problems encountered in this experiment:

1. Often accidentally using Chinese characters, resulting in compilation failure

2. The Cat and Dog program, the beginning of how all the compilation was unsuccessful, and later thought of the cat class and the dog class as a separate file, compiled successfully

3. The definition of plural, involving int and double problems, just beginning to define the mess, and then after repeated error correction, unified with int, and the value of division also int, important to solve

4. Still not very accustomed to the virtual machine, a lot of keys can not be found, so in addition to Umbrello are all in Windows complete (virtual machine is better than before, can move, but because of the speed problem, or not smooth)

Experiment Harvest:

This experiment is more difficult than the last time, it took a lot longer, fortunately, the steps in the Experiment Guide is very detailed, but also introduced a lot of knowledge, the first two experimental code are simple content, but involves TDD, mastered the new programming skills, Umbrello software A little fun, the final program is more difficult, A long time to come out (the plural is what has long been forgotten, the calculation method also forget almost, to the Internet is now looking for information tuition)

Experiment two Java object-oriented programming

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.