Java Modeling: UML workbook, part 1

Source: Internet
Author: User


Java Modeling:UML workbook, part 1 Original ENGLISH


content:
sequence diagram
about the sample application
getting started
Add a participant
Connection Points
Create an activity diagram
indicates the passage of time
next
references
about the author
comment on this article


Related content:
Create a UML sequence diagram with a style
Object-Oriented Design Process: Case Introduction
All articles in the Java modeling Series


Sequence diagram Introduction

Granville Miller (rmiller@togethersoft.com)
Consultant, togethersoft
May 2001

Granville Miller introduced a component of the Unified Modeling Language (UML) in the first part of his new column: sequence diagrams. A sequence diagram is used throughout the design process to demonstrate the internal interaction between participants and objects during system execution. Let's create a graph with Granville, and we will use a loan processing application.ProgramAs an example.

The Unified Modeling Language (UML) is a standard markup method used to establish an object-oriented system model. Between 1995 and 1997, UML was mounted to object-oriented programming.CommunityAnd was recognized by the Object Management Organization (OMG) in the late 1997 s. Although it was initially controversial-because it was proposed in a piece of support and opposition-UML has become an industry standard for system marking. The current version of UML is 1.4, and it will continue to develop to meet the needs of object-oriented developers. (For more information about the history of UML, see references .)

UML may be hard to learn, primarily because it attempts to provide modeling markup for a wide range of situations. Each modeling markup method uses a diagram, but currently there are nine types of diagrams in the UML specification. Fortunately, learning UML can be a progressive process; you can learn only one graph at a time, without having to include complex things in the diagram at the first trial.

In this column, I will teach you how to gradually learn the UML design and markup method based on Java application development. I will introduce the basic knowledge of the UML framework and other modeling technologies in a logical (possibly pleasant) way. You will learn the actual operations by creating a realistic model. In the first part, we use the loan processing application as an example, starting from creating a sequence diagram. Note that you are familiar with the Java language and have basic knowledge of object-oriented methods and terms. This topic will briefly describe the concept of object-oriented, but will not be discussed in depth.

Sequence Diagram

About participant roles
The participant role helps to discover and identify the participants that can participate in the use case plan. One participant can have multiple roles in one use case and multiple use cases. Currently, four different types of participant roles have been identified as UML enhanced or traditional roles: Start Programs, servers, receivers, and proxies. You should be familiar with the functions of the participant roles in the sequence diagram.

  • Start the programIs an external entity that sets a system action in an action. A startup program can request services or generate events. In the sequence diagram showing the participants, the startup program starts the sequence in the action.
  • ExternalServerA role provides services for other roles. The server provides external functions or information to help the system achieve its goals. Many external systems that contain the operating system are server roles. The server will receive messages, but may not generate messages.
  • ReceiverThe role receives information from the system. They provide services in a negative way. Therefore, they may not provide values to the system, but may want other participants to provide values. An example of a receiver is a data warehouse or an external backup system. The receiver generally receives messages from objects in the system, but generally does not generate messages.
  • ProxyIs the participant that represents the operation performed by another participant. An example of an agency is the music store staff who rent a video.

UML does not exclude any special software development methods or processes; it only standardizes the markup format. However, many development methods are combined with UML. The Rational Unified Process (RUP) is such a method; the other is feature-driven development (FDD ). Because of its intuition and versatility, UML sequence diagrams have become part of the front-end modeling activities of these processes. A sequence diagram is used to create a model for the following content:

    • Case Scheme
    • Protocols in the framework
    • Subsystem
    • Class
    • Method Logic

The following is a brief description of each of the above features.

Case Scheme
For example applications, we will use a sequence diagram to create a model for a single use case scheme. A use case is a single task executed by a participant to interact with the application to achieve a specified goal. A participant can be any end user, organization, or system that interacts with the application and is outside the application. (For more information about the four types of participant roles, see about the participant roles. For more information about the use case solution, see references .)

Protocols in the framework
The Protocol lies in the framework and is calledCollection. Understanding the interactions required by the framework helps develop new collections. A sequence diagram is usually used to record these interactions.

Subsystem
A large project is broken down into smaller and manageable parts, calledSubsystem. The interfaces between subsystems are crucial to integrating them into a larger whole (that is, a system. A sequence diagram is used to specify the interaction between classes on the subsystem boundary.

Class
Some classes (suchSocketAndInetaddress) Requires a complex sequence of method calls for correct interaction. These sequences form a protocol used to interact with such a class or a group of classes. A sequence diagram can be used to describe the use of a class or a group of interacting classes, thus describing the protocols required for interaction.

Method Logic
Sequence diagrams are excellent in recording method logic. In fact, as long as the Java method is provided, some CASE tools will automatically generate a sequence diagram. Sequence diagrams can be used to design future methods or record existing methods.

Sample Application
We will learn the sequence diagram with the help of the example loan processing application. Because the focus of this column is modeling, rather than method, we need to directly discuss graph creation, so we do not focus on application details. The basic functions we plot for the loan processing application are as follows:

Use Case: Submit a loan request

    1. The applicant completes and submits a loan application to the bank over the Internet.
    2. The system confirms the loan application information and checks whether it is correct and whether the information is as complete as possible.
    3. The system forwards loan requests to external credit consultation institutions to obtain the applicant's credit report.
    4. The system calculates the credit points of the applicant based on the returned credit report.

Getting started
The first step in creating a sequence chart is to determine whether the chart represents interaction with external or internal entities. If you are creating a model for the use case scheme, the sequence diagram usually represents interaction with external entities. If you are creating a protocol model in the framework, this figure may indicate internal or external interactions. Subsystem diagram, class diagram, and logic diagram of some methods usually only represent internal entities. In either case, the interaction type to be modeled determines the first (leftmost) element in the sequence diagram.

Interaction with external entities indicates that participants are part of the interaction. Internal interaction may be started by participants (if the subsystem use case is the basis of interaction), but it is more likely to be calledSender. If a participant initiates an interaction, the participant is classified as one of the four common participant roles (for more information, see about the participant role ).

We will focus on the loan processing application (as outlined aboveSubmit loan requestUse Case. Note the changes in the sequence diagram when the applicant completes the online loan application and submits it over the Internet. In this scheme, the applicant is outside the system and therefore represented by the participant. We will first add participantsApplicantAdd to sequence diagram, as shown in 1.

Figure 1. Add an applicant

Add participant
Once the interaction startup program is in place, the next step is to add the object it will interact with during the solution process. The names of these objects should reflect the behavior of the class or instance. (The class or instance selection gives a different meaning from the sequence diagram, but I will keep the difference between the two for the next discussion .)

For the example scheme, we will add two classes:LoanapplicationAndLoanrequest. When applying for a loan, you must submit a loan application. It contains information about the applicant and the expected loan amount. A loan request is a form sent by a bank to a commercial credit consultation institution for receiving a loan application. It contains some information from the loan application and requests to obtain information about the applicant's credit history. Figure 2 shows how to add these two classes to the sequence diagram.

Figure 2. Add two interactive classes

Connection Point-dotted line
For most software developers, the sequence diagram is intuitive. They map objects and participants (horizontal) to time (vertical ). Messages connect to objects. When messages occur, they move from one object to another along the vertical axis. These messages are connected to the vertical dotted line extending from the middle of an object or participant. This line is calledLifeline.

On the horizontal axis, we call itCall arrowOrMessage arrowTo indicate the message. The message arrow points from the sender (tail) to the receiver (header ). These arrows are used to capture the dynamic behavior of the system. The call usually starts from the left and moves to the right. That is, the initial arrow in the interaction usually comes from the left. When creating a new instance of the class, the arrows we draw point to the class itself, not the lifeline. The first step in our solution is to create a new loan application, so weApplicantAndLoanapplicationDraw arrows between them. Since creating a new instance in Java involves calling the constructor, we will mark this arrow with the constructor name. If possible, we will also mark the variable.

We are still in the analysis phase of the software development lifecycle, so we need to include only a lot of analysis information. One of our business analysts mentioned that we call the procedure of creating a new loan application "to complete a loan application ". If we want to keep the sequence diagram as true during the construction processCompleteImplemented as a public method, which will callLoanapplicationConstructor, as shown in figure 3.

Figure 3. Create loanapplication

Create an activity diagram
However, when a class or instance receives a message, it creates a box on the lifeline of the receiving object. This box is calledActivity. Activity indicates the flow of control in the method of the receiver. When a message creates an object, the first activity indicates the logic of the constructor. Subsequent messages will lead to the creation of new activities.

However, when a message is received, the receiving object can send the message to itself or other objects in sequence. This is shown by the arrow's tail, which indicates that the arrow originates from the activity and ends with the new activity. However, when an object calls itself, new activities are placed above old ones.

In this scheme, the applicant interacts with the loan application twice, the first is to complete it, and the second is to submit it. WhenLoanapplicationReceivedSubmitWhen a message is sentValidateThe message is sent to itself to verify itself. If valid, it will create a newLoanrequest. Figure 4 showsLoanapplication.

Figure 4. Confirm loanapplication

Arrow file: indicates the passage of time
We use an oblique arrow to indicate the passage of real time between message sending and receiving. This flag is used to display non-basic calls. An example of a non-basic call is a method call by Using CORBA or RMI, or a message sent over the network.

In this example, the Business Credit advisor is an external system that is a participant with a server role (for more information, see about participant roles ). The server usually does not generate messages, but there will be messages sent to them-in this example, a request for a credit report sent by the credit checker. The credit checker represents a commercial credit consultation institution. It tracks requests and forwards the requests to the credit advisor, tracks and receives responses, and establishes a connection between the loan processing application and the credit advisor. The business credit advisory institution will receive the request and process the request according to its own schedule. We use an oblique arrow to show the passage of time, as shown in Figure 5 below.

At the end of the activity, the result returned to the calling program is implicit. However, in some cases, you may want to return an explicit response. The explicit return call is indicated by the dotted arrow. the tail of the arrow is the receiver and the header is the sender. The explicit return arrow is usually marked by the value returned by the call. For this exampleCreditbureauAndCreditcheckerAn explicit arrow is added between them. This arrow can be labeled.CreditreportBecause it is fromRequestcreditreportObject returned by the method.

Figure 5. Obtain the creditreport

Next step
As I mentioned at the beginning of this article, the sequence diagram is used to describe the internal behavior of the system during running. In this article, I have introduced the first step to build a sequence diagram by creating an interactive model between objects. In the next section, I will introduce two types of Sequence Diagrams (general and instance), and illustrate the role of conditional logic in sequence diagrams using examples drawn based on simple Java methods. See you later!

References

  • Click"Discussion"Participate in the Forum on this article.

  • Martin Fowler (UML DistilledThe author of UML) provides an overview of the early history of UML.
  • Fowler's "Why use UML" further illustrates the need for standardized marking in the development cycle (software development online, December March 2000 ).
  • If you want to study UML carefully, you should start with the original articles written by three friends (booch, Jacob, Rumbaugh:Unified Modeling Language User Guide(Addison Wesley Object Technology series, 1998 ).
  • The basic book to be learned next is the unified modeling language specification of OMG (version February 2001 was used in 1.4 ).
  • The rational UML resource page provides information about UML and RUP and other content.
  • For additional information about sequence diagrams and UML, see "Creating a UML sequence diagram with styles" by Scott W. Ambler (developerworks, February 2001 ).
  • Allen Holub provides an in-depth description of the use case solution in his series of object-oriented design processes (developerworks, January 2001 ).
  • For more in-depth study of case modeling, see "Advanced use case modeling, Volume I: Software Systems" (Addison-Wesley, 2001) by Frank armour and Granville Miller ).
  • For more information about function-driven development and Rational Unified Process, see Peter Coad, Eric Lefebvre, and Jeff Deluca.Java Modeling in color with UML(Prentice Hall, 1999 ).
  • Another good book about RUP was written by Philip kruchten.The rational uniied process: An Introduction(Addison Wesley, 2000 ).
  • Please refer to OCL, which is the expression language of UML.
  • IBM and other industry leaders have created XMI, a new open industry standard, it combines the advantages of some XML standards based on Web for editing, validation, and sharing document formats with the advantages of UML.

About the author
Granville has been in the object-oriented community for 13 years. He is a co-author of the Advanced use case modeling series and has introduced tutorials at various object-oriented technical conferences around the world. His practical method of object-oriented development comes from his experience working in a number of companies, including various companies from startups to well-developed software giants.

He is currently teaching workshops, tutorials, and courses on flexible processes, methods, and Java technologies, as well as coaching and helping implement some active projects. Granville can be contacted through a rmiller@togethersoft.com.


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.