From: Rob McDonald on
I started a thread in comp.lang.java.programmer a while ago about this
general topic (subject: Interface Delegation or ??). I am starting
this thread in comp.object to try to get a more abstract/general
discussion.

In a 'normal' inheritance hierarchy, the superclass is most general,
and inheritance is used to form a specialized subclass.

For example, we could have a class Segment used to represent a finite-
length curve in space. Subclasses of Segment could straight-line
segments, quadratic segments, or spline segments. It may be
appropriate to have different specialized classes for 2D vs 3D
segments.

So far, everything is normal.

I would like to inherit another layer, but instead of specializing
further, I would like to bring things back together. My structure
goes something like general to specialized and back to general.

Does this have a name? Is it a design pattern? What are the syntax
idioms for this sort of thing?

An Edge is-a Segment, but it has connectivity information in the form
of a list of generalized polygons (Poly) which it helps build. I
would like to code up a single implementation of Edge, but be able to
have it inherit from any specialized form of Segment.

I am working in Java, so I have accomplished this through interfaces
and interface delegation. I think the following 'cartoon' should get
the point across.

interface ISegment {}
class StraightLineSegment implements ISegment{}
class SplineSegment implements ISegment{}

interface IEdge extends ISegment{}

class DefaultEdge implements IEdge{
protected ISegment s;
DefaultEdge(ISegment s){
this.s=s;
}
// Delegate ISegment interface to this.s
}

IEdge e1 = new DefaultEdge(new SplineSegment());
IEdge e2 = new DefaultEdge(new StraightLineSegment());

I would like to use this structure throughout my library. For
example...

IPoint // A Point is a set of coordinates, x,y or x,y,z, or r,theta,
etc.
Point2D, Point3D, PointPolar2D, ArrayPoint3D, PointDouble3D,
PointBigDecimal3D, etc.
IVertex extends IPoint
A Vertex includes connectivity information as a list of Segments it
belongs to.
ISegment // A Segment is a collection of Vertex's
StraightLineSegment, QuadraticSegment, SplineSegment
IEdge extends ISegment
A Edge includes connectivity information as a list of Polys it
belongs to
IPoly // A generalized polygon, a list of Segments
Tri, Quad, NGon
IFace extends IPoly
A Face includes connectivy information as a list of Surfaces it
belongs to
ISurface // A surface, a collection of Faces
ListSurf, HashSurf, ArraySurf, etc.

Any help is appreciated.

Rob

From: Daniel T. on
Rob McDonald <rob.a.mcdonald(a)gmail.com> wrote:

> I started a thread in comp.lang.java.programmer a while ago about this
> general topic (subject: Interface Delegation or ??). I am starting
> this thread in comp.object to try to get a more abstract/general
> discussion.
>
> In a 'normal' inheritance hierarchy, the superclass is most general,
> and inheritance is used to form a specialized subclass.
>
> For example, we could have a class Segment used to represent a finite-
> length curve in space. Subclasses of Segment could straight-line
> segments, quadratic segments, or spline segments. It may be
> appropriate to have different specialized classes for 2D vs 3D
> segments.
>
> So far, everything is normal.
>
> I would like to inherit another layer, but instead of specializing
> further, I would like to bring things back together. My structure
> goes something like general to specialized and back to general.
>
> Does this have a name? Is it a design pattern? What are the syntax
> idioms for this sort of thing?
>
> An Edge is-a Segment, but it has connectivity information in the form
> of a list of generalized polygons (Poly) which it helps build. I
> would like to code up a single implementation of Edge, but be able to
> have it inherit from any specialized form of Segment.
>
> I am working in Java, so I have accomplished this through interfaces
> and interface delegation. I think the following 'cartoon' should get
> the point across.
>
> interface ISegment {}
> class StraightLineSegment implements ISegment{}
> class SplineSegment implements ISegment{}
>
> interface IEdge extends ISegment{}
>
> class DefaultEdge implements IEdge{
> protected ISegment s;
> DefaultEdge(ISegment s){
> this.s=s;
> }
> // Delegate ISegment interface to this.s
> }
>
> IEdge e1 = new DefaultEdge(new SplineSegment());
> IEdge e2 = new DefaultEdge(new StraightLineSegment());

Sounds like the Bridge pattern to me. The Abstraction is the IEdge and
the Implementor is ISegment.
From: Rob McDonald on
On Dec 30, 11:08 am, "Daniel T." <danie...(a)earthlink.net> wrote:
> Sounds like the Bridge pattern to me. The Abstraction is the IEdge and
> the Implementor is ISegment.

Daniel,

I think you're right. Thanks for the help.

I found the following discussion helpful.
http://www.vincehuston.org/dp/bridge.html

It also looks like I'm implementing this with the 'right' idiom.
(Using aggregation with interface delegation.)

Thanks,

Rob
From: Rob McDonald on
On Dec 30, 1:32 pm, Rob McDonald <rob.a.mcdon...(a)gmail.com> wrote:
> On Dec 30, 11:08 am, "Daniel T." <danie...(a)earthlink.net> wrote:
>
> > Sounds like the Bridge pattern to me. The Abstraction is the IEdge and
> > the Implementor is ISegment.
>
> Daniel,
>
> I think you're right. Thanks for the help.
>
> I found the following discussion helpful.http://www.vincehuston.org/dp/bridge.html
>
> It also looks like I'm implementing this with the 'right' idiom.
> (Using aggregation with interface delegation.)
>

Actually, it looks like the Bridge pattern is part of the solution,
but not all of it. The Bridge pattern does not require the interface
delegation I use to establish the IEdge is-a ISegment relationship.

However, the Bridge pattern does directly address the combinatorial
explosion problem I was going to have if I progressed with a pure
inheritance model.

Rob