• 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: OOP Clarification
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: OOP Clarification


  • Subject: Re: OOP Clarification
  • From: Thomas Lachand-Robert <email@hidden>
  • Date: Fri, 4 Jan 2002 19:47:48 +0100

Le vendredi 4 janvier 2002, ` 06:36 , Smith, Bradley a icrit :

Yes. Not as elegantly though 'cos you can't refer to the superclass in C+
+
without knowing what it is. So, class bar derives from foo then the method
on bar has to call foo::theMethod rather than super::theMethod.

Actually class methods in C++ are nothing but standard C++ functions with a slightly different syntax. That is, you call them with the syntax of a method, using a classname in place of an object.

Anyway, I see the differences now. Thanks to everyone who helped clear that
up.


IMHO the main difference is in the fact that there is no class _objects_ in C++. That means that you cannot relate directly an object to its class the way you do in ObjC (using [myObject class]). This looks not very useful at first sight, but it is in some very crucial places, like copying an object (see a previous message of mine three days ago about that).

There are some constructs that are very easy to do in Obj-C, and just impossible in C++ (or difficult). Consider for instance NSMatrix: every instance of it has a member indicating the CLASS of its cells, something you can change using:
- (void)setCellClass:(Class)aClass
(From the doc: "Configures the receiver to use instances of aClass when creating new cells. aClass should be the id of a subclass of NSCell, which can be obtained by sending the class message to either the NSCell subclass object or to an instance of that subclass.")

This allows the matrix to send a
[[[self cellClass] alloc] init]
message when it needs a new cell.



Thomas Lachand-Robert
********************** email@hidden
<< Et le chemin est long du projet ` la chose. >> Molihre, Tartuffe.


References: 
 >RE: OOP Clarification (From: "Smith, Bradley" <email@hidden>)

  • Prev by Date: Re: NSTextView/NSTextField Question
  • Next by Date: Re: The ULTIMATE Cocoa Development Language
  • Previous by thread: RE: OOP Clarification
  • Next by thread: Re: OOP Clarification: difference between classes and instances, compare with C++
  • Index(es):
    • Date
    • Thread