[Java] BigData basis _ Interface

Interface concept

Java interface is a declaration of a series of methods, is a collection of some of the features of the method, an interface features not only the method of implementation, so these methods can be implemented in different classes in different places, but these implementations can have different behavior ( function) .

The following is a personal understanding:

In the software development process, when we develop a large-scale project, probably a lot of people together to develop a project, but the whole project is divided into many modules, we can not follow the order to develop modules, etc. A team developed the test is completed the first module , B team began to develop a second module, so, if team a delay occurs, it will affect the progress of the development of the entire project, so this serial development approach does not work, then we can develop in parallel, to I want to do parallel development, the development team when B assume a team has developed well, this time on the introduction of the interface. A B is a give output, B line developed on the basis of this result.

Code

FIG code structure:

 

Package cn.test.logan.day07; 

Import the java.util.HashMap; 

public  class ServiceTest {
     public  static  void main (String [] args) {
         // oriented programming interface can be referenced with "Interface Variable Type" "specific implementation object "
         // in this way, at the time of software development, you can develop your own business logic code before the call to achieve
         // ServiceDemo service = null; 
        
        // after the class that implements the interface development is completed, the interface to the class object for the realization of variable assignment you can, write the following code will work without modification 
        ServiceDemo Service = new new ServiceImpl (); 
        
        // Step1 method is called 
        String str = service.Step1 (); 
        System.out.println (str); 
        
        // call the Step2 method of 
        service. step2 ( "Logan"); 
        
        // Step3 method is called 
        HashMap <Integer, String> hashmap = service.Step3 (1, " I am Step3" ); 
        System.out.println (HashMap.get ( 1 )); 
    } 

}
ServiceTest.java
Package cn.test.logan.day07; 

Import the java.util.HashMap; 

/ ** 
 * only interface method definitions, there is no method to achieve 
 * Therefore, the interface can not be instantiated 
 action * interface: is used in the business achieve a functional specification and defined between the caller 
 * @author QIN 
 * 
 * / 
public  interface ServiceDemo {
     public String Step1 ();
     public  void Step2 (String name);
     public the HashMap <Integer, String> Step3 ( int a, B String) ; 
}
ServiceDemo.java
Package Penalty for cn.test.logan.day07; 

Import java.util.HashMap; 

/ ** 
 * implementation class to establish contact with the interface via Implements keyword 
 * in the implementation class must be defined in the interface method to achieve full 
 * In addition, addition to the methods defined in the interface, additional methods may be defined in the implementation class 
 * before implementation @Override plus sign indicates that the implementation class of the method, when implemented in Eclipse name and method class interface when the method name inconsistency error occurs 
 * @author QIN 
 * 
 * / 
public  class ServiceImpl the implements ServiceDemo { 

    @Override 
    public String Step1 () {        
         return "I am Step1" ; 
    } 

    @Override 
    public  void Step2 (String name) { 
        System .out.println ("我是Step2,我的名字是:"+name);
        
    }

    @Override
    public HashMap<Integer, String> Step3(int a, String b) {
        HashMap<Integer, String> hashmap = new HashMap<Integer, String>();
        hashmap.put(a, b);
        return hashmap;
    }

}
ServiceImpl.java

 

Guess you like

Origin www.cnblogs.com/OliverQin/p/12088537.html