• 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: NSImage to JPEG file?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSImage to JPEG file?


  • Subject: Re: NSImage to JPEG file?
  • From: Alastair Houghton <email@hidden>
  • Date: Thu, 17 Jan 2019 08:05:29 +0000

On 16 Jan 2019, at 20:17, Jens Alfke <email@hidden> wrote:
>
>> On Jan 16, 2019, at 9:59 AM, Carl Hoefs <email@hidden>
>> wrote:
>>
>> But all of that would come "for free" if NSImage inherited from NSData, no?
>
> Well, that wouldn’t make sense, because an NSImage isn’t a piece of data. It
> can have multiple data representations (JPEG, PNG, PDF…) and it might not
> have any at all if it was created directly in-memory with a pixmap. It’s a
> thing that can create a data representation.

Quite.  This point is worth emphasising, actually.  A very common mistake
people make when trying to write OO programs is using inheritance where there
isn’t an is-a relationship.

NSImage definitely *is not* an NSData, and so should not inherit from it.

(Indeed, it could even have a custom NSImageRep backing it that does the
drawing on the fly; indeed, there is actually a built-in version of this in the
current version of Cocoa, where you can specify a block that gets used to
render the image whenever the system feels it’s necessary.)

This confusion isn’t helped by the fact that certain commonly used OO languages
(I’m looking at you, C++) muddy the waters by trying to use inheritance for
multiple different purposes (e.g. interfaces, typically via pure virtual
classes; mixins and the like for *implementation* purposes - which largely only
works because of multiple inheritance and/or templates, depending on how the
mixin is built).

Kind regards,

Alastair.

--
http://alastairs-place.net

_______________________________________________

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

References: 
 >Re: Cocoa-dev Digest, Vol 16, Issue 1 (From: Bruce Stephens <email@hidden>)
 >Re: NSImage to JPEG file? (From: Jens Alfke <email@hidden>)
 >Re: NSImage to JPEG file? (From: Carl Hoefs <email@hidden>)
 >Re: NSImage to JPEG file? (From: Carl Hoefs <email@hidden>)
 >Re: NSImage to JPEG file? (From: Jens Alfke <email@hidden>)
 >Re: NSImage to JPEG file? (From: Carl Hoefs <email@hidden>)
 >Re: NSImage to JPEG file? (From: Jens Alfke <email@hidden>)

  • Prev by Date: Re: NSImage to JPEG file?
  • Next by Date: Crash in terminate: on Mavericks
  • Previous by thread: Re: NSImage to JPEG file?
  • Next by thread: Re: Cocoa-dev Digest, Vol 16, Issue 1
  • Index(es):
    • Date
    • Thread