Student number 2017-2018-20172309 "Program Design and Data Structure" Week 8 Learning Summary

Student number 2017-2018-20172309 "Program Design and Data Structure" Week 8 Learning Summary

Textbook learning content summary

  • post binding.
    • At a certain moment of program execution, a request event may be generated, requiring the execution of a certain piece of code to complete a method call. This request event is called the binding of a method call and a method definition .
    • Normally this binding occurs at compile time, but for polymorphic references, the binding is delayed until the program runs, and the method definition to be bound depends on the object referenced by the reference variable at that time.
    • Polymorphic references can point to different types of objects over time.
    • In Java, polymorphism can be referenced in two ways: inheritance and interface.
  • Implement polymorphism in inheritance:
    • For example:

        父类: Animal    方法: sleep()、 eat().
        子类: Cow       方法: 1. sleep()     System.out.println("牛在睡觉“”);
                                                        2. eat()   System.out.println("牛在吃草”);
        子类:Sheep     方法: 1.sleep()     System.out.println("羊在睡觉”);      
                                                        2. eat()   System.out.println("羊在吃草”);
        为了显示多态性,我们可以这样产生对象 :
         Animal   function  = new  Cow();   Animal function = new Sheep();
        当使用 function.sleep();    function.eat();时
        结果为: 
                牛在睡觉
                羊在睡觉
                牛在吃草
                羊在吃草
    • In Java, a reference variable declared with a parent class can point to an object of a child class. A reference to the parent class is polymorphic if two classes have two methods with the same signature.
  • Implement polymorphism in interfaces:
    • Point: Polymorphism generated by an interface means that different classes implement the same interface in different ways, so interface variables can have multiple forms when they call back an interface method.
    • I understand it simply: all the interfaces are provided to the outside world.
    • The idea of ​​interface: such as a laptop with a USB interface.
      1. The appearance of the interface expands the function.
      2. The interface is actually the exposed rules.
      3. The appearance of the interface reduces the coupling and decoupling.
    • Knowledge points:
      1. Interface names can be used to declare object reference variables.
      2. An interface reference variable can point to any object of any class that implements the interface.
      3. The parameters of the method can be polymorphic, making the parameters accepted by the method flexible.
  • Sort:
    • Sorting is divided into selection sorting and insertion sorting .
    • Important: A sorting algorithm implemented polymorphically can sort any set of comparable objects.
    • Selection sort method: successively place each value in its final position.
    • Insertion Sort: Continuously insert a new element into a sorted subset of the sequence.
    • Comparison of sorting algorithms: There are various performance indicators when choosing an algorithm, including algorithm recommendation, efficiency and storage space requirements.
  • search:
    • Search is divided into linear search and binary search .
    • Linear search: A target is compared to each element at a time, and the target element is finally found.
    • Binary Search: Eliminate 1/2 of the options for each search until the final target element in the search.
    • Comparison of search algorithms: The choice of algorithm depends on specific conditions: Although the efficiency of binary search is significantly higher than that of linear search, the requirement of binary search is that it has been sorted.

Problems and Solving Processes in Teaching Materials Learning

  • Question 1: How should interfaces be implemented in polymorphism?
  • Problem 1 Solution: Take PP10.1 as an example:
  1. First give an interface, the format of the interface is
    so in PP10.1 it should be
  2. Interfaces should be used:
    it is worth noting that *8 should implement all methods in the interface**
  • Question 2: When sorting, I can understand if it is a set of int data, but how should I understand the sorting of names in the example?
  • Problem 2 solution:
  • Question 3: Comparison of sorting algorithms, comparison of search algorithms, what is being compared, and what is the purpose of the comparison?
    -solution:
  • Compare content:
  1. is stability. The so-called stability refers to whether two elements with equal values ​​will exchange positions before and after sorting. If no swap occurs, it is considered a stable algorithm; otherwise, it is considered an unstable sorting algorithm.
  2. is the time complexity, which refers to the length of time it takes to execute the algorithm. Simply put, it is the speed of the algorithm execution.
  3. is the space complexity, which refers to the memory size occupied by the execution algorithm.
  • Comparison of sorting algorithms:
  1. In general the simplest algorithm is often the least efficient algorithm. Because if you want the algorithm to be simple, you have to use a loop. Using a loop is an algorithm that performs a large number of repetitions and compares again and again, so it is cumbersome.personal understanding
  2. High efficiency does not necessarily mean that the algorithm is simple.
  3. Both selection sort and insertion sort have the same efficiency, and they are both n^2-order algorithms.
  4. For the same efficiency, there are other things to consider, like selection sort is easier to understand, performs fewer swap operations, etc.
  • Comparison of search algorithms:
  1. It is not necessarily necessary to select an efficient algorithm, and the choice of the algorithm depends on specific conditions.
  2. Undoubtedly, binary search is more efficient than linear search, but binary search requires sorting the data. The implementation of linear search is quite simple.

Problems and solutions in code debugging

  • Question 1: The PP10.1 requirement is to implement polymorphism with Payable. But because I don't know the interface, I can't start, but I have a general understanding of the interface after reading books and asking my classmates.
  • Problem 1 solution:

    interface Payable
    Staff employee information
    main function
  • Question 2:
  • Problem 2 Solution: XXXXXX
  • ...

code hosting

Summary of last week's exam mistakes

  • Error 1:
  • Now understand: the directive super represents a call to something in the parent class of the current class. Since there is no message, but just super(), it is a call to the superclass constructor.
  • Error 2:
  • Now understand: Java supports inheritance, but not multiple inheritance, so a Java class can have any number of children, but only one parent. Also, since all Java classes inherit directly or indirectly from the object class, all Java classes have a parent class.
  • Error 3:
  • Now understand: The term polymorphism means that a variable can take many forms. In general, Java is strongly defined that a variable, once declared as a type, can never be changed to a different type. The only exception is that a polymorphic variable can be a derived class of any type (although not at the same time a variable can be converted from one type to another).
  • Error 4:
  • Now understand: hyper-reserved words provide a mechanism to access the parent class's methods and instance data (whether they are hidden or not). Additionally, super can be used to access the superclass's constructor(s). So the correct answer is a combination of A and B which is not an option so the correct answer is e.
  • Mistake 5:
  • Now understand: A derived class can redefine any instance data or methods of the parent class. The version of the parent class is now hidden, but can be accessed by using super, just like in super. same as in x.

    Review Template:

  • Worth learning or questions from the blog:
    • xxx
    • xxx
    • ...
  • Worth learning or problems in the code:
    • xxx
    • xxx
    • ...
  • Based on the scoring criteria, I give this blog a score: XX points. The scores are as follows: xxx

Reviewed classmates blog and code

  • Pair study this week
    • 20172310
    • Pair learning content
      • XXXX
      • XXXX
      • ...
  • Last week's blog comments
  • student number 4
  • ...

    Others (perception, thinking, etc., optional)

    This chapter of polymorphism is very difficult to understand, and you may not fully understand it after reading the textbook two or three times. Only after watching the blue ink cloud class can I have a general impression, um, keep working hard! come on.

learning progress bar

Lines of code (added/accumulated) Blog volume (new/cumulative) Study time (added/accumulated) important growth
Target 5000 lines 30 articles 400 hours
the first week 075/200 1/1 05/20
the second week 560/500 1/2 13/38
The third week 972/1000 1/4 21/60
the fourth week 694/1666 1/5 21/90
fifth week 1544/3095 1/6 30/90
Week 6 600/3627 1/7 30/120

References

1. Java inheritance and encapsulation
2. Computation of common sorting algorithms
3. Interface format and application
4.

Guess you like

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