home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / pascal / 6697 < prev    next >
Encoding:
Internet Message Format  |  1992-11-18  |  2.1 KB

  1. Path: sparky!uunet!mcsun!sun4nl!wtrlnd!contrast!postmaster
  2. From: berend@contrast.wlink.nl (Berend de Boer)
  3. Newsgroups: comp.lang.pascal
  4. Subject: Interesting design/implementation dilemma
  5. Message-ID: <722091628.F00001@contrast.wlink.nl>
  6. Date: Wed, 18 Nov 1992 08:17:46
  7. Sender: postmaster@contrast.wlink.nl
  8. Lines: 61
  9.  
  10. Hello All!
  11.  
  12. Lately when designing two objects, a printer object and a (print)job
  13. object, an interesting design dilemma happened. I could choose:
  14. 1) let the printer object accept jobs, or
  15. 2) let the job print itself on a printer
  16.  
  17. In Turbo Pascal:
  18. 1) Printer^.PrintJob(Job); or
  19. 2) Job^.Print(Printer);
  20.  
  21. It happened that I could not choose between these two designs. Turbo
  22. Pascal forced me to take the second. Here's how: I wanted the two
  23. objects in two seperate units. The printer unit could not be overlaid,
  24. but the Job unit could. The Job unit needed to use the printer unit
  25. (else how could it print) If I wrote the units this way, the first
  26. option gave me an circular reference error. To see why, here the
  27. interface sections (simplified):
  28.  
  29.  
  30. unit Printer;
  31.  
  32. interface
  33. uses Job;              {* the Job unit reference was only needed *}            
  34.  
  35.                        {* for method PrintJob                    *}
  36. type
  37.   TPrinter = object
  38.     procedure PrintJob(AJob : TJob);
  39.   end;
  40.  
  41.  
  42. unit Job;
  43.  
  44. interface
  45. uses Printer;          {* the Job unit needs the Printer unit anyway *}
  46. type
  47.   TJob = object
  48.     procedure Print(APrinter : TPrinter);
  49.   end;
  50.  
  51.  
  52. So I had to choose design 2, deleting the reference to the Job unit
  53. from the Printer unit. (I could choose design 1 but than I had to
  54. write code especially to circumvent the circular reference error). My
  55. question is: how far does a particular language (Turbo Pascal in this
  56. case) influence design? In this case implementation and design could
  57. not be seperated but had to be considered in parallel. I suppose this
  58. is very common. For example, one cannot choose a design using multiple
  59. inheritance if your language does not support it.
  60.  
  61. Any comments on this design/implementation dilemma would be greatly
  62. appreciated.
  63.  
  64.  
  65. Greetings,
  66.  
  67. Berend. (-:
  68. fido: 2:281/527.23
  69. email: berend@contrast.wlink.nl
  70.  
  71.