From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=BAYES_05,REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,63a41ccea0fc803a X-Google-Attributes: gid103376,public From: "John G. Volan" Subject: Re: Naming of Tagged Types and Associated Packages Date: 1998/09/04 Message-ID: <35F0CAF2.9B447FD2@sprintmail.com> X-Deja-AN: 388078502 Content-Transfer-Encoding: 7bit References: <6qfp80$p0u$1@nnrp1.dejanews.com> <35CD0A8E.21D64380@sprintmail.com> <35CEBAAF.B9B82820@sprintmail.com> X-Posted-Path-Was: not-for-mail Content-Type: text/plain; charset=us-ascii X-ELN-Date: Fri Sep 4 22:23:31 1998 Organization: EarthLink Network, Inc. Mime-Version: 1.0 Reply-To: johnvolan@sprintmail.com Newsgroups: comp.lang.ada Date: 1998-09-04T00:00:00+00:00 List-Id: Matthew Heaney wrote: > > "John G. Volan" writes: > > > But you see, you diverted the poor guy off onto a tangent. What if he > > had responded, "Why, it's a color of anything that can _be_ colored, > > not just the color of a car. In short, "Color" is an abstraction all > > its own, in a module of its own that is all about colors. > > No. I was talking specifically about the color attribute of a car > abstraction. You have no guarantee that a car abstraction can have all > possible values for color. Hence, Car_Color. Look, I provided you with one puzzle to solve, but you insist on solving a different one, one that's easier for you to fit into your scheme. Okay, fine, but how about solving my puzzle, too? What if -- what if -- you were presented with a problem domain where there are cars, and there are colors, and there are other things that can have colors, and any car can get any of the colors? For me, if I were coding in Ada, it would be simple: with Percentages; use Percentages; package Colors is type Color_Type is ... private; ... function Make_Color (Red_Percentage : Percentage_Type; Green_Percentage : Percentage_Type; Blue_Percentage : Percentage_Type) return Color_Type; ... Red : constant Color_Type; Green : constant Color_Type; Blue : constant Color_Type; White : constant Color_Type; Black : constant Color_Type; ... end Colors; with Colors; use Colors; ... package Cars is type Car_Type is ... private; ... function Get_Color (Car : in Car_Type) return Color_Type; procedure Paint (Car : in out Car_Type; Color : in Color_Type); ... private type Car_Type is ... record ... Color : Color_Type; ... end record; end Cars; package body Cars is ... function Get_Color (Car : in Car_Type) return Color_Type is begin return Car.Color; end Get_Color; procedure Paint (Car : in out Car_Type; Color : in Color_Type) is begin ... Car.Color := Color; ... end Paint; ... end Cars; -- Usage: with Cars; use Cars; with Colors; use Colors; ... Car : Car_Type; ... Paint (Car, Color => Blue); ... In Java, it would be even simpler: public class Color { public Color(Percentage redPercentage, Percentage greenPercentage, Percentage bluePercentage) { ... } public static final Color RED = ... ; public static final Color GREEN = ... ; public static final Color BLUE = ... ; public static final Color WHITE = ... ; public static final Color BLACK = ... ; ... } public class Car { private Color color; public Color getColor() { return color; } public void paint (Color newColor) { ... color = newColor; ... } ... } // Usage: ... Car car = new Car(...); ... car.paint(Color.BLUE); ... And in Eiffel it would also be simpler: expanded class COLOR creation make feature {NONE} make (redPercentage: PERCENTAGE; greenPercentage: PERCENTAGE; bluePercentage: PERCENTAGE) is do ... end ... end -- class COLOR class COLOR_CONSTANTS feature ... Red: COLOR is once ... end Green: COLOR is once ... end Blue: COLOR is once ... end White: COLOR is once ... end Black: COLOR is once ... end ... end -- class COLOR_CONSTANTS class CAR creation make feature ... color: COLOR -- note: no need for a get_color function, clients -- already see attributes as functions (read-only) -- due to principle of Uniform Access paint (new_color: COLOR) is do ... color := new_color ... end ... feature {NONE} make (...) is do ... end end -- class CAR -- Usage: ... inherit COLOR_CONSTANTS ... car: CAR; ... !!car.make(...) ... car.paint(Blue) ... Now, Matt, given the above, would you still insist that there had to be a "Car_Color" type somewhere? -- indexing description: "Signatures for John G. Volan" self_plug: "Ex Ada guru", "Java 1.1 Certified", "Eiffelist wannabe" two_cents: "Java would be even cooler with Eiffel's assertions/DBC, % %generics, true MI, feature adaptation, uniform access, % %selective export, expanded types, etc., etc..." class JOHN_VOLAN_SIGNATURE inherit SIGNATURE invariant disclaimer: not (opinion implies employer.opinion) end -- class JOHN_VOLAN_SIGNATURE