Experiment two Java object-oriented programming _20135129 Li Yu Yu

Source: Internet
Author: User

Course: Java Lab class: 201352 Name: Chi Binning No.: 20135212

Score: Instructor: Lou Jia Peng Experimental Date: 15.05.05

Experiment level: Preview degree: Experiment time:

Instrument Group: Compulsory/Elective: Elective experiment number: 2

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

Experimental 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 experiment report focuses on the running results , problems encountered (tool find, installation, use, program editing, debugging, running, etc.), solutions (empty methods such as "Check the network", "Ask classmates", "reading" and so on all get 0 points) and analysis (from which can get what revelation, what harvest, 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.

Experimental instrument:

Name

Model

Number

Pc

1

Experiment contents, steps and experiences (attached paper):

(a) Unit testing

(1) Three kinds of code

Programming is intellectual activity, not typing, what to do before programming, how to do to think clearly to write the program, write well. With a lot of students at present, a program to open the editor to write code, I hope that students develop a habit, when you want to solve problems with the procedure, you will write three kinds of code:

  • Pseudo code
  • Product Code
  • Test code
  • (2) TDD (test driven devlopment, testing-driven development)

  • (ii) Object-oriented three elements

    • + indicates public
    • #表示 protected
    • -Indicates private
    • (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

1, the use of TDD design off the implementation of the plural class complex.

(1) Pseudo-code

Plural class

Complex number = Real part + complex PART I

Sum of complex numbers = (real part added) + (sum of complex parts) I

Subtract the same truth;

Print:

Imaginary part greater than 0: "real" + "+" + "imaginary part" + "I"

Imaginary part less than 0: "real" + "imaginary part" + "I"

The imaginary part is 0: "The real part"

(2) Product Code

Complex print, add, subtract

public class Complex {

private int sh,xu;

Complex () {

this.sh=0;

this.xu=0;

}

Complex (int sh) {

This.sh=sh;

this.xu=0;

}

Complex (int sh,int Xu) {

This.sh=sh;

This.xu=xu;

}

public void Addfu (Complex p1,complex p2) {

System.out.println ("The sum of these two complex numbers is:");

this.sh=p1.sh+p2.sh;

This.xu=p1.xu+p2.xu;

Print ();

}

public void Minusfu (Complex p1,complex p2) {

System.out.println ("The difference between these two complex numbers is:");

this.sh=p1.sh-p2.sh;

This.xu=p1.xu-p2.xu;

Print ();

}

public void Outputfu () {

System.out.println ("The value of the plural is:");

Print ();

}

public void print () {

if (this.xu>0) {

System.out.println (this.sh+ "+" +this.xu+ "I");

}else if (this.xu<0) {

System.out.println (this.sh+ "" +this.xu+ "I");

}else{

System.out.println (this.sh);

}

}

}

(3) test code

2, the report of the experiment to count their own PSP (Personal software Process) time

Steps

Take

Percentage

Demand analysis

25min

18%

Design

35min

25%

Code implementation

30min

21%

Test

30min

21%

Analysis Summary

20min

15%

3. Summarize the benefits of unit testing

(1) Make it easy to modify test code without worrying about the test code that will affect the design.

(2) It is easier to find the problem at an early stage, the problem is not easy to accumulate, can be solved immediately.

Problems encountered:

When you use the Umbrello tool, the abstract of the created class cannot be displayed.

When the output is a character, you do not know how to do TDD unit testing.

Workaround:

After you create the class, forget to open the display in the Class option, tick the public only option.

The output is clearly defined and the output is judged.

Experiment two Java object-oriented programming _20135129 Li Yu Yu

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.