• 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: Objective-C Question
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Objective-C Question


  • Subject: Re: Objective-C Question
  • From: Chris Hanson <email@hidden>
  • Date: Mon, 22 Sep 2003 17:18:36 -0500

On Monday, September 22, 2003, at 04:56 AM, Steve Ehrenfried wrote:
From what I can tell Obj C is missing several things
which a good OOP language like Java has:

1) Being a able to make a method and/or class "final",
i.e. it can't be overridden or subclassed.

Useless in Objective-C. The dynamic nature of the language means you can send any message to any object at any time.

2) Being to able to have a partial implementation of a
class, i.e. an "abstract class". (Perhaps Obj C
supports this but I just don't know about it. If there
is, how do you specify that instances of a specific
class can't be instantiated?)

You override +alloc in the class to check whether the class itself or a subclass is being instantiated. If the class itself is being instantiated, you raise an exception. You can even do fancier things and check to see whether a subclass implements required methods, and raise an exception if it doesn't. (I think Foundation's class-cluster base classes like NSString and NSArray do this.)

3) Built in support for exceptions, though this is
more of a convenience than part of the object model.
Great implementation in Java, horrendous
implementation in C++ (the function signature doesn't
specify what exceptions are thrown, so how do you know
[unless it's documented, which it probably isn't] what
you need to catch or re-throw? It's real easy for an
uncaught exception to percolate up the stack).

Check out the GCC 3.3 release notes installed by the August 2003 GCC Update, available for download for a while now from ADC. Objective-C as of Panther and GCC 3.3 gets a Java-like exception model with @try, @catch, and @finally clauses. According to the release notes it can interoperate with older code that uses NS_DURING etc. but isn't backwards-compatible to 10.2 and earlier.

Objective-C doesn't get exception declarations in method signatures because this is useless due to the nature of the language. You can send any message to any object at any time; exception specifications aren't enforceable by the runtime without significant additional cost and don't buy you much anyway. (You should generally assume exceptions can be thrown, even in Java because RuntimeExceptions don't have to be declared.)

4) Being able to specify the access control of members
(public, protected, private). Isn't everything public
in Obj C? Sorry, I'm a newbie here, but isn't data
encapsulation part of the object model?

When you say "members," do you mean "instance variables"? Because Objective-C does have protection of instance variables. Of course you can still use the runtime to bypass this (including via Key-Value Coding) but it'll stop direct access.

If you mean method protection, it's not really feasible in Objective-C because you can send any message to any object at any time. (Notice a pattern?)

5) No namespaces (C++) or packages (Java). Again, Java
has a much cleaner implementation and is better
thought through, IMHO. Anything like this in Obj C?

Not yet. I'd like to see namespaces or packages in Objective-C as well.

-- Chris

--
Chris Hanson, bDistributed.com, Inc. | Email: email@hidden
Custom Mac OS X Development | Phone: +1-847-372-3955
http://bdistributed.com/ | Fax: +1-847-589-3738
http://bdistributed.com/Articles/ | Personal Email: email@hidden
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Objective-C Question (From: Steve Ehrenfried <email@hidden>)

  • Prev by Date: Re: What ever happened to "shared frameworks"?
  • Next by Date: Re: Objective-C Question
  • Previous by thread: Re: Objective-C Question
  • Next by thread: Re: Objective-C Question [long]
  • Index(es):
    • Date
    • Thread