home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / object / 5018 < prev    next >
Encoding:
Internet Message Format  |  1993-01-23  |  1.5 KB

  1. Path: sparky!uunet!paladin.american.edu!howland.reston.ans.net!sol.ctr.columbia.edu!The-Star.honeywell.com!umn.edu!kksys.com!wd0gol!rathe!mack
  2. From: mack@rathe.cs.umn.edu (Mack Read-Mackenzie)
  3. Newsgroups: comp.object
  4. Subject: POLYMORPHISM: (was RE:FAQ && RE:HELP:Array of different classes)
  5. Message-ID: <1993Jan22.160856.2402@rathe.cs.umn.edu>
  6. Date: 22 Jan 93 16:08:56 GMT
  7. Organization: Rathe, Inc.
  8. Lines: 19
  9.  
  10. vinay> The user of this program will choose at the runtime what objects to put
  11. vinay> in the holder. The problem is how do i store this information (i.e the
  12. vinay> contents ) in class HOLDER. I cannot create a single array of objects
  13. vinay> because each object is of different class.
  14.  
  15. woods> All things, like `pen', `eraser', `pencil' etc.  share the property
  16. woods> that they can be put in the holder.  So, define class HolderTool.
  17. woods> Then define subclasses of this, such as Pencil, Pen and Eraser.  Then
  18. woods> one's holder is simply an array of HolderTool instances. 
  19.  
  20. This is a classic example in polymorphism in action.  A variety of distinct
  21. yet related objects can be handled by one set of code.  The trick is to extract
  22. what is similar among all of the objects into an abstract base class, from
  23. which each of the unique objects will inherit.  The code which needs to deal
  24. with their commonality will treat each of the unique objects as a member of
  25. the base class.  (Just what John Woods said above).  To the guys arguing over
  26. the FAQ: what is so hard to understand or define about polymorphism anyway?
  27.  
  28. I don't mean to be rude, but this seems pretty simple...
  29.