Java Fundamentals-Interfaces & Simple Factories

Source: Internet
Author: User

Statement: The material used in this column is written by the VIP students of the Kay Academy, who has the right to be anonymous and has the final right to interpret the article; The Edith Academy is designed to promote students to learn from each other on the basis of public notes.

A Interface
1. The interface only makes the specification and the declaration does not do the realization;
2.java class can only be single inheritance, not multiple inheritance, but the interface can inherit more;
3. Interface do not look from the function, do not feel that the interface will bring the function of ascension, can only be seen from the design perspective, from a long-term perspective, to bring us the norm, so that we better face the parent class programming, which is the interface charm.

4. An interface is a class, which is an abstract class that is still a class file after compilation. Writing is also a pure abstract class to be written.

5. Inheritance issues for interfaces

Interfaces may not inherit classes or abstract classes;
Interfaces can inherit more interfaces.
6. Classes can implement interfaces, but interfaces cannot inherit classes.

In order, the inheritance is in front, and the interface is placed behind.
To implement multiple interfaces, you simply need to separate the interfaces and interfaces with commas (,).
7. From the design point of view: Everything is the interface.
Do not rely on the implementation of the class, easy to expand and upgrade, we need to be very easy to upgrade and extension, so we want to interface programming, that is, to the parent class programming, let the implementation of the class to implement these methods, and then use these implementation classes can be.

8. Note
The interface must be programmed for interface applications.
is to apply for the interface a bit to interface programming, it is equivalent to the parent class programming.

Two Simple Factory design mode

1. Create design mode;
2. Also to create objects;
3. The purpose is to hide the implementation class and not be discovered.

4. Examples:

This function can achieve the purpose of upgrading.

If the interface with the factory, will be written on the interface called the product interface, created here is the conductor products, we have to do is to be sure to hide the object is not seen by others, if people find it can not be called the factory method.
The purpose of the factory is to hide object creation, the reason for hidden objects is to change the subclass very well, to modify the sub-class very well!!!!

Java Fundamentals-Interfaces & Simple Factories

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.