2019/7/1 learning summary (afternoon)

2019/7/1 learning summary (afternoon)

1 JAVA part

1.1 Information hiding

In JAVA, the properties of the class are opaque, and the methods are public.
The subclass can superaccess the constructor of the parent class through statements, and can also use this method to read/write private attribute variables inherited from the parent class.
Therefore, the subclass inherits all the information of the parent class , but obtaining information from the outside regardless of whether it is the subclass or the parent class can only be achieved through specific methods (ie getter,settermethods).

1.2 this

thisThe sentence has three functions:

1.2.1 The prefix this.represents the class variable and distinguishes it from the formal parameter.

1.2.2 The prefix this.represents the class method, distinguishing it from the method of the same name.

1.2.3 this(形参1,形参2,...)can also be used to refer to the constructor.

1.3 Abstract classes and interfaces

Abstract class: its methods contain abstract methods.
The format is

public abstract class A
{
public  abstract void B();
}

Interface: A special class whose "methods" are not implemented.
The format is

public interface A
{
public void B();
}

When ordinary classes inherit abstract classes and interfaces, all methods must be implemented .

1.4 Transformation, polymorphism & decoupling, contract spirit

1.4.1 Transformation

Transformation rules:
Under normal circumstances, a child class can be transformed into a parent class (because it contains all the information of the parent class), but the parent class cannot be transformed into a child class. But when the parent class is transformed from a subclass, it can be transformed again to become the original subclass.
which is

Father object1 = new Son();//legal
Son object2 = new Father();//illegal
Son object3 = (Son) object1;//legal
/*这是针对一个具体对象而言的*/

1.4.2 Polymorphism & Decoupling

Transformation achieves polymorphism and decoupling .

Polymorphism allows a code of a program to contain different method connotations of many seed classes ;
decoupling makes it possible to reduce the "dependency" between two classes. When writing code, programmers do not need to write an object while worrying about others. Compatibility of the object with it.

1.4.3 The spirit of contract

The existence of the interface allows the subclass to have a unified specification, which is the spirit of the contract.
However, the existence of polymorphism allows each subclass to have different connotations, thus realizing both disciplined and free JAVA code.

Guess you like

Origin blog.csdn.net/qq_44065334/article/details/94410120