• 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: Multiple inheritance and objective-c
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multiple inheritance and objective-c


  • Subject: Re: Multiple inheritance and objective-c
  • From: Serge Meynard <email@hidden>
  • Date: Mon, 21 Mar 2005 21:30:54 -0500

If A has nothing to do with C, yet B (a subclass of A) shares 90% of its code with C... That sounds a bit crooked to me :)
Can you have B and C both inherit from a shared class D, then have A be a subclass of B? Or simply have A and C inherit from D, and skip B altogether?


A is a class that is operated on by other classes. B is a class that groups classes of A (or B) together. Code may say "if ( [object hittest:point])". If "object" is of class "B", it passes the hittest message to each of the objects it is grouping, returning true if any of its objects have been hit (class B won't always pass through messages, but it sometimes does, as in the hittest case). Class C implements the same grouping methods as B, however it doesn't need to be treated as a class of A, nor does it need to respond to most of the methods of class A.

I COULD make C a subclass of B, which would handle all of the shared code issues. It just would also include class A, which isn't bad--just more overhead and not necessary (maybe that's not as bad of a "word" in Objective-C as it is in C++?)

Mark

I don't think a "group of object" should be a subclass of "object". Grouping other objects is a concept in itself, and it belongs separate from the objects it groups (as your dilemma demonstrates). I'd suggest trying to create a "group of" base class, that would implement the grouping behavior, then subclassing that to create concrete group classes. In terms of your examples, I'd create a class G with the shared grouping behavior, then derive A and C from G. In fact, from your description, I gather that you want a "group of A" to behave pretty much like an A from the outside. So why not make the two the same? Make A an entity that can either stand alone, or else contain a list of A's, in which case it relays its messages to the grouped objects as you describe.
Making C derive from B would be clunky, since what you want to inherit is the grouping functionality, not class A's behavior. Shared behavior belongs higher up in the inheritance chain, and specializations belong lower.


Serge


_______________________________________________ Do not post admin requests to the list. They will be ignored. Cocoa-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Multiple inheritance and objective-c (From: Mark Dawson <email@hidden>)
 >Re: Multiple inheritance and objective-c (From: "John C. Warner" <email@hidden>)
 >Re: Multiple inheritance and objective-c (From: Mark Dawson <email@hidden>)
 >Re: Multiple inheritance and objective-c (From: Mont Rothstein <email@hidden>)
 >Re: Multiple inheritance and objective-c (From: Mark Dawson <email@hidden>)
 >Re: Multiple inheritance and objective-c (From: Serge Meynard <email@hidden>)

  • Prev by Date: [SOLVED] Re: How to adjust the drag & drop start timing?
  • Next by Date: Benefits of subclassing NSWindowController?
  • Previous by thread: Re: Multiple inheritance and objective-c
  • Next by thread: Re: Multiple inheritance and objective-c
  • Index(es):
    • Date
    • Thread