Object-oriented is actually an interface (1) - interface 1

xiaoxiao2021-03-06  107

For different classes of some have the same action name (the action implementation process is not necessarily the same, the action is the method), one interface can be implemented, by calling the interface method, to achieve different specific exercises

At this time, this interface object must have the above object being implemented.

public interface InterfaceA {public void mothedA () {} public void mothedB () {}} public class ClassA implements InterfaceA {public void mothedA () {// embodied} public void mothedB () {// embodied}

} public class classb imports interfacea {public void motheda () {// concrete implementation} public void mothedb () {// concrete implementation}

} public class classtest {public void run (interfacea a) {a.motheda (); A.MOTHEDB ();}}

The RUN method does not have to consider the transmission of the parameters is the instance of class A or the instance of class B, even in the future, any instance of Interfacea, improves the scalability of the program and maintainability.

转载请注明原文地址:https://www.9cbs.com/read-103187.html

New Post(0)