Second experimental report on Java programming

Source: Internet
Author: User

Beijing Institute of Electronic Technology (BESTI)

Lab Report

Course: Data structure class: 1352 name: He Weizin No.: 20135223

Score: Instructor: Lou Jia Peng Experimental Date: 2015.5.6

Experiment level: Preview degree: Experiment time: 5:30-10:00

Instrument Group: 23 Compulsory/elective: Compulsory experiment serial number: 02

Experiment Name: Java Object-oriented programming

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

Laboratory equipment

Model

Number

Notebook PC

Dell 14z-5423

1

Eclipse

\

\

Virtual machines

\

\

Experimental steps

(a) Unit testing

(1) Three kinds of code

When using the program to solve the problem, you will write three kinds of code:

    • Pseudo code
    • Product Code
    • Test code

Use an example to illustrate how to write these three kinds of code.

Requirements: We want to solve a percentile grade in a Myutil class turn into "excellent, good, medium, pass, fail" five grade system performance function.

1. Pseudo-code

2. Product Code

3. Test code

Test normal condition

Test error condition

Test boundary condition

(2) TDD (test driven devlopment, testing-driven Development )

Write the test code first, then write the product Code development method called "Test-driven Development" (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

The coding rhythm of TDD is:

    • Add test code, JUnit appears red bar
    • Modify the Product Code
    • JUnit appears green bar, Task complete

The test results showed a red bar, indicating that the test failed, the red bar summarized the test situation, ran a test, no errors, a test failed. The following reasons are also clear: the test code in line tenth passed in 55 o'clock, the expected result is "failed", the code returned "error"

Modify the Myutil.java bar, enter the following code, the green bar indicates that the program runs through

(ii) Object-oriented three elements

(1) abstract

Abstraction is a matter of extracting the essential features of things and not considering their details for the time being. For complex system problems, we can solve problems by means of hierarchical abstraction. At the highest level of abstraction, the solution of the problem is described in a generalized way, using the language of the problem environment. In the lower layers of abstraction, they are described in a procedural way. When describing a problem solution, use a problem-oriented and implementation-oriented terminology. In program design, abstraction consists of two aspects, one is process abstraction and the other is data abstraction.

(2) encapsulation inheritance and polymorphism

1. Encapsulation actually uses methods to hide the data of the class, controlling the user's modifications to the class and the extent to which the data is accessed, resulting in the benefits of modularity (modularity) and information hiding (information hiding) Interface (interface) is an accurate description of the package.

2. Inheritance refers to the definition of a class can be based on another already existing class, that is, the subclass is based on the parent class, thus implementing the reuse of the parent code. The key to inheritance is to confirm that a subclass is a special type of parent class. Inheritance is the foundation of software reusability, is the main way to improve the expansibility and maintainability of software system, and inheritance can realize code reuse. It should be noted that the more important role of inheritance is to achieve polymorphism.

3. Polymorphism refers to the phenomenon that different class objects will execute different code when they invoke the same signed member method. Polymorphism is the basis of the flexibility and extensibility of object-oriented programming. Let's look at the previous class diagram and we can further abstract the bark () and meow () in the Cat class into an abstract method shout (), which is covered in the Dog class and cat class.

(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 a customary solution (solution) for a particular problem (problem) under an external environment (context). The pattern must make the problem clear, explain why it is used to solve the problem, and under what circumstances it will not work, and each pattern can be reused because of its repeatability, having its own name, being able to impart it, and transplanting it into different scenarios. Patterns can be seen as expert solutions to a problem that can be reused . There are many patterns in computer science:

        • Grasp mode
        • Analysis mode
        • Software Architecture Patterns
        • Design Patterns: Created, structured, behavioral
        • Management mode: The manager Pool implementation mode
        • Interface Design Interaction Mode
        • ...

        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.

      • (3) design pattern Real Example

        Design pattern provides a subsystem or component for refining a software system, or a diagram between them, which describes the public rendition structure of a communication component, which can solve a design problem in a particular context.

(iv) Practice

Use TDD the way to design off implements the plural class Complex

1. Pseudo-code

2. Test code

3. Product Code

4. Running Results

5. Statistical time

Steps

Take

Percentage

Demand analysis

5 6.25%

Design

10 12.5%

Code implementation

50 62.5%

Test

10 12.5%

Analysis Summary

5 6.25%

Summarize the benefits of unit testing:

(1) Optimize the program design, and continuously optimize the procedure, make the procedure more perfect.

(2) Let oneself responsible module function definition as clear as possible, the module internal changes will not affect other modules, and the quality of the module can be stable, quantitative guarantee.

(3) The program coupling degree of the design is also getting lower. The input and output of each unit program, the business content and the exception situation will be as simple as possible. Finally found that their programming habits and design capabilities will be better

Experiment Experience:

This experiment has gained a great harvest, initially mastered unit testing and TDD, and in-depth understanding and to some extent mastered the Java programming in the encapsulation, inheritance, polymorphic applications.

the UML Modeling and S.O.L.I.D Principles also have a certain degree of understanding. Although there are many problems in the experiment, it can be solved very well in the end. But the experiment took too much time, and overall the experiment was inefficient.

Second experimental report on Java programming

Related Article

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.