home *** CD-ROM | disk | FTP | other *** search
- 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
- From: mack@rathe.cs.umn.edu (Mack Read-Mackenzie)
- Newsgroups: comp.object
- Subject: POLYMORPHISM: (was RE:FAQ && RE:HELP:Array of different classes)
- Message-ID: <1993Jan22.160856.2402@rathe.cs.umn.edu>
- Date: 22 Jan 93 16:08:56 GMT
- Organization: Rathe, Inc.
- Lines: 19
-
- vinay> The user of this program will choose at the runtime what objects to put
- vinay> in the holder. The problem is how do i store this information (i.e the
- vinay> contents ) in class HOLDER. I cannot create a single array of objects
- vinay> because each object is of different class.
-
- woods> All things, like `pen', `eraser', `pencil' etc. share the property
- woods> that they can be put in the holder. So, define class HolderTool.
- woods> Then define subclasses of this, such as Pencil, Pen and Eraser. Then
- woods> one's holder is simply an array of HolderTool instances.
-
- This is a classic example in polymorphism in action. A variety of distinct
- yet related objects can be handled by one set of code. The trick is to extract
- what is similar among all of the objects into an abstract base class, from
- which each of the unique objects will inherit. The code which needs to deal
- with their commonality will treat each of the unique objects as a member of
- the base class. (Just what John Woods said above). To the guys arguing over
- the FAQ: what is so hard to understand or define about polymorphism anyway?
-
- I don't mean to be rude, but this seems pretty simple...
-