Results 1 to 5 of 5
  1. #1


    Member Since
    Mar 02, 2009
    Posts
    5
    Sending messages to other object's instances?
    *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

  2. #2


    Member Since
    Feb 15, 2009
    Posts
    6
    Create a reference to the box class in the box class and then reference the box 2 to your box1.

  3. #3


    Member Since
    Mar 02, 2009
    Posts
    5
    Shogun: Thanks for the reply. Trying to digest your suggestion. Not sure exactly how to implement it.

    *scouring source material*

  4. #4


    Member Since
    Feb 15, 2009
    Posts
    6
    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 ();
        }
    }

  5. #5


    Member Since
    Mar 02, 2009
    Posts
    5
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Messages Sending From @me account
    By SpencerE in forum OS X - Operating System
    Replies: 1
    Last Post: 08-06-2012, 01:32 AM
  2. Sending group messages
    By beka_wasa in forum iOS and Apps
    Replies: 0
    Last Post: 06-04-2012, 07:17 PM
  3. Sending text messages to IPHONES
    By hotbum40 in forum OS X - Apps and Games
    Replies: 3
    Last Post: 03-11-2011, 02:07 PM
  4. Sending Text Messages from PC with Iphone
    By Dannyq in forum iOS and Apps
    Replies: 4
    Last Post: 11-18-2009, 11:00 AM
  5. Sending messages between Macs w/o IM?
    By MattSharp in forum OS X - Operating System
    Replies: 2
    Last Post: 09-16-2007, 09:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •