RE: [GD-General] Re: Simulating constrained genericity in C++
Brought to you by:
vexxed72
From: Patrick M D. <pa...@wa...> - 2001-12-27 17:49:53
|
On Wed, 26 Dec 2001, Brian Hook wrote: > >When a language relies on inheritence for subtyping relationsips, then > >additional effort is required when an interface is created after a > >particular implementation is coded. > > Can you give an example of this? Sure, here is the initiale code in Java (or something fairly close, I'll probably get the syntax wrong): interface point3d { public float x(); public float y(); public float z(); } class point3d_impl implements point3d { ... } Now somebody has written some code that only works on 2d points, like so: public int dist(point2d p1, point2d p2) where point2d has the expected interface definition. Can we pass objects of type point3_impl to this method? If inheritence defines subtyping (with the implements keyword being a form of inheritence) then one cannot. If names and their types define the subtyping relationship then this is perfectly legal. This isn't the best motivating example, but it should be easy enough to understand the principle. Patrick |