From Java small example to programming for (oriented) interfaces

Source: Internet
Author: User

Code similar to the following is often used in Java programming,

New Arraylist<string> ();

Just know that this is polymorphic, like a specification and somehow.

Programming for a supertype (parent class), which means that the declared type of a variable (or the return type of the method) is a supertype, not a specific subclass. The specific implementations of each method in the superclass are not in the superclass, but in each subclass. This allows you to perform a real (one subclass) behavior based on the actual condition when the program executes. The benefit is that when declaring a variable, we don't have to worry about what the actual data type is (a subclass type) at the time of execution, which is the idea of decoupling (loose coupling). We can replace the declared variable at any time after we maintain it with the type that really needs to be executed, if in the above code when want to swap with LinkedList to implement this function, the other code does not change, only need to change this line, because the interface declares the method that the subclass common. It has high maintainability and scalability. So in fact, we can also change the phrase: "For the Super Type Programming", the super-type is usually an interface or an abstract class.

In fact, this is for interface programming (Interface-oriented programming), which separates the design from the implementation. In an object-oriented system, the various functions of the system are accomplished by many different objects. In this case, it is not so important for the system designers to implement their own internal objects, but the collaboration between the objects becomes the key of the system design. Small to different classes of communication, large to the interaction between the modules, at the beginning of the system design is to focus on, which is the main work of the system design.

More specific explanations refer to: http://toyota2006.iteye.com/blog/25232?yyue=a21bo.50862.201879

From Java small example to programming for (oriented) interfaces

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.