Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!cs.utexas.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!brutus.cs.uiuc.edu!ux1.cso.uiuc.edu!ux1.cso.uiuc.edu!m.cs.uiuc.edu!p.cs.uiuc.edu!johnson From: johnson@p.cs.uiuc.edu Newsgroups: comp.lang.c++ Subject: Re: Design question Message-ID: <77300051@p.cs.uiuc.edu> Date: 26 May 90 12:33:00 GMT References: <1338@calmasd.Prime.COM> Lines: 39 Nf-ID: #R:calmasd.Prime.COM:1338:p.cs.uiuc.edu:77300051:000:1611 Nf-From: p.cs.uiuc.edu!johnson May 26 07:33:00 1990 Reid Spencer wrote: > Initially, we might think of a hierarchy containing an extremely abstract > type "geo_obj" as the base of the hierarchy: > geo_obj > point > line > ray > segment > region Marshall Cline didn't like this, suggesting that ray and line were actually subtypes of segment. Rays are just segments with one end point infinitely far away, while both of the endpoints of a line are infinitely far away. Walt Peterson argued the opposite, that a line has a slope and a zero intercept, while a ray and a segment each add a constraint of an endpoint. Both points of view are valid in certain circumstances, which leads to my claim: line and segment are not subtypes of each other. Taking either point of view is too restrictive. Either class hierarchy will not be general purpose. The solution is an abstract class. A good rule of thumb is that most superclasses in a library should be abstract. Subclassing a nonabstract class is usually a little messy. It is fine for application programmers, who just want to get their job done and are not so concerned about other people having to reuse and learn their code, but it is usually a bad idea for class library designers to use it. I would have a class "AbstractLine" that defines abstract operations to return the slope, a point on the line (if any) that intersects with another line, etc. Each subclass will implement these operations differently. This will allow each subclass to have the most efficient implementation, rather than using an over general one. Ralph Johnson -- University of Illinois at Urbana-Champaign