New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Development and Darwin Discussion and questions about development for Mac OS X.

Sending messages to other object's instances?


Post Reply New Thread Subscribe

 
Thread Tools
ND45

 
Member Since: Mar 02, 2009
Posts: 5
ND45 is on a distinguished road

ND45 is offline
*let me preface this question with "noob".

Say we have 3 objects: controller , box1, and box2.

"box1" and "box2" are instances created in "controller" and both have a method called "crunch".

Calling "crunch" from "controller" is no problem, but how do I call "box2"s crunch method from "box1"?

Said another way:

If an object instantiates 2 or more new objects, how can those new objects send messages to each other?

Thanks
QUOTE Thanks
Shogun

 
Member Since: Feb 15, 2009
Posts: 6
Shogun is on a distinguished road

Shogun is offline
Create a reference to the box class in the box class and then reference the box 2 to your box1.
QUOTE Thanks
ND45

 
Member Since: Mar 02, 2009
Posts: 5
ND45 is on a distinguished road

ND45 is offline
Shogun: Thanks for the reply. Trying to digest your suggestion. Not sure exactly how to implement it.

*scouring source material*
QUOTE Thanks
Shogun

 
Member Since: Feb 15, 2009
Posts: 6
Shogun is on a distinguished road

Shogun is offline
don't know what language you use but in Java you would implement it something along the lines of this:

writing these straight here, may be a few typos.
box class:
Code:
public class Box {
    private Box boxWithInBox; //Imagine that we keep boxes within boxes

    public Box (){
    }

    public void crunch (){
        //do stuff
    }

    public void crunchBoxWithInBox(){
        getBoxWithInBox ().crunch();
    }

    public void set boxWithInBox (Box boxWithInBox){
        this.boxWithInBox = boxWithInBox;
    }

    public Box getBoxWithInBox (){
        return boxWithInBox;
    }
}
controller class:
Code:
public Class Controller {
    
    public Controller (){
    }

    public void doStuff (){
        Box box1 = new Box ();
        Box box2 = new Box ();

        box1.setBoxWithInBox (box2);

        box1.crunchBoxWithInBox ();
    }
}
QUOTE Thanks
ND45

 
Member Since: Mar 02, 2009
Posts: 5
ND45 is on a distinguished road

ND45 is offline
Shogun: Thanks for the reply. I am using objective C but I understand your point. I will give it a try in the morning.

Thanks for taking the time.
QUOTE Thanks

Post Reply New Thread Subscribe


« save container variable to file in applescript? | Xcode won't start »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Mail not sending Gmail messages dub diver OS X - Apps and Games 7 09-07-2008 05:46 AM
Entourage 2008 sync'd sent messages display strangely! dB-A1 OS X - Apps and Games 0 06-14-2008 06:59 PM
sending garbled messages with mac mail 3.2 outrigger OS X - Apps and Games 1 03-18-2008 06:03 AM
Sending messages between Macs w/o IM? MattSharp OS X - Operating System 2 09-16-2007 08:50 PM
Problems with mail program sending emails? dorian86 OS X - Apps and Games 0 06-24-2007 08:28 PM

All times are GMT -4. The time now is 05:35 AM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?