📄 message.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN"><html><head><title>What Is a Message?</title><script language="JavaScript"><!-- hidefunction openWin(term) { url="../../information/glossary.html#" + term; myWin= window.open(url, "Glossary", "width=400,height=150,scrollbars=yes,status=no,toolbar=no,menubar=no"); myWin.focus();}//--></script><STYLE type="text/css"><!--.FigureCaption { margin-left: 1in; margin-right: 1in; font-family: Arial, Helvetica, sans-serif; font-size: smaller; text-align: justify }--></STYLE> </head><body BGCOLOR="#ffffff" LINK="#000099"><B><FONT SIZE="-1">The Java</font><sup><font size="-2">TM</font></sup> <font size="-1">Tutorial</FONT></B><br><table width="550" summary="layout"><tr><td align="left" valign="middle"><a href="object.html" target="_top"><img src="../../images/PreviousArrow.gif" width="26" height="26" align="middle" border="0" alt="Previous Page"></a><a href="../TOC.html#concepts" target="_top"><img src="../../images/TOCIcon.gif" width="26" height="26" align="middle" border="0" alt="Lesson Contents"></a><a href="class.html" target="_top"><img src="../../images/NextArrow.gif" width="26" height="26" align="middle" border="0" alt="Next Page"></a></td><td align="center" valign="middle"><font size="-1"><a href="../../index.html" target="_top">Start of Tutorial</a>><a href="../index.html" target="_top">Start of Trail</a>><a href="index.html" target="_top">Start of Lesson</a></font></td><td align="right" valign="middle"><font size="-1"><a href="../../search.html" target="_top">Search</a><br><a href="http://developer.sun.com/contact/tutorial_feedback.jsp">Feedback Form</a></font></td></tr></table><img src="../../images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" ALT=""><br><font size="-1"><b>Trail</b>: Learning the Java Language<br><b>Lesson</b>: Object-Oriented Programming Concepts</font><h2>What Is a Message?</h2><blockquote>A single object alone generally is not very useful. Instead, an object usually appears as a component of a larger program or application that contains many other objects. Through the interaction of these objects, programmers achieve higher-order functionality and more complex behavior. Your bicycle hanging from a hook in the garage is just a bunch of metal and rubber; by itself, it is incapable of any activity; the bicycle is useful only when another object (you) interacts with it (by pedaling).<p>Software objects interact and communicate with each other by sending <em>messages</em> to each other. When object A wants object B to perform one of B's methods, object A sends a message to object B (see<span id="figure:concepts-message.gif">the following figure</span>).<center><p><IMG SRC="../../figures/java/concepts-message.gif" WIDTH="380" HEIGHT="321" ALIGN="BOTTOM" ALT="Object A sends a message to object B."></p><p class="FigureCaption">Objects interact by sending each other messages.</p></center>Sometimes, the receiving object needs more information so that it knows exactly what to do; for example, when you want to change gears on your bicycle, you have to indicate which gear you want. This information is passed along with the message as <em>parameters</em>.<p><span id="figure:concepts-bicycleMessage.gif">The next figure</span> shows the three parts of a message:<ul><li>The object to which the message is addressed (<code>YourBicycle</code>)<li>The name of the method to perform (<code>changeGears</code>)<li>Any parameters needed by the method (<code>lowerGear</code>)</ul><center><p><IMG SRC="../../figures/java/concepts-bicycleMessage.gif" WIDTH="380" HEIGHT="320" ALIGN="BOTTOM" ALT="The You object sends a changeGears(lowerGear) message to the YourBicycle object"></p><p class="FigureCaption">Messages use parameters to pass along extra information that the object needs — in this case, which gear the bicycle should be in.</p></center>These three parts are enough information for the receiving object to perform the desired method. No other information or context is required.<P>Messages provide two important benefits:<UL><LI>An object's behavior is expressed through its methods,so (aside from direct variable access) message passing supports all possible interactions between objects.<LI>Objects don't need to be in the same process or even on the same machine to send messages back and forth and receive messages from each other.</UL></blockquote><img src="../../images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" ALT=""><br><table width="550" summary="layout"><tr><td align="left" valign="middle"><a href="object.html" target="_top"><img src="../../images/PreviousArrow.gif" width="26" height="26" align="middle" border="0" alt="Previous Page"></a><a href="../TOC.html#concepts" target="_top"><img src="../../images/TOCIcon.gif" width="26" height="26" align="middle" border="0" alt="Lesson Contents"></a><a href="class.html" target="_top"><img src="../../images/NextArrow.gif" width="26" height="26" align="middle" border="0" alt="Next Page"></a></td><td align="center" valign="middle"><font size="-1"><a href="../../index.html" target="_top">Start of Tutorial</a>><a href="../index.html" target="_top">Start of Trail</a>><a href="index.html" target="_top">Start of Lesson</a></font></td><td align="right" valign="middle"><font size="-1"><a href="../../search.html" target="_top">Search</a><br><a href="http://developer.sun.com/contact/tutorial_feedback.jsp">Feedback Form</a></font></td></tr></table><p><font size="-1"><a href="../../information/copyright.html">Copyright</a>1995-2005 Sun Microsystems, Inc. All rights reserved.</font></p></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -