Recently to find an internship, began to review javase

Source: Internet
Author: User

Abstract classes and Interfaces
What is an interface: An interface is a collection of method features------interfaces are abstractions of abstractions.
What is an abstract class: An abstract class that implements a partial implementation of a specific type------abstract class is a concrete abstraction.
Method features include: The name of the method, the number of arguments, and the type of the parameter. Not included: return type, Parameter name, and thrown exception.
An interface is a precondition for type conversion and a guarantee of dynamic invocation. A type conversion (multiple inheritance) is accomplished by implementing an interface, and the dynamic invocation only cares about the type and does not care about the specific class.
--------------------------------------------------------------------------------------------------------------- -----------------------
The Java Interface (abstract class) is used to declare a new type.
Java designers should primarily use interfaces and abstract classes to decouple software units from internal and external.
In other words, you should use Java interfaces and abstract classes instead of concrete classes to declare variables, type declarations of parameters, return type declarations of methods, conversions of data types, and so on.
Of course, a better approach would be to use only interfaces, not abstract classes, to do these things.
Ideally, a specific class should implement only the methods declared in the interface and the abstract class, and should not give redundant methods!
Interfaces and abstract classes are generally used as a starting point for a type hierarchy.
Interfaces are more abstract than abstract classes, so it's preferable to declare abstract types with interfaces!
--------------------------------------------------------------------------------------------------------------- -----------------------
Abstract classes and Interfaces
Abstract classes provide only a partial implementation of a class. An abstract class can have an instance variable, and one or more constructors. Abstract classes can be both abstract and concrete methods.
An abstract class does not have an instance, and its constructors cannot be used by clients to create instances. The constructor of an abstract class can be called by its subclasses, so that all subclasses of an abstract class can have some common implementations, and different subclasses can have different implementations on this basis.

Interfaces are more abstract than abstract classes, so wired uses interfaces to declare abstract classes!
Abstract classes are used for inheritance. (The specific class is not inherited, "as long as it is possible not to inherit from a specific class---Scott Meryes").
Abstract class design principles:
1. Abstract classes should have as much code as possible! (Common method). The code concentrates on the direction of the abstraction.
2. Abstract classes should have as little data as possible! (Public properties). The data is concentrated in a specific direction.
Use conditions for inheritance reuse-------Peter coad conditions
1. Subclasses are a special kind of superclass rather than a super-class character! Correctly distinguish the relationship between "has-a" and "is-a".
2. There should be no substitution between subclasses!?
3. Subclasses have the responsibility to extend the superclass, rather than the responsibility of displacing (Override) off or unregistering (nullify) out.
4. Inheritance can only be used if it is taxonomic and not inherited from a specific class.
The difference between an interface and an abstract class:
1. Abstract classes can provide implementations of certain methods. If you add a new, concrete method to an abstract class, all of the subclasses get this method in a single swoop. Interface does not do this! (This may be the only advantage of an abstract class).
2. Because of Java's single-root structure limitation, only one class can implement an abstract class type, and the interface type has no such restriction. This causes the abstract class to lag behind the interface as a type definition tool. An interface is an ideal tool for defining a mixed type, which implements multiple from inheritance: with a
3. From the point of view of code refactoring, it is easy to refactor a specific class into an interface implementation.

Recently to find an internship, began to review javase

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.