Personal Understanding interface meaning

Source: Internet
Author: User
/* Generally, the interface is useless. You can add, delete, modify, and query an implementation class. The processed items can be divided into multiple packages. * Similar to com. user. *; COM. group. *; COM. role. *; ** the general practice is as follows: */public class sportscar {public void save (CAR) {}; public sportscar Update () {}; public int Delete () {}; public... {}} public class mailcar {public void save (car) {}; public mailcar Update () {}; public int Delete () {}; public... {}} public class synchronized ECAR {public void save (car) {}; public synchronized ECAR Update () {}; public int Delete (){ }; Public... {}... // then, when many operations are found to be identical, the interface is required. Public interface ICAR {public void save (car) throws exception; Public synchronized ECAR Update () throws exception; Public int Delete () throws exception; public... {} throws exception} public class implements ecarimpl implements ICAR {implements method... {};} public class mailcarimpl implements ICAR {implements method... {};}// the advantage of doing so is that you only need to modify the interface when restructuring the method. // If the DAO method is implemented using an interface. Public interface ipolicecardao {void save (car) throws exception;} public interface imailcardao {public int Delete () throws exception;} public class caropraeteimpl implements extends ecardao, mailcardao {public void save (car ){...} public int Delete (){...}} /** then the program can be loosely coupled */public class caropraeteservice {public imailcardao MC; Public void setmc (imailcardao MC) {This. MC = MC;} public void save (Car car) {// The save method is called here. So the specific implementation method. This class is unknown. This is what I think is the so-called loose coupling, right? // This. MC = new caropraeteimpl (); the interface is initialized in this way. This. MC. Save (CAR) ;}// this is also the case when the following action is called. Action does not know what the serviceinterface class has done. // All corresponding service interfaces can be implemented by a class. In this way, the serviceimpl implementation class will not be known when there are internal methods to process data. // Summary: interfaces are secure, loosely coupled, and easy to modify.

This is my opinion. I don't know. If you have any questions, add qq290010324.

Personal Understanding interface meaning

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.