<P>I have made an instance instead of inheritence.&nbsp; when i try to print using transcript show it display all the objects only the last one.&nbsp; Is there a way for me to return every single object in the instance using transcript show:
<P>&nbsp;<B><I>"Richard A. O'Keefe" &lt;ok@cs.otago.ac.nz&gt;</I></B> wrote:
<BLOCKQUOTE style="BORDER-LEFT: #1010ff 2px solid; MARGIN-LEFT: 5px; PADDING-LEFT: 5px">Janet Abdul-Karim <JN_KARIM@YAHOO.COM>wrote:<BR>I created a subclass to ordered collections.<BR><BR>Unless you are inventing a new kind of collection data structure,<BR>you probably don't want to do that.<BR><BR>We could have hours of fun debating whether a portfolio<BR>*is* a collection of accounts or *has* a collection of<BR>accounts, but the simplest way to look at it may be this:<BR>If your class INHERITS from Collection, then<BR>(a) you have the obligation to make sure that all of the methods<BR>in the interface of Collection WORK for your class, or are<BR>explicitly cancelled. Collection is pretty big in Squeak,<BR>you probably don't want to do that.<BR>(b) you inherit EVERYTHING from Collection, including methods<BR>that change the object in ways you probably don't want to<BR>happen.<BR><BR><BR>I am trying to add objects to the new class<BR><BR>Presumably you mean "add objects to AN INSTANCE OF the new class".<BR><BR>and then print it to make sure they are in there.<BR><BR>Good.<BR><BR>I add one object it prints but when I add another object and<BR>print it only prints the first object i added<BR><BR>sample code to add to list.<BR><BR>account: aAccount<BR>"Add an account to the portfolio"<BR><BR>self isNil ifTrue:[self add: aAccount]<BR>ifFalse:[ self addLast: aAccount].<BR><BR>The only object for which 'self isNil' can ever be true is nil.<BR>nil is the unique instance of UndefinedObject.<BR>nil is NOT an instance of your class.<BR>Your code can be simplified to<BR><BR>addAccount: anAccount<BR>self addLast: anAccount.<BR><BR>code to print list. <BR><BR>accounts<BR>"Returns the accounts for the portfolio"<BR><BR>self do:[:element|^element number].<BR><BR>(1) That code doesn't print anything.<BR>(2) Did you notice that little caret in there?<BR>What your code says is<BR>"For each element in myself<BR>RETURN the element's number STRAIGHT AWAY RIGHT NOW!<BR>(and don't look at any other elements)."<BR><BR>This is almost the same as<BR>^self first number<BR><BR>Change the code to<BR><BR>accountNumbers<BR>"Answer the account numbers of all the accounts<BR>in the portfolio."<BR>^self collect: [:each | each number]<BR><BR></BLOCKQUOTE><p><br><hr size=1>Do you Yahoo!?<br>
<a href="http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com">Yahoo! Mail Plus</a> - Powerful. Affordable. <a href="http://rd.yahoo.com/mail/mailsig/*http://mailplus.yahoo.com">Sign up now</a>