• 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 language [NEWBEE QUESTIONS]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Objective C language [NEWBEE QUESTIONS]


  • Subject: Re: Objective C language [NEWBEE QUESTIONS]
  • From: Chris Hanson <email@hidden>
  • Date: Fri, 30 Jan 2004 10:45:51 -0600

On Jan 30, 2004, at 6:08 AM, Alexander F. Hartner wrote:
1. ) Private methods:
Is it possible to declare a method as private. From what I found out so
far it is not, but a similar behaviour may be achieved by declaring a
private category. How would one declare a private category. One example
I found simple named the category "Private", but this seems to easy /
wrong to me.

That's the only way to get "private" methods in Objective-C. Since Objective-C is an object-oriented language, you can send any object any message at any time; "private" methods really wouldn't be "private," unless "privacy" was enforced by the runtime somehow.

2.) Abstract methods:
Is is possible to declare methods / classes as abstract. Conceptually I
see that it is possible, but how is it done in practice to prevent
instantiation of a class?

There's no such thing as an abstract class at the language level in Objective-C. You can override +alloc to check the class being instantiated; if it's the "abstract" class, or it doesn't respond to all of the selectors for methods that need to be overridden in subclasses, throw an exception.

3.) Inheritance of the constructor / class methods
Is seems to me that the constructor is inherited as well. Does this
mean that inheritance covers class methods (i.e. +) as well ?

There are no "constructors" in Objective-C. But yes, class methods are inherited just as instance methods are. There are no "static" methods as in C++ or Java.

4.) Runtime adoption
This might be the most misguided question of all. Is it possible to
adopt a protocol at runtime, i.e. without having it declared before. I
vaguely remember reading in a tutorial that the Objective C language
supports a feature along the lines of adopting a protocol at runtime.
Is there such a thing and how is it done.

You could probably just override -conformsToProtocol: and +conformsToProtocol: to respond the right way at run-time.

In Cocoa, though, formal protocols aren't used nearly as often (other than NSCopying and NSCoding) as they are in Java. Many protocols are documented as being "informal protocols" where the entire protocol doesn't need to be implemented by a class; for instance, most delegate and data source methods work this way. (E.g. To act as an NSTableView's dataSource an object don't need to implement every method in NSTableDataSource or conform to NSTableDataSource.)

-- Chris

--
Chris Hanson <email@hidden>
bDistributed.com, Inc.
Outsourcing Vendor Evaluation
Custom Mac OS X Development
Cocoa Developer Training
_______________________________________________
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: 
 >Objective C language [NEWBEE QUESTIONS] (From: "Alexander F. Hartner" <email@hidden>)

  • Prev by Date: Re: Objective C language [NEWBEE QUESTIONS]
  • Next by Date: Lotus Notes from cocoa
  • Previous by thread: Re: Objective C language [NEWBEE QUESTIONS]
  • Next by thread: Re: Objective C language [NEWBEE QUESTIONS]
  • Index(es):
    • Date
    • Thread