From: Tod Date: 2006-09-21T02:35:14+09:00 Subject: Re: Message passing between objects Paul Lutus wrote: > Tod wrote: > > / ... > > > Someone yesterday said you would create a superclass that both of these > > objects would share and this superclass would handle communication > > between the objects. I can see how that would work. But is that the > > only way? Is there no way for ruby objects to communicate directly with > > one another? > > No, in fact, there are any number of ways to do this. The question you > should be asking is which of the available methods meets your requirements > most efficiently. > > Obviously, using your example of a student registration system, the > student's identity is the key to the relationship between objects. > Therefore a parent class containing everything that is known about the > student should deal with various aspects of the student -- registration, > arranging for classes, health care, grades, whatever. > cture is also > easy for the maintainer to understand and modify. > In the process of applying for a particular class for example, the object > responsible for requesting a particular course would pass this request to a > parent class that coordinates all activities for that particular student, > and that class on turn would communicate with a class responsible for > assigning courses university-wide. > > The student's data is obviously self-contained, no peer-to-peer transactions > required. But the communication between the student's data and that > belonging to the university would be by way of another hierarchy of > classes, one in which the university's master record-keeping system would > be the parent of each student record. > > My point is true peer-to-peer transactions without a parent class to > coordinate the activities are rare, and should be avoided if possible. Many > data relations are naturally hierarchical, and this archite > > -- > Paul Lutus > http://www.arachnoid.com Thank you so much Paul for taking the time to lay that out for me. I appreciate it. The reason for the persistent nature of my question originates from a book I have on Java (I am not a Java programmer but this book helps me object oriented concepts) in which there is a sub-heading in a chapter: Message Passing Between Objects (hence my post title). In this section it appears (to my hazy mind) that they are describing a direct object to object interaction. But I may be wrong. Here is what it appears to be saying using the student example: Student s = new Student() Course c = new Course() Course c recieves the message: c.register(s) before Course c can register s it sends a message to Student s, perhaps s.successfullyCompleted(c2) where c2 is some other course that is required for the current registration request. Student s replies to Course c with true. Now Course c can register Student s and confirms the to whatever originated the request (a GUI perhaps) by returning true. To me that looks like two objects communicating directly with one another. But I am way out of my league here. The book is "Beginning Java Objects (2nd Ed) Jacquie Baker (2005 Apress). But again, thank you for your post above. TOD