• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Initialize a subclass object with a base class object
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Initialize a subclass object with a base class object


  • Subject: Re: Initialize a subclass object with a base class object
  • From: "stephen joseph butler" <email@hidden>
  • Date: Tue, 20 May 2008 02:57:41 -0500

On Tue, May 20, 2008 at 1:50 AM, Liviu Andron
<email@hidden> wrote:
> setRepresentedObject: is a hint, thanks, but it doesn't resolve the problem
> either: he MUST copy every property from the original NSButtonCell (font,
> attributedTitle, imageDimsWhenDisabled, etc).

This is how you will have to do it. Or you could write a wrapper,
although NSButtonCell has a lot of methods. You'll probably want to
intimately understand NSProxy and how messages work in Obj-C.

Cocoa doesn't have a copy constructor design pattern, because one is
not generally required. This isn't that usual. Java doesn't mandate
one either.

> He could use copyWithZone (or,
> better, memcpy) , but maybe there's a pointer there, that will be used after
> some copy is destroyed :((

No, you can't use copyWithZone:. It will never do what you want.
Looking back at your code, I think you misunderstand how zones work. A
zone is not a block of memory, but a collection of regions of memory
that blocks are/can be allocated from. They're heaps.

Besides, shallow copying is only a concern if you are subclassing. If
you're using representedObject plus a bunch of category methods, then
you will never have to worry about copyWithZone. Remember,
representedObject is an ivar that NSCell is aware of. If it *didn't*
properly handle representedObject in its implementation of
copyWithZone:, then that's a serious bug of NSCell, not your code.

Still, it would probably be a good idea to make sure your
representedObject itself conforms to copyWithZone in a sane way. Also,
supporting NSCoding would be a good idea.

> My high-level goal:
>   "he wants an Objective-C equivalent to a C++ copy constructor"

You need to go a little higher. WHY do you need a C++ copy
constructor? You talk about someone modifying your nib in IB. Why is
someone doing this w/o understanding the class hierarchy of your
application?
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Initialize a subclass object with a base class object
      • From: "Liviu Andron" <email@hidden>
    • Re: Initialize a subclass object with a base class object
      • From: Nathan Kinsinger <email@hidden>
References: 
 >Re: Initialize a subclass object with a base class object (From: "Liviu Andron" <email@hidden>)

  • Prev by Date: Re: Cocoa et al as HCI usability problem
  • Next by Date: Re: Initialize a subclass object with a base class object
  • Previous by thread: Re: Initialize a subclass object with a base class object
  • Next by thread: Re: Initialize a subclass object with a base class object
  • Index(es):
    • Date
    • Thread