Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!yale!mintaka!bloom-beacon!eru!luth!sunic!mcsun!ukc!icdoc!sot-ecs!sra From: sra@ecs.soton.ac.uk (Stephen Adams) Newsgroups: comp.object Subject: inheritance and `type loss' Message-ID: Date: 10 Jul 90 14:56:06 GMT Sender: sra@ecs.soton.ac.uk Distribution: comp Organization: Southampton University Computer Science Lines: 35 This might be a naive question, but it has been puzzling me for a while. Consider the class integer. This class supports two methods: + which takes another integer and returns the sum image which returns a string denoting the integer as a decimal number so 2+4 -> 6 and (6).image -> "6" Suppose I create a subclass called roman. I provide a new method called image which returns roman numerals e.g. roman_6.image -> "VI". The + operation is inherited from integers. I declare the following variable and initialize it V:roman := make a roman with the value 5 I have two questions: (a) what should (V+V).image yield? "10" or "X"? (V+1).image "6" or "VI"? (1+V).image "6" or "VI" or error (in +)? (b) what do various object oriented systems actually do? If V+V is not a roman (but an integer, 10) then some information has been lost. This might be reasonable but it does seem surprising. -- Stephen Adams S.Adams@uk.ac.soton.ecs (JANET) Computer Science S.Adams@ecs.soton.ac.uk (Bitnet) Southampton S09 5NH, UK S.Adams@sot-ecs.uucp (uucp)