Design the Java application with UML

xiaoxiao2021-03-06  76

UML software engineering organization

Design the Java application with UML

Source: Reprinted from Umlchina, Hans-Erik Erikkson, Magnus Penker, Liu Zhong (Caulzhong@sina.com)

Case Studies in this article provide an example that explains how to use UML in reality. A application of libraries borrowings and bookings and magazines can get enough to test the level of UML to solve the problem of practical problems. But if it is too big, it is not suitable for published in the magazine. In the analysis model, the application is described with use case and domain analysis. We further extend it into design models. In the design model, we describe typical technical solution details. Finally, we have written a Java code (the code along with a complete analysis and design model is available online, in a format that can identify the Rational Rose, including the evaluation version.) You must pay attention, just a feasible solution . There may be many other solutions. There is no absolutely correct solution. Of course, some programs are better, but only the work of continuous practice and efforts can master the corresponding skills. 1. Requirements typically, the demand specification documentation of the text form is written by the representative of the system end user. For the library app, demand specifications documents should be similar to this: 1. This is a library support system; 2. Library will borrow books and magazines to borrowers. Borrowers have pre-registered, books and magazines are also pre-registered; 3. The library is responsible for the purchase of new books. Every book is purchased into many books. When the old book is over, when it is shaped, it removed from the library. 4. The library administrator is the employee of the library. Their job is to deal with the reader and work in the support of the software system. 5. Borrowers can book the current books and magazines. In this way, when he is booked and the magazine returns back or purchases, it will notify the predetermined person. When the borrowers of a book have borrowed the book, it will be canceled. Or forcibly cancel the reservation by explicit cancellation processes. 6. The library can easily establish, modify and delete title, borrowers, borrow information, and predetermined information. 7. The system can run in all popular technical environments, including UNIX, Windows, and OS / 2, and there should be a modern graphical user interface (GUI). 8. The system is easy to expand new features. The first version of the system does not have to consider the predetermined book after the predetermined book arrives, nor does it take to check the borrowing expiration. 2. The purpose of Analysis System Analysis is to capture and describe all system requirements, and create a model to define the main domain classes in the system. The understanding and communication of developers and demanders are achieved through system analysis. Therefore, the analysis is generally the product of analysts and users. At this stage, program developers should not consider the problem of code or program; it is just a first step in understanding the needs and implementation of the system. 2.1 Requirements Analysis analysis The first step is to determine what the system can do? Who will use this system? These are called a role (ACTORS) and use case. Use examples to describe what kind of functionality is provided. Analyze the use case by reading and analyzing documents, as well as and with potential user discussion systems. The role of the library is set to book administrators and borrowers. Book administrators are users of software systems; and borrowers are customers who borrow or book a book magazine. Occasionally, other staff of the library or library may also be a borrower. Billians are not directly interacting with the system, and the books of books are executed by the book administrator. The use cases in the library system are: 1. Borrowing book 2. Reservations 3. Reservation 4. Cancellation 5. Add the title 6. Modify or delete the title 7. Increase Bibliographic 8. Remove Bibliography 9. Increase Borrowers 10. Modify Or delete borrowers Since a book usually has multiple backups, the system must separate the title of the book and the concept of the book. The result of the library system analysis is written in the UML Model, as shown in Figure 1. Each usage is included with a text document, describing the details of the use case and customer interaction. The text is obtained by discussing with the customer.

The use case "Borrow" is described as follows: 1. If the borrower does not have a predetermined: h Determines Title H Determines the effective bibliograph in the title to determine the borrower H library to borrow a new borrow 2. If the borrower has a predetermined: h determines that the Billion H determines the title H to determine the effective bibliographic H Library under the title to lend the corresponding bibliographic Library H. Register a new borrowing H. Cancel, except for the functional requirements of the system, The use case is used to check if there is a corresponding domain class has been defined, and then they can be used in the design phase to ensure that the solution can effectively handle the system functionality. Details can be visualized in the sequence diagram. Figure 1: Role and use case. The first step in the analysis is to point out what the system can be used, who will use it. They are all use cases and roles, respectively. All use cases must begin with roles, and some use cases have also ended in the role. The role is a person or other system outside the system you work. A printer or a database may be a role. This system has two roles: borrowers and book administrators. By discussing with users or customers, each with example can be described using text. 2.2 Domain Analysis system analysis also lists the domain (critical classes in the system). In order to derive a domain analysis, you can read the specification document (Specifications) and the use case, and find which concept should be processed by the system. Or organize a collective discussion, which point the key concept that must be handled in the system under users and field experts, and the relationship between them. The domain class in the library system is as follows: BorrowerInformation (so naming is to distinguish between the role Borrower in the example map), Title, Book Title, Magazine Title, Item, RESERVATION, and LOAN. These classes and relationships between them are recorded in the class diagram document, as shown in Figure 2. The domain class is defined as the Business Object version, the Business Object version is a user-defined version that specifies that the object of the class is part of a key domain and should be durable in the system. Some of these classes have a UML state diagram that displays these classes of objects that may have different states, and events that trigger their status changes. The classes of the state map in this example are Item and Title classes. The sequential diagram of the use case lend item (the borrower does not have a predetermined case) is shown in FIG. The sequence diagram of all use cases can be found in the online model. Figure 2: Domain structure. Domain analysis details the key classes in the system. For each object, if it calls a method of other objects, then use a straight line between them to display the relationship between them. Each of the four-sided four-sided shape is divided into three parts, the top layer includes the name of the class, the intermediate layer is the attribute of the class, the bottom layer is the method of classes. The straight line between the class is associated and is used to indicate a method of calling another object. If you look carefully, you will find that there is "0..1" near the association relationship between Loan and ITEM, which represents the relevance of the associated weight. Renary "0..1 means that Item can perceive 0 to 1 Loan. Other possible weights also:" 0 .. * "represents 0 or more;" 1 "means 1;" 0 "means 0, "1.. *" Represents 1 or more. When modeling the order is modeled, the form and dialog must be provided as an interface of human-computer interaction. In this analysis, just know the book, book, and return The form is OK. Here, the detailed interface does not have to be considered. In order to separate the forms and domain classes in the system, all forms organizations are placed together in the GUI Package package. The domain organization is put together In the business package package. Figure 3: The sequence diagram of the Lend Item scene.

The scene is a specific process that implements a use case from beginning to end. The scene always begins with the role, and the role belongs to the outside of the system. The scene depicts the full process of completing a system actions from all roles. UML is shown in the sequence diagram. This example example shows the lend cases in the case where the borrower does not have a predetermined book. The top of the map is an object involved in interaction. Since the top, the time is expressed. First, the library administrator tries to find the title. The "lending window" is a user interface, and the analysis phase is a rough object. Each arrow in the sequence diagram is a method of calling. The head end of the arrow is the object called, the end of the arrow is the object being called. 3. The design phase expands the analysis model and further refine the model and considers technical details and restriction conditions. The purpose of the design is to specify a feasible solution so that it can easily transform into programming code. The design can be divided into two phases: Architecture Design. This is a design from a higher level, used to define a package (subsystem), and describe the dependence and communication mechanisms between the package. Naturally, the purpose is to design a clear and simple architecture, there are very few dependence, and avoid bidirectional dependence as much as possible. Detailed Design. At this stage, all classes are detailed, and a clear specification for programmers writing code. The dynamic model in the UML is used to illustrate how the objects make corresponding performance in a particular case. 3.1 Architecture Design A good architecture design is a scalable and changeable system basis. Packages may focus on specific functional areas or focus on specific technical fields. Separation of application logic (domain) and technical logic is critical, so that no matter which part changes will not affect other parts. The package or the subsystem of this case is as follows: User-interface package package. The class in this package is based on the Java AWT package. Java AWT is a standard library for writing a Java for writing user interface applications. This package and business-objects package packages are collaborated. The Business-Objects Package package contains classes that actually store data. The UI package calls the operation of the Business object, and takes out or inserts data operations. Business-Object Package. This package includes domain classes (such as BorrowerInformation, Title, Item, Loan, etc.) from the analysis model. The design phase completely defines the operations of these classes and adds some other details to support continuous storage. The Business-Object package collaborates with Database Package. All Business-Object classes must inherit the Persistent class in Database Package. Database package. Database packages provide services to class in the Business-Object package so they can be continuously stored. In the current version, the Persistent class stores the objects of its subclass to the file of the file system. Utility package. Utility Package includes some services that are used to be called in other packages in the system. Currently, the OBJID class is the unique class in this package. Used to be used by User-Interface, Business-Object, and Database Package for the entire system. The internal design of these packages is shown in Figure 4. Figure 4: Overview of the library application architecture design. This class diagram shows the application pack and the dependence between them. The Database package provides the Persistence class. The Utility package provides the Object ID class.

The Business-Object package contains domain classes (see Figure 5 for detail) Finally, the UI package (which in this example is based on the standard JAA AWT library) Call the operational operation in the Business object to implement them. 3.2 Detailed Design Detail Design Describes a new technical class such as a class in the user-interface and database package, and enriches the Business-Object class formed by the analysis phase. The graph, state diagram, and dynamic maps are also formed by the analysis phase, but have a higher technical level for their definitions. The textual description of the use case in the analysis phase is used to prove that the use case can also be processed during the design phase. The sequence diagram is used to illustrate, for example, to be implemented in the system. Database package. The application must have a continuous storage object. Therefore, the data layer must be added to provide such services. For the sake of simplicity, we save the object in the form of a file on the disk. The details of the store are hidden by the application, just call such as Store (), Update (), Delete (), and Find (). These are part of the Persistent class, and all classes that require continuous objects must inherit it. An important factor for continuous processing for classes is the OBJID class. Its object is used to reference any of the continuous objects in the system (regardless of this object is on the disk or has been read into the application). Objid is an Object Identity, it is a widely applying technology that effectively handles object references in the application. By using Object Identifiers, an object ID can be passed to a normal persistent.getObject () operation, which will be removed or stored from a continuous storage. Typically, these are done by a getObject operation per sustained class. Of course, the continuous class also does some operations for inspection or format conversion. An object identifier can also be easily passed between two operations as a parameter (for example, a query window to find a specific object can pass its query results to another through the Object ID). Objid is a common class that can be used in all packages in a system, so it is placed in the Utility package during the design phase instead of placing in the Database package. The current implementation of the Persistent class can also improve. To do this, define the interface of the Persistent class to facilitate continuous storage changes. Some alternative scenarios may be: Store objects in a relational database or stored in object-oriented databases, or using the continuous objects supported by Java 1.1 to store them. Business-Object Package. The Business-Object package in the design phase is based on the package of layered domain classes in the corresponding analysis phase. The relationship between classes and classes and their behavior continue to retain, but they are more detailed, including their relationships and behaviors are implemented. Some of the operations in the analysis model are translated into a design model, and others have changed their name. This is a normal thing, because the analysis phase gets a sketch of each class, and the design phase is a detailed description of the system. Therefore, the design of the design model must have a good design and return value (due to space limit, Figure 5 is not displayed, but they are in the online model). Note the changes in the design and analysis phases listed below: 1. The current version of the system does not require inspection of whether the bibliography is returned on time, nor does it require processing a predetermined order. Therefore, the date property is not set in the Loan and the RESERVATION class.

2. In addition to the longest borrowing period, the method of processing the magazine and book title is the same. Substations, Sub-class Magazine Title and Book Title, are considered unnecessary in the design phase, but increasing the Type property in the Title class to point out that a book is still a magazine. There is no design in the object-oriented design that cannot be simplified. If necessary, these simplities in future versions can be easily canceled. The status map of the analysis phase is also refined in the design phase. The status diagram shows how to represent the status and how to process the status in the system. The status map of the Title class in the design phase is shown in Figure 6. Other objects can change the status of the Title object by calling the action addRservation () and RemoveReServation () as shown. User-interface package. User-Interface Package is located in "above" in other packages. It provides users with output information and services in the system. As mentioned above, the package is based on standard Java AWT (Abstract Windows Toolkit). The dynamic model in the design model is placed in the GUI package because all and the user's interaction begins with the user interface. At this statement, the sequence diagram is used to display a dynamic model. The implementation of the use case in the design model is shown in detail by sequential diagram, including the actual operation in the class. The sequence diagram consists of a series of interactions. In the implementation phase (encoding), more interactions may be made in consideration of specific situations. Figure 7 shows the sequence diagram of the Add title use case. The actual operation and feature value can be seen from the online model code. Figure 5: Business-Object Design. This figure describes the different classifications in the Business-Object package. Design includes a stereotype, more completely customize interface, select data type to attribute, and so on. 6: State diagram of Title. Title has a predetermined and non-predetermined state, in the design, through a vector called "reservations". 7: The sequence diagram of add title. The details of the user interface issues involved in this figure have exceeded the scope of this article. The collaboration map can be replaced by a sequence diagram, as shown in Figure 8: Figure 8: Collaboration of Add Title. The details of the user interface issues involved in the figure have exceeded the range of 3.3 User-Lnterface Design Design phases in this detail to create a user interface. The user interface of the library system is based on the case, divided into the following parts, each part gives a separate menu item on the main form menu. Functions: Forms that implement system basic functions, through it can achieve borrowings, return and book for books. Information: View system information form, collect information about borrowers and books. Maintenance: Maintenance system form, add, modify, and delete title, borrowers, and books. Figure 9 shows an example of a class-interface package in a user-interface package. It includes a typical AWT event handle. The attributes of buttton, label and edit (Edit) are not displayed. Typically, each form gives a service of the system and maps an initial use case (although not all user interfaces must be mapped in an example). Creating a successful user interface has exceeded the scope discussed herein. Invite readers here to consider the UI code of this application developed with the Symantec Visual Cafe environment (already placed online). Figure 9: Function class diagram model.

The user interface class in the function menu generally has a relationship between 1 pair 1, indicating that the associated window class is required, or you need to access the associated commercial object class. 4. Implementation is programmed in the construction or stages of implementation. The application requires running on several different processors and different operating systems, thus selecting Java to implement the system. Java can easily map logic classes to code components because there is 1 pair 1 mapping between classes and Java code files. Figure 10: Component diagram shows dependencies. The source code component implements the domain class, and the association between them is displayed as two-way dependency Figure 10 shows that the component view of the design model simply maps the classes in the logical view into components in the component view. Each logical view contains a connection to the class of the logical view, so you can easily navigate between different views (even if this example is just simply using the file name). Since dependence can be obtained from a class diagram of a logical view, there is no dependency between the components in the component map. When writing the code, the specification description from the design model below: 1. Class Specification: The specification of each class shows the necessary properties and operations in detail. 2. Classroom: Class diagram consists of classes, showing the structure of the class and the relationship between classes. 3. Status Figure: The state diagram of the class displays the state of the class and the state shift required to process (and the operation of triggering the transfer). 4. Dynamic diagram (sequential diagram, collaboration): Targeting objects involving class, showing how specific methods in the class implementation, or how other classes are interacted using other classes. 5. Model and specification: When developers need to learn more about how the information is used (when the developer feels him or she is lost in a piece of details), they show the results of the system used. Naturally, some of the defects in the design can be found at the coding phase. Some new operations or modifications may be needed, which means that developers must change the design model. This will happen in all the projects. It is important to synchronize the design model and code in order to enable the model to become the final document of the system. Here is a Java code for the Loan class and some TitleFrame classes. The Java code for the entire application can be found online. When learning these code, pay attention to the UML model, how the UML structure is transformed into code. Note the following: 1. The Java package specification is a code that corresponds to the corresponding package in the logical view or component view of the class. 2. Private properties correspond to the properties specified in the model; and, a natural Java method corresponds to the operation in the model. 3. The OBJID class (object identifier) ​​is called to achieve the association. That is, the association usually saves together with the class (because the OBJID class continues). The code example of the Program List 1 comes from the Loan class, the Loan class is a business-object class that is used to store borrow information. Since this class is mainly the storage of information, the implementation of the program is straightforward, and the code is simple. Most features inherit the Persistent class in the Database package. The only attribute of this class is an object identifier, associating the Item and the BorrowerInformation class. And these associated properties are also saved in Write () and read () operations. Try to verify the addButton_Clicked () operation displayed in the program list 2 in the Add Title sequence (Figure 7) context. Combined with sequence diagram reading code, it can be seen that it is a more detailed description of another collaborative relationship expressed by the sequence chart.

The encoding of the sequential diagram in all design models is included in the source code (the operand and class name shown in the sequence diagram) 5. After the test and deployment encoding, the use of UML has not stopped. For example, you can verify whether the use case can be well supported in the completed application. For the deployment of the system, use the model and this article to make a heart-minded document. 6. Summarizing the different parts of this study case is designed by a group of people. They strive to complete the work in the way they do practical engineering. Although different phases and activities seem to be independent, it is managed in strict order, there is still a lot of repetitions in actual work. Experience and lessons in the design feedback to the analysis model, and the new situation found in the implementation changes or updates in the design model. This is a general method for establishing an object-oriented system. This article is extracted from UML Toolkit, New York: Wiley & Sons, 1998. Hans-Erik Erikkson is a famous C and OO technology authors. Magnus Penker is a vice chairman of Astrakan Training, Astrankan is a company specializing in OO modeling and design.

Original link: http://www.umlchina.com/indepth/designjava.htm model and source code: http://www.umlchina.com/zippdf/libraryjava.zip attached: Main Terms in English Control Actor: Role USE CASE: with Example domain: domain domain analysis: domain analysis specification: specification document sequence diagram: sequence diagram collaboration diagram: collaboration FIG component diagram: assembly of FIG state diagram: the state of FIG dependency: dependency attribute: attribute method: The method of operation: operation association: association multiplicity : Recent Class: Class Object: Object Package: Package: Package: DEPLOYMENT: Deployment: Source Code LOSTING 1. Loan Class. Loan Is A Business-Object Class Used for Storing Information About a loan. Most of the functionality is inherited from THE PERSISTENT CLASSIN THE DATABASE PACKAGE. // Loan.java: Repesents a loan. The Loan Refer to One /// Package Bo; Import Util.objid; Import Db. *; Import Java.Io. *; import java.util *;. public class Loan extends Persistent {private ObjId item; private ObjId borrower; public Loan () {} public Loan (ObjId it, ObjId b) {item = it; borrower = b;} public BorrowerInformation GetBorrower () {BorrowerInformat ion ret = (BorrowerInformation) Persistent.getObject (borrower); return ret;} public String getTitleName () {Item it = (Item) (item) Persistent.getObject; return it.getTitleName ();} public Item getItem () { Item it = (item); return it;} public int GETITEMID () {item IT = (item); return it.getid ();} public void write (RandomaccessFile Out) Throws ioException {item.write (out); borrower.write (out);} {= new objid (); item.read (in); item.read (in);

borrower = new ObjId (); borrower.read (in);.}} Listing 2. TitleFrame Class This is another, more detailed description of the collaboration described by the diagram in Figure 7. // TitleFrame.java // Package ui; import bo *;. import util *;. import java.awt *;. public class TitleFrame extends Frame {private Title current; void addButton_Clicked (Event event) {if (! Title.findOnName (titleField.getText ()) = null) {New MessageBox (this, "a title with That name already exists!"); return;} if (isbnfield.getText ())! = null) {New MessageBox (this, "a title with the same ISBN / NR Field Already Exists! "); return;} int type = 0; if (BookButton.getState () == true) Title.Type_book; Else IF (MagazineButton.getState () == true) type = Title. TYPE_MAGAZINE; else {new MessageBox (this, "Please give type of title!"); return;} current = new title (titleField.getText (), authorField.getText (), isbnField.getText (), type); int itemno ; if (itemsfield.gettext (). Equals ("")) itemno = 0; else itemno = integer.Valueof (item ()). INTVALUE (); if (itemno> 25) {New MessageBox (this, "Maximum Number of items IS 25!"); Return;} for (INT i = 0; i ) {item it = new item (current.getobjid (), i 1); it.Store (); current.additem (it.getobjid ());} current. Store (); titlefield.Settext (""); ""); isbnfield.settext (""); itemsfield.settext (""); bookbutton.setState (false); magazinebutton.setState (false); } void canbutton_clicked (Event Event) {Dispose ();} public titleframe () {// {{init_controls setLayout (NULL); addNotify ();

Right 430, INSETS () () (). rT 229); TitLabel = New Java.awLabel = New Java.awt.label ("Title Name"); TitleLabel.reshape INSETS (). LEFT 12, INSETS (). TOP 24, 84, 24); Add (TitleLabel); titlefield = new java.awt.textfield (); titlefield.reshape (Insets (). Left 132, Insets () .top 24, 183, 24); add (titlefield); Authorfield = new java.awt.textfield (); authorfield.reshape (inserts (). LEFT 132, INSETS (). TOP 60, 183, 24); add (authorfield); isbnfield = new java.awt.textfield (); isbnfield.reshape (ISBNFIELD.RESHAPE (ISTS (). LEFT 132, INSETS (). TOP 96, 183, 24); add (isbnfield); label1 = new java.awt. Label ("ISBN / NR"); label1.reshape (INSETS (). LEFT 12, INSETS (). TOP 96, 84, 24); add (label1); label2 = new java.awt.label ("Author "); label2.reshape (INSETS (). LEFT 12, INSETS (). TOP 60, 84, 24); add (label2); addbutton = new java.awt.button (" insert "); addbutton.reshape (INSETS (). Left 348, INSETS (). TOP 24, 60, 24); add (addbutton); cancelButton = new java.awt.button ("close"); CancelButton.reshape (Insets (). LEFT 348, INSETS (). TOP 192, 60, 24); add (canbutton); label3 = new java.awt.label ("items available"); label3.reshape (Insets). LEFT 12, INSETS (). TOP 192, 108, 24); add (label3); itemsfield = new java.awt.textfield (); itemsfield.reshape (ITEMSFIELD.RESHAPE (ITEMS (). LEFT 132, INSETS (). TOP 192 , 36, 23); add (itemsfield); group1 = new checkboxgroup (); bookbutton = new java.awt.checkbox ("book", group1, false); bookbutton.reshape (INSETS (). Left 132, insets ) .top 132, 108, 24); add (bookbutton); magazinebutton = new java.awt.checkbox ("

Magazine, Group1, False; MagazineButton.reshape (inset (). Left 132, INSETS (). TOP 156, 108, 24); add (magazinebutton); label4 = new java.awt.label ("type"); " Label4.reshape (INSETS (). LEFT 12, INSETS (). TOP 132, 108, 24); Add (Label4); SetTitle ("Insert Title Window"); //}} BookButton.SetState (TRUE); Titlefield. Requestfocus (); // {{init_menus ///}}} public titleframe (string title) {this (); settitle (title);} public synchronized void show () {Move (50, 50); super.show () ;} public boolean handleEvent (Event event) {if (event.id == Event.WINDOW_DESTROY) {dispose (); return true;} if (event.target == addButton && event.id == Event.ACTION_EVENT) {addButton_Clicked (event); return true;} if (event.target == cancelButton && event.id == Event.ACTION_EVENT) {cancelButton_Clicked (event); return true;} return super.handleEvent (event);} // {{DECLARE_CONTROLS Java.awt.TextField Titlefield; java.awt.textfield Authorfield; java.awt.textfield isbnfield; java.awt.label la bel1; java.awt.Label label2; java.awt.Button addButton; java.awt.Button cancelButton; java.awt.Label label3; java.awt.TextField itemsField; java.awt.Checkbox bookButton; CheckboxGroup Group1; java.awt .Checkbox magazinebutton; java.awt.label label4; //}} // {{declare_menus //}}}}}}}}

转载请注明原文地址:https://www.9cbs.com/read-92835.html

New Post(0)