<HTML><BODY style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; ">I totally miss the point, my proposal was to have an header like this for the immutable class:<DIV><BR class="khtml-block-placeholder"></DIV><DIV><DIV>NSMutableData *seqdata;</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>- (NSData *)data;</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>the implementation:</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>- (NSData *)data {</DIV><DIV>    return seqdata;</DIV><DIV>}</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>I don't see how the underlying data could change because there are no public methods to edit the data. The compiler will beep when you do try to edit the mutabledata object outside the sequence object because the method tells you it's immutable (which it isn't in reality of course).</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>The mutable class overrides the -data method to:</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>- (NSMutableData *)data {</DIV><DIV>    return seqdata;</DIV><DIV>}</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>But perhaps there are way better approaches. I think our biggest problem is that we have kind of 2d inheritance we would like, both in the direction of mutable vs immutable, and in the direction of DNA, RNA, Protein, etc. What's the best approach to do that? This would be absolutely the biggest argument in favor of the single sequence does it all method (untyped sequence, typed by the symbolset).<BR></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV>Cheers,</DIV><DIV>Alex</DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><BR class="khtml-block-placeholder"></DIV><DIV><DIV><DIV><DIV>On 11-jul-2005, at 2:11, Charles Parnot wrote:</DIV><BR class="Apple-interchange-newline"><BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">On Jul 10, 2005, at 1:16 AM, Alexander Griekspoor wrote:</DIV> <BR><BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><snip>...Anyway, I would have no problem to make the public method return an NSData but the private property be an NSMutableData, also for the immutable sequence....<snip></DIV> <BR></BLOCKQUOTE><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">I think we should not do that. This is very dangerous. In most cases, it will go unnoticed, but in certain configurations, this is the path to very weird bugs in programs using the framework.</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Let me give you an example where that would be bad. The user implements a very rudimentary undo, simply by saving the contents of the sequence at each manipulation (let's say she does not know about the NSUndoManager!!).</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">So every time the user changes something:</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">NSData *currentSequence = [mySequence data];</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">[myMemoryStack addObject:currentSequence withKey:[NSDate date]];</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">and then later wants to go back to the sequence 2 hours ago:</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">NSData *previousSequence = [myMemoryStack objectForKey:twoHoursAgoDate];</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">oldSequence = [BCSequence sequenceWithData:previousSequence];</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Well, the data retrieved then will actually be the data corresponding to the sequence as of right now, because the pointer was actually to the actual data object in the sequence, which has been mutated since...</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">You only return a mutable object instead of a non-mutable, when you just created it on the fly, do not share it with any other object, and you are (auto)releasing it anyway and are not going to modify it.</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Of course, for performance, you could still return the muutable data object, and do a lazy copy of the data if needed, later, when:</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">* the data is asked by another object</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">* the data<SPAN class="Apple-converted-space">  </SPAN>is being modified</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">(so you need some sort of flag for that).</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV> <BR><BLOCKQUOTE type="cite"><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">But if there is a way to have the immutable bcsequence have an NSData property and the mutable version have an NSMutableData then that would be more elegant obviously...</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Cheers,</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Alex</DIV> <BR></BLOCKQUOTE><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">You can set an ivar to be NSData, but make it an NSMutableData anyway. With the proper casts, the compiler won't tell anything, and the runtime won't bother... As long as you don't call the wrong methods on the wrong type!!</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Another option to avoid the casts is to type the ivar as an 'id'. But then you don't get any compiler checking, of course,...</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">charles</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">--</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Xgrid-at-Stanford</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Help science move fast forward:</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><A href="http://cmgm.stanford.edu/~cparnot/xgrid-stanford">http://cmgm.stanford.edu/~cparnot/xgrid-stanford</A></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; ">Charles Parnot</DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; "><A href="mailto:charles.parnot@gmail.com">charles.parnot@gmail.com</A></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV><DIV style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; min-height: 14px; "><BR></DIV> <BR class="Apple-interchange-newline"></BLOCKQUOTE></DIV><BR><DIV> <P style="margin: 0.0px 0.0px 0.0px 0.0px"><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica">*********************************************************<SPAN class="Apple-converted-space"> </SPAN></FONT></P> <P style="margin: 0.0px 0.0px 0.0px 0.0px"><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica"><SPAN class="Apple-converted-space">                    </SPAN>** Alexander Griekspoor **</FONT></P> <P style="margin: 0.0px 0.0px 0.0px 0.0px"><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica">*********************************************************<SPAN class="Apple-converted-space"> </SPAN></FONT></P> <P style="margin: 0.0px 0.0px 0.0px 0.0px"><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica"><SPAN class="Apple-converted-space">              </SPAN>The Netherlands Cancer Institute</FONT></P> <P style="margin: 0.0px 0.0px 0.0px 0.0px"><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica"><SPAN class="Apple-converted-space">              </SPAN>Department of Tumorbiology (H4)</FONT></P> <P style="margin: 0.0px 0.0px 0.0px 0.0px"><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica"><SPAN class="Apple-converted-space">         </SPAN>Plesmanlaan 121, 1066 CX, Amsterdam</FONT></P> <P style="margin: 0.0px 0.0px 0.0px 0.0px"><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica"><SPAN class="Apple-converted-space">                   </SPAN>Tel:<SPAN class="Apple-converted-space">  </SPAN>+ 31 20 - 512 2023</FONT></P> <P style="margin: 0.0px 0.0px 0.0px 0.0px"><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica"><SPAN class="Apple-converted-space">                  </SPAN>Fax:<SPAN class="Apple-converted-space">  </SPAN>+ 31 20 - 512 2029</FONT></P> <P style="margin: 0.0px 0.0px 0.0px 0.0px"><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica"><SPAN class="Apple-converted-space">                  </SPAN>AIM: <A href="mailto:mekentosj@mac.com">mekentosj@mac.com</A></FONT></P> <P style="margin: 0.0px 0.0px 0.0px 0.0px"><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica"><SPAN class="Apple-converted-space">                 </SPAN>E-mail: <A href="mailto:a.griekspoor@nki.nl">a.griekspoor@nki.nl</A></FONT></P> <P style="margin: 0.0px 0.0px 0.0px 0.0px"><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica"><SPAN class="Apple-converted-space">              </SPAN>Web: <A href="http://www.mekentosj.com">http://www.mekentosj.com</A></FONT></P> <P style="margin: 0.0px 0.0px 0.0px 0.0px; min-height: 14.0px"><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica"><SPAN class="Apple-converted-space"> </SPAN></FONT></P> <P style="margin: 0.0px 0.0px 0.0px 0.0px"><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica"><SPAN class="Apple-converted-space">              </SPAN>4Peaks - For Peaks, Four Peaks.</FONT></P> <P style="margin: 0.0px 0.0px 0.0px 0.0px"><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica"><SPAN class="Apple-converted-space">       </SPAN>2004 Winner of the Apple Design Awards</FONT></P> <P style="margin: 0.0px 0.0px 0.0px 0.0px"><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica"><SPAN class="Apple-converted-space">               </SPAN>Best Mac OS X Student Product<SPAN class="Apple-converted-space"> </SPAN></FONT></P> <P style="margin: 0.0px 0.0px 0.0px 0.0px"><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica"><SPAN class="Apple-converted-space">             </SPAN><A href="http://www.mekentosj.com/4peaks">http://www.mekentosj.com/4peaks</A></FONT></P> <P style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica; min-height: 14.0px"><BR></P> <P style="margin: 0.0px 0.0px 0.0px 0.0px"><FONT face="Helvetica" size="3" style="font: 12.0px Helvetica">*********************************************************</FONT></P>  </DIV><BR></DIV></DIV></DIV></BODY></HTML>