ancestor to all descendant classes to extend the new abstract class, regardless of whether it is appropriate for these descendant classes.An interface is an ideal choice for defining mixed types.Interfaces allow us to construct a type framework that is not hierarchically structured. If we have two interfaces, one for singers, another for composers, in real life
In fact, there is a big difference between the two, for their choice even reflects the nature of the problem areas of understanding, the design of the intention to understand whether the correct and reasonable. This paper will analyze the differences between them and try to give developers a basis for choosing between them.
I. Understanding of abstract classes
Abstract
(){... } Void alarm (){... }}
This method violates a core principle in object-oriented design, ISP (interface segregation priciple ), in the definition of door, the inherent behavior methods of the door concept are mixed with the behavior methods of another concept "alarm. One problem is that the modules that rely solely on the door concept will change due to changes in the concept of "alarm" (for example, modifying the parameters of the alarm
using static.
Interface: this interface is used to present abstract descriptions of some special functions. It is handed over to the class implementing the interface to complete the methods in the interface.
It is easy for everyone to confuse the two. I am also the same. When I listen to the design pattern of Teacher Li Jianzhong, he often calls abstract classes as interfaces, which makes me even more confused, so I found some online materials.
I. abstract class:
Abstract classes are special classes, but they cannot be ins
implementations. ,7, abstract methods cannot be modified with static.After looking at abstract classes and abstract methods, let's look at the interface-related contentInterface Related: Interface: An interface is a special
We often encounter the difference between abstract class and interface, but today encountered an abstract interface, feel interface do not have to abstract again ah. Conclusion: This is
First, look at what is abstract class and interface Abstract class:A class that is defined as abstract cannot be instantiated. A class must be declared
Introduction to PHPOPP mechanism and mode (abstract class, interface and contractual programming ). 1. in the abstract class mechanism, a common base class is always defined, and specific details are left to the successor for impl
Java provides two mechanisms that can be used to define types that allow multiple implementations: interfaces and abstract classes. The most obvious difference between these two mechanisms is that abstract classes allow implementations of certain methods to be included, However, the interface is not allowed. A more imp
voidE ();//abstract method in Class A E } Public Abstract classB:a//because Class B inherits the abstract method E from Class A, Class B also becomes an
;age;//inherits the parent class can access the age of the parent class}function Run () {echo "will run";// }function Speakenglish () { echo "speaks English." }function Drive ($height){echo $height. " }}Interface common{ //All interface methods, the class that implements the
Everyone is easy to confuse the two, I also, in listening to the Li Jianzhong Teacher's design model, he also old to say the abstract class interface, I was more confused, so found some online information.First, abstract class:Abstract classes are special classes that cannot be instantiated, except that they have other
of the interface.
An interface is a class-like structure that can be used to declare the methods that the implementation class must declare. For example, an interface is typically used to declare an API without having to define how to implement the API.
Most developers ch
, and those members are defined as public, in addition to methods. In addition, you cannot include any other members, such as constants, fields, constructors, destructors, static members. A class can inherit directly from multiple interfaces, but only a single class (including abstract classes) is inherited directly. Third, the difference between
method E from class A, Class B also becomes an abstract class{ }public class C:b{public override void E ()//overrides the abstract method inherited from Class A. If
Interface inheritance is also called the normalization design of the program, and this kind of thing is called abstract class.So what is abstract class?Abstract class This kind of thing, can only be inherited, can not be instantia
keyword, just like defining a standard class, but all methods are empty.
All methods defined in the interface must be public, which is a feature of the interface.
An interface is a structure similar to a class and can be used to declare the methods required to implement the
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.