Why do Design Patterns say that "two objects of the same type only need to separate part of their interfaces"?

On page 13 in the GoF book there is an instruction:

Two objects of the same type need only share parts of their interfaces. 

I'm not sure I understand this sentence.

EDIT : A full quote can really help to understand what

Type is the name used to indicate a specific interface. We are talking about an object that is of type "Window" if it accepts all the requests for the operation defined in the interface called "Window". An object can have many types and different objects can share a type. A part of an object interface can be characterized by one type and other parts by other types. Two objects of the same type must exchange parts of their interfaces. Interfaces may contain other interfaces as subsets.

+6
source share
3 answers

In your language, the object interface is the entire public contract of the object (do not think about implementing the language here).

The set of all signatures defined by an object is called an interface. to the object.

The type is more like what you consider a declared interface ....

A type is the name used to indicate a specific interface.

Imagine:

 public class Foo : IBar, IBaz {} public class Fuz : IBar, IBuz {} 

A Foo and Fuz are both types of IBar, but they only share this aspect of their respective interfaces.

+7
source

more complete quote:

Type is the name used to indicate a specific interface. We are talking about an object that is of type "Window" if it accepts all the requests for the operation defined in the interface called "Window". An object can have many types, and widely different objects can share a type. Part of the interface of an object can be characterized by one type and another part by other types. Two objects of the same type should share only parts of their interfaces. Interfaces may contain other interfaces, such as subsets.

and quite clearly, I think it speaks of multiple inheritance. for example, you can have TextWindow and MenuWindow both subclasses of Window along with other classes. both objects can be considered in the sense in which they are used to have a "type" Window , and both of them will perform operations associated with this type - both of them will have Window methods. but TextWindow can also be a subclass of TextEditor , while MenuWindow not, therefore their common set of methods (what they mean by "interface") do not match, although Window partially overlap.

http://www.uml.org.cn/c++/pdf/DesignPatterns.pdf

+1
source

I do not know what this means because I do not have a book. But an interface is the signature of a class method in combination with public variables. As a subtype of a certain type, is also a type of its parent class, it may have methods that it does not have on the parent, so it only shares part of the parent's interface. I have no idea if this is really what he was talking about.

-1
source

Source: https://habr.com/ru/post/896404/


All Articles