Learning of PHP Interfaces (Repost)

by stilling2006 on 2008-11-04 19:59:53

Most people believe that the significance of interfaces lies in replacing multiple inheritance. It is well-known that Java does not have the mechanism of multiple inheritance like C++, but it can implement multiple interfaces. Actually, this is quite a stretch. Interfaces and inheritance are entirely different things. Interfaces do not have the ability to replace multiple inheritance, nor is it their responsibility. The role of an interface, in short, is to signify the category (type) of a class. By assigning classes of different types to different interfaces, we can manage them more effectively. In my view, the essence of object-oriented programming lies in the abstraction of objects, and interfaces best embody this idea. Why do we always discuss design patterns in the context of languages capable of abstraction (such as C++, Java, C#, etc.)? It's because what design patterns essentially study is how to abstract things reasonably. (Cowboy's famous saying, "Abstraction is about removing the parts that resemble," may seem like a joke, but it contains profound truth.)