• 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: calling a function in one class from another
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: calling a function in one class from another


  • Subject: Re: calling a function in one class from another
  • From: Quincey Morris <email@hidden>
  • Date: Thu, 5 Aug 2010 10:31:46 -0700

On Aug 5, 2010, at 07:42, Geoffrey Holden wrote:

> If I have a class 'Foo' (containing the function 'Wabble'), which loads
> another class 'Bar', is it possible a function within 'Bar' to execute the
> 'Wabble' function within the calling class 'Foo'?

You repeatedly say "function", but do you mean "function" or "method"?

If you really mean "function", then you can make the relevant functions global in the normal C way, and call them in the normal C way.

If you really mean "method" ...

> Why do I want to do this?  Well, 'Bar' contains all the code necessary to
> control a view.  This view contains an NSTableView for an address book.
>
>
> 'Foo' loads the address book data from a remote server.  'Foo' also loads
> another class 'Baz' which has an editor view.  I want 'Bar' to be able to
> execute the address book loader code in 'Foo' and I want to be able to
> double click on an address in 'Bar' and have it execute code in 'Foo' which
> will then appropriately load the editor view in 'Baz'.

Yeah, this sort of thing -- defining behavior in one place and making it available elsewhere -- is called encapsulation, and is precisely the reason why OO languages like Objective-C exist. So you seem to be asking how to encapsulate behavior in a language which provides encapsulation.

> I'm sure I've seen this done, and I'm fairly certain that it's easy to do -
> but I can't for the life of me remember how or where!
>
>
> I hope that this makes sense.

No, it really doesn't, though I freely admit I might have misunderstood the point of your question. It sounds like, in spite of using an OO language, you're thinking in functional-language terms and then asking where the encapsulation is. It's there if you think (and design) in OO terms.




_______________________________________________

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: 
 >calling a function in one class from another (From: Geoffrey Holden <email@hidden>)

  • Prev by Date: Re: NSRunLoop's -runMode:beforeDate: not exiting after an NSTask finishes
  • Next by Date: Re: Resolution of an NSImage(Rep)?
  • Previous by thread: Re: calling a function in one class from another
  • Next by thread: Re: calling a function in one class from another
  • Index(es):
    • Date
    • Thread