Previous people planting trees

zhaozj2021-02-16  48

This mode may be the simplest mode. Because almost all object-oriented languages ​​support abstraction

Because. This is an object-oriented basic law. And the template mode defines an algorithm in an operation.

The skeleton, and some steps are delayed into subclasses, which is clear. It is used to use abstract classes. So almost

Needless to introduce something. But consider writing all 23 modes, or write one.

Although it is simple. But common. It is also very common.

If we want to design a container. The style of the container cannot be determined in advance, but it can be determined that the container is used.

Water. It is obvious that water can be determined. And the style of the container must be placed in the subclass.

// Abstract class Public Abstract Class Container {// Style We can't determine public abstract void containerStyle (); // in advance (//); 装 水 水 .writeLine ("Water"); }

// Sublayer delay

Public Class Glass: Container {Override Public Container {Override Public ContainerStyle () {Console.WriteLine ("Round");}}

Also pay attention to it. It is necessary to delay the talented to the subclass. Otherwise, there is no need. So now

It is clear. The difference between abstraction and interface. The interface cannot be done. Because the interface does not implement any

operating.

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

New Post(0)