📄 200442149.htm
字号:
<TR>
<TD><IMG src="2004421492.jpg" tppabs="http://www.uml.org.cn/images/upfile/2004421492.jpg"> </TD></TR>
<TR>
<TD align=middle><SPAN class=caption><B xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Figure 1:</B> Sample use-case diagram </SPAN></TD></TR></TBODY></TABLE>
<P>A use-case diagram is typically used to communicate the high-level functions of the system and the systems scope. By looking at our use-case diagram in Figure 1, you can easily tell the functions that our example system provides. This system lets the band manager view a sales statistics report and the Billboard 200 report for the bands CDs. It also lets the record manager view a sales statistics report and the Billboard 200 report for a particular CD. The diagram also tells us that our system delivers Billboard reports from an external system called Billboard Reporting Service.</P>
<P>In addition, the absence of use cases in this diagram shows what the system <I xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">doesnt</I> do. For example, it does not provide a way for a band manager to listen to songs from the different albums on the Billboard 200 ?i.e., we see no reference to a use case called Listen to Songs from Billboard 200. This absence is not a trivial matter. With clear and simple use-case descriptions provided on such a diagram, a project sponsor can easily see if needed functionality is present or not present in the system.</P>
<P><A name=N10090><SPAN class=atitle2><STRONG><FONT size=4>Class diagram</FONT></STRONG></SPAN></A><BR>The class diagram shows how the different entities (people, things, and data) relate to each other; in other words, it shows the static structures of the system. A class diagram can be used to display logical classes, which are typically the kinds of things the business people in an organization talk about ?rock bands, CDs, radio play; or loans, home mortgages, car loans, and interest rates. Class diagrams can also be used to show implementation classes, which are the things that programmers typically deal with. An implementation class diagram will probably show some of the same classes as the logical classes diagram.The implementation class diagram wont be drawn with the same attributes, however, because it will most likely have references to things like Vectors and HashMaps.<BR xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><BR xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">A class is depicted on the class diagram as a rectangle with three horizontal sections, as shown in Figure 2. The upper section shows the classs name; the middle section contains the classs attributes; and the lower section contains the classs operations (or methods). </P>
<TABLE cellPadding=5 width=150>
<TBODY>
<TR>
<TD><IMG src="2004421493.gif" tppabs="http://www.uml.org.cn/images/upfile/2004421493.gif"> </TD></TR>
<TR>
<TD align=middle><SPAN class=caption><B xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Figure 2:</B> Sample class object in a class diagram </SPAN></TD></TR></TBODY></TABLE>
<P>In my experience, almost every developer knows what this diagram is, yet I find that most programmers draw the relationship lines incorrectly. For a class diagram like the one in Figure 3,you should draw the inheritance relationship<A href="javascript:if(confirm('http://www-106.ibm.com/developerworks/rational/library/769.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www-106.ibm.com/developerworks/rational/library/769.html#footnotes'" tppabs="http://www-106.ibm.com/developerworks/rational/library/769.html#footnotes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><SUP><FONT color=#996699>1</FONT></SUP></A> using a line with an arrowhead at the top pointing to the super class, and the arrowhead should a <I xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">completed triangle</I>. An association relationship should be a solid line if both classes are aware of each other and a line with an <I xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">open arrowhead</I> if the association is known by only one of the classes.</P>
<TABLE cellPadding=5 width=250>
<TBODY>
<TR>
<TD align=middle><A onclick=window.open(content/03July/2500/2772/2772_fig3.gif,fig_3,height=309,width=718); href="javascript:if(confirm('http://www-106.ibm.com/developerworks/rational/library/769.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www-106.ibm.com/developerworks/rational/library/769.html#'" tppabs="http://www-106.ibm.com/developerworks/rational/library/769.html#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" false;; return><IMG src="2004421494.jpg" tppabs="http://www.uml.org.cn/images/upfile/2004421494.jpg" border=0><FONT color=#996699> </FONT></A></TD></TR>
<TR>
<TD align=middle><SPAN class=caption><B xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Figure 3:</B> A complete class diagram, including the class object shown in Figure 2 </SPAN></TD></TR>
<TR>
<TD align=middle>(<A onclick=window.open(content/03July/2500/2772/2772_fig3.gif,fig_3,height=309,width=718); href="javascript:if(confirm('http://www-106.ibm.com/developerworks/rational/library/769.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www-106.ibm.com/developerworks/rational/library/769.html#'" tppabs="http://www-106.ibm.com/developerworks/rational/library/769.html#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" false;; return><FONT color=#996699>click here to enlarge</FONT></A>) </TD></TR></TBODY></TABLE>
<P>In Figure 3, we see both the inheritance relationship and two association relationships. The CDSalesReport class inherits from the Report class. A CDSalesReport is associated with one CD, but the CD class doesnt know anything about the CDSalesReport class. The CD and the Band classes both know about each other, and both classes can be associated to one or more of each other.</P>
<P>A class diagram can incorporate many more concepts, which we will cover later in this article series. </P>
<P><A name=N10104><SPAN class=atitle2><STRONG><FONT size=4>Sequence diagram</FONT></STRONG></SPAN></A><BR>Sequence diagrams show a detailed flow for a specific use case or even just part of a specific use case. They are almost self explanatory; they show the calls between the different objects in their sequence and can show, at a detailed level, different calls to different objects. </P>
<P>A sequence diagram has two dimensions: The vertical dimension shows the sequence of messages/calls in the time order that they occur; the horizontal dimension shows the object instances to which the messages are sent. </P>
<P>A sequence diagram is very simple to draw. Across the top of your diagram, identify the class instances (objects) by putting each class instance inside a box (see Figure 4). In the box, put the class instance name and class name separated by a space/colon/space : (e.g., myReportGenerator : ReportGenerator). If a class instance sends a message to another class instance, draw a line with an open arrowhead pointing to the receiving class instance; place the name of the message/method above the line. Optionally, for important messages, you can draw a dotted line with an arrowhead pointing back to the originating class instance; label the return value above the dotted line. Personally, I always like to include the return value lines because I find the extra details make it easier to read.</P>
<P>Reading a sequence diagram is very simple. Start at the top left corner with the driver class instance that starts the sequence. Then follow each message down the diagram. Remember: Even though the example sequence diagram in Figure 4 shows a return message for each sent message, this is optional. </P>
<TABLE cellPadding=5 width=250>
<TBODY>
<TR>
<TD align=middle><A onclick=window.open(content/03July/2500/2772/2772_fig4.gif,fig_4,height=440,width=744); href="javascript:if(confirm('http://www-106.ibm.com/developerworks/rational/library/769.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www-106.ibm.com/developerworks/rational/library/769.html#'" tppabs="http://www-106.ibm.com/developerworks/rational/library/769.html#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" false;; return><IMG src="2004421495.jpg" tppabs="http://www.uml.org.cn/images/upfile/2004421495.jpg" border=0><FONT color=#996699> </FONT></A></TD></TR>
<TR>
<TD align=middle><SPAN class=caption><B xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Figure 4:</B> A sample sequence diagram </SPAN></TD></TR>
<TR>
<TD align=middle>(<A onclick=window.open(content/03July/2500/2772/2772_fig4.gif,fig_4,height=440,width=744); href="javascript:if(confirm('http://www-106.ibm.com/developerworks/rational/library/769.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www-106.ibm.com/developerworks/rational/library/769.html#'" tppabs="http://www-106.ibm.com/developerworks/rational/library/769.html#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" false;; return><FONT color=#996699>click here to enlarge</FONT></A>) </TD></TR></TBODY></TABLE>
<P>By reading our sample sequence diagram in Figure 4, you can see how to create a CD Sales Report. The aServlet object is our example driver. aServlet sends a message to the ReportGenerator class instance named gen. The message is labeled generateCDSalesReport, which means that the ReportGenerator object implements this message handler. On closer inspection, the generateCDSalesReport message label has cdId in parentheses, which means that aServlet is passing a variable named cdId with the message. When gen instance receives a generateCDSalesReport message, it then makes subsequent calls to the CDSalesReport class, and an actual instance of a CDSalesReport called aCDReport gets returned. The gen instance then makes calls to the returned aCDReport instance, passing it parameters on each message call. At the end of the sequence, the gen instance returns aCDReport to its caller aServlet.</P>
<P>Please note: The sequence diagram in Figure 4 is arguably too detailed for a typical sequence diagram. However, I believe it is simple enough to understand, and it shows how nested calls are drawn. Also, with junior developers, sometimes it is necessary to break down sequences to this explicit level to help them understand what they are supposed to do.</P>
<P><A name=N10152><SPAN class=atitle2><STRONG><FONT size=4>Statechart diagram</FONT></STRONG></SPAN></A><BR>The statechart diagram models the different states that a class can be in and how that class transitions from state to state. It can be argued that every class has a state, but that every class shouldnt have a statechart diagram. Only classes with interesting states ?that is, classes with three or more potential states during system activity ?should be modeled. </P>
<P>As shown in Figure 5, the notation set of the statechart diagram has five basic elements: the initial starting point, which is drawn using a solid circle; a transition between states, which is drawn using a line with an open arrowhead; a state, which is drawn using a rectangle with rounded corners; a decision point, which is drawn as an open circle; and one or more termination points, which are drawn using a circle with a solid circle inside it. To draw a statechart diagram, begin with a starting point and a transition line pointing to the initial state of the class. Draw the states themselves anywhere on the diagram, and then simply connect them using the state transition lines.</P>
<TABLE cellPadding=5 width=250>
<TBODY>
<TR>
<TD align=middle><A onclick=window.open(content/03July/2500/2772/2772_fig5.jpg,fig_5,height=418,width=770); href="javascript:if(confirm('http://www-106.ibm.com/developerworks/rational/library/769.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www-106.ibm.com/developerworks/rational/library/769.html#'" tppabs="http://www-106.ibm.com/developerworks/rational/library/769.html#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" false;; return><IMG src="2004421496.jpg" tppabs="http://www.uml.org.cn/images/upfile/2004421496.jpg" border=0><FONT color=#996699> </FONT></A></TD></TR>
<TR>
<TD align=middle><SPAN class=caption><B xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">Figure 5:</B> Statechart diagram showing the various states that classes pass through in a functioning system </SPAN></TD></TR>
<TR>
<TD align=middle>(<A onclick=window.open(content/03July/2500/2772/2772_fig5.jpg,fig_5,height=418,width=770); href="javascript:if(confirm('http://www-106.ibm.com/developerworks/rational/library/769.html \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address. \n\nDo you want to open it from the server?'))window.location='http://www-106.ibm.com/developerworks/rational/library/769.html#'" tppabs="http://www-106.ibm.com/developerworks/rational/library/769.html#" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" false;; return><FONT color=#996699>click here to enlarge</FONT></A>) </TD></TR></TBODY></TABLE>
<P>The example statechart diagram in Figure 5 shows some of the potential information they can communicate. For instance, you can tell that loan processing begins in the Loan Application state. When the pre-approval process is done, depending on the outcome, you move to either the Loan Pre-approved state or the Loan Rejected state. This decision, which is made during the transition process, is shown with a decision point ?the empty circle in the transition line. By looking at the example, a person can tell that a loan cannot go from the Loan Pre-Approved state to the Loan in Maintenance state without going through the Loan Closing state. Also, by looking at our example diagram, a person can tell that all loans will end in either the Loan Rejected state or the Loan in Maintenance state.</P>
<P><A name=N10197><SPAN class=atitle2><STRONG><FONT size=4>Activity diagram</FONT></STRONG></SPAN></A><BR>Activity diagrams show the procedural flow of control between two or more class objects while processing an activity. Activity diagrams can be used to model higher-level business process at the business unit level, or to model low-level internal class actions. In my experience, activity diagrams are best used to model higher-level processes, such as how the company is currently doing business, or how it would like to do business. This is because activity diagrams are less technical in appearance, compared to sequence diagrams, and business-minded people tend to understand them more quickly. </P>
<P>An activity diagrams notation set is similar to that used in a statechart diagram. Like a statechart diagram, the activity diagram starts with a solid circle connected to the initial activity. The activity is modeled by drawing a rectangle with rounded edges, enclosing the activitys name. Activities can be connected to other activities through transition lines, or to decision points that connect to different activities guarded by conditions of the decision point. Activities that terminate the modeled process are connected to a termination point (just as in a statechart diagram). Optionally, the activities can be grouped into swimlanes, which are used to indicate the object that actually performs the activity, as shown in Figure 6. </P>
<TABLE cellPadding=5 width=439>
<TBODY>
<TR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -