Re: [GD-General] Re: Simulating constrained genericity in C++
Brought to you by:
vexxed72
From: Patrick M D. <pa...@wa...> - 2001-12-27 20:14:36
|
On Thu, 27 Dec 2001, Joe wrote: > So assuming point2d was an interface too, wouldn't you > just do > interface point3d extends point2d{ > public float z(); > } > and then your old implimentation should work > Here is a more compelling example directly from the JDK. The interface AbstractCollection contains a number of methods that require more functionality than is actually required: public boolean containsAll(Collection c) public boolean addAll(Collection c) public boolean removeAll(Collection c) public boolean retainAll(Collection c) Each of these could be implemented on a class that implemented a single method (e.g. 'contains' or 'iterator'). There was a proposal to introduce additional interfaces like so: public boolean containsAll(Container c) public boolean addAll(Iterable c) public boolean removeAll(Container c) public boolean retainAll(Container c) But this was rejected because it increased the number of interfaces that were required. There's nothing the end-programmer can really do about this without breaking compatibility with the standard libraries. This kind of problem is pervasive throughout languages like Java and C++ that do not separate the notions of inheritance and subtyping. I suspect that you could find similar problems in Eiffel libraries as well. Patrick |