Programming, not (interface)

xiaoxiao2021-03-20  254

Programming, not (interface)

[Program to An Interface, Not An Implementation]

interface

The N interface is an object that is known when it is called other objects.

n An object can have multiple interfaces (actually, the interface is a subset of all methods of the object)

N-type is a specific interface of the object.

N Different objects can have the same type, and an object can have multiple different types.

n An object can only be understood by other objects through its interface.

n In a sense, the interface is in a very limited manner, "is a ..." expression as "a support for this interface."

n Interface is the key to implementing pluggability

Implement inheritance and interface inheritance

n Implement inheritance (class inheritance): An implementation of an object is defined according to the implementation of another object.

n Interface Inherit (Sub Type): Describes when an object can be used to replace another object.

The inheritance mechanism of N c is both inheritance and refers to the inheritance of the interface.

N C achieves the interface inherit by inheriting pure emptive.

n Java inherits the interface with a separate language constructor -Java interface.

n Java interface constructors are easier to express and achieve designs that focus on object interfaces.

Benefits of interface

n Advantages:

F Client does not have to know the specific class of its use of objects.

F An object can be easily replaced with another object of (realized the same interface).

The connection between F objects does not have to hardbonize (hardwire) to an object of a specific class, thereby adding flexibility.

F loosen coupling.

F adds the possibility of reuse.

F Raise the chance of (object) combination because the object being included may be any class that implements a specified interface.

n Diffility:

The complexity of F design is slightly increased.

(Translator Note: The interface represents the relationship of "..." (Likea), inherits the relationship of "... is ..." (ISA), combining the relationship of "..." "(HASA).)

Interface instance

This method refers to other classes that can be driven by vehicles without having to care about it actually (car, ship, submarine, or other object that implements imaneuverabre).

转载请注明原文地址:https://www.9cbs.com/read-130377.html

New Post(0)