home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / sys / mac / oop / misc / 83 < prev    next >
Encoding:
Text File  |  1992-12-13  |  2.5 KB  |  59 lines

  1. Newsgroups: comp.sys.mac.oop.misc
  2. Path: sparky!uunet!destroyer!gumby!kzoo!k044477
  3. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  4. Subject: Re: The Member Function: Spawn Of Satan?
  5. Message-ID: <1992Dec13.161514.25723@hobbes.kzoo.edu>
  6. Summary: member(member, Satans_spawn)?
  7. Organization: Kalamazoo College
  8. References: <1992Dec13.144549.24447@reed.edu>
  9. Date: Sun, 13 Dec 1992 16:15:14 GMT
  10. Lines: 47
  11.  
  12. orpheus@reed.edu (P. Hawthorne) writes:
  13. >It seems un-structured. What would Djikstra say?
  14.  
  15. I find myself using member() in the TCL for three chief purposes:
  16.  
  17. 1]  ASSERTs.  It's handy to make sure something is what you expect.
  18. 2]  In CCollaborators' ProviderChanged() method, testing whether the
  19. provider that changed is of a certain type.  (For non-TCLers,
  20. CCollaborator is a class whose instances can DependUpon() each other;
  21. whenever a CCollaborator calls BroadcastChange(), all itsDependents
  22. get their ProviderChanged() method called.  Very handy, but to design a
  23. flexible system, a CCollaborator has to expect to get lots of unwanted
  24. ProviderChanged() messages.)
  25. 3]  In methods that, I suspect, would be called "friend" under C++.
  26. Think C doesn't give you a way to link a bunch of classes together and
  27. say "only these classes are friends of mine, and only my friends can
  28. call the following methods."  (Is that essentially what C++ does?)
  29. So you have to fake it with run-time checking on your own.
  30.  
  31. >When I use it...I worry that perhaps a seriously
  32. >abstract class variable could formalize whatever notions are at work. Or I
  33. >think that it is a kludge so that I can put off a total overhaul until I
  34. >figure out how to work in the exceptional classes.
  35.  
  36. If you write, for example,
  37.  
  38. void CEatingObject::eatObject(CFoodObject *theFoodObj)
  39. {
  40.     if (member(theFoodObj, CBanana)) gobbleBanana();
  41.     else if (member(theFoodObj, CCookie)) munchCookie();
  42.     else if (member(theFoodObj, CSquid)) slurpSquid();
  43. }
  44.  
  45. ...then you're misusing member().  (In this case, the eating method
  46. should go into CFoodObject, not CEatingObject, and should be overridden
  47. by all those subclasses.)
  48.  
  49. If Think C's lack of multiple inheritence forces you to construct a dual
  50. class hierarchy, I can see having to misuse member(), as a consequence.
  51.  
  52. But otherwise, unless you're doing something like CEatingObject, I
  53. wouldn't worry about it.
  54. -- 
  55.  Jamie McCarthy      Internet: k044477@kzoo.edu      AppleLink: j.mccarthy
  56.  "Apple developers will still have access to System 7.1 through the
  57.   monthly Developer CD series, but they may use it only for testing
  58.   and development purposes."              - AppleDirect, Nov/Dec 92
  59.