Java interface rewriting (translated from Java tutorials)

Source: Internet
Author: User


English from

Consider that you have developedDoitInterface

Public interface doit {void dosomething (int I, double X); int dosomethingelse (string S );}

Suppose you wantDoitAdd the third method, so the interface changes:

Public interface doit {void dosomething (int I, double X); int dosomethingelse (string S); Boolean diditwork (int I, double X, string S );}


If this change is made, all the old interfaces will be inherited.Doit classes all have errors because they do not fully implement this interface. Depends on this interfaceProgramMembers will protest loudly.

Try to make all the functions of your interface fully foreseen from the very beginning. This is often impossible. You may need to create more interfaces. For example, you can create a doitplus interface ExtensionDoit:

Public interface doitplus extends doit {Boolean diditwork (int I, double X, string S );}

Now, yourCodeYou can choose to continue using the old interface or upgrade to the new interface.

Related Article

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: 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.