UML design Java application

xiaoxiao2021-03-06  67

Use unified modeling language to master the power of object-oriented programming in Java

By Hans-Erik Erikkson and Magnus Penker

The case of this article is provided to the reader how to use UML feel in reality. Handling a library books and magazines borrowings and storage, this application has been large enough to illustrate UML's use. If this application is too complicated, we are afraid that it is not suitable to put it in the magazine. We analyze and describe this application in an analysis model (USE Cases) and a domain analysis (Domain Analysis). We extend it and put into a design model that describes the typical part of the technical solution. Finally, we encode its module in Java language (providing design source code, including full analysis and design model online download, the file format is RATIONAL ROSE). Remember, only one possible solution is shown here. There are still many other solutions, but at the same time, there is no solution to all situations. Of course, some solutions will prove that they will be better than others, but only experience and hard work will achieve knowledge.

demand

Typically, the system requirements instructions are written by the representative of the system end user. For the library, it looks like this:

(1) It is a system designed for library.

(2) The library borrows books and magazines to readers, and readers seem to be registered in the library system like library books and magazines.

(3) The library needs to deal with the name of the book. Popular books to buy multiple volumes. When the old books and magazines are out of time or when they are useless, they are removed.

(4) Book administrator is an employee of library, he is responsible for interacting with customers (readers), and systematically supports his work.

(5) The reader can retain a book or magazine currently yet, so that this reader is notified when booking (magazine) is refunded and purchased. When the reader (borrowing person) takes out the book (magazine) or cancel it through an external program, the original retention is canceled.

(6) The library can be easily established, updated and deleted related to the title, reader (borrowers), book lending, inventory information.

(7) The system can run on all popular operating systems, including UNIX, Windows, and OS / 2. Moreover, the system must have a modern graphic user interface (GUI).

(8) The system is easy for new functional expansion.

The first version of the system does not have to deal with information sent to the reader (borrowing person) when the reserved book name is changed, and it is not necessary to check the book name.

analysis

The analysis attempts to capture and describe all the needs of the system, and establish a domain class (in the system being processed) model in this system. The purpose is to provide an understandable thing that enables developers to communicate with this system between the establishment of demand personnel. Therefore, the analysis is a typical guidelines with the user or customer collaboration.

Developers should not think about code and programming in this analysis phase; it is just the first step in designing system and demand under design.

demand analysis. The first step of the analysis is to draw the system will be used and who will use it. These are all use cases and roles. Use examples describe what features provide in terms of functionality: the functional requirements of the system. A use case analysis includes reading and analyzing system requirements instructions, as if the system potential useer (customer) is discussed.

The role inside the library is confirmed as library managers and readers (borrowers). Library management is a system of users, while readers (borrowers) are customers, customers refer to people who take out and save books and magazines from libraries, sometimes a library management or a library management personnel It may be a reader (borrowing person). Readers (borrowers) are not directly interacting with the system; their behavior is working by library staff. The use cases of the library management system are:

L Len ITEM

l Return (Return Item)

L Make RESERVATION

l Remove Reservation

l Add Title

l Update or Remove Title (Update or Remove Title)

l Add Item

l Remove item

l Add Borrower)

l Update or delete readers (borrowers) (Update or Remove Borrower)

Since libraries often have multiple popular titles, the system must distinguish between the title and the title of the project.

Library management system analysis is made into an example of UML, as shown in Figure (-). Each use case describes the interaction between the use case and the role in more detail. This text is defined after the user / customer discusses.

Figure (1)

All use cases are online; lend item use examples are described below:

1. If the reader (borrowing person) is not retained:

l book title is identified.

A obtained column (item) identified by the title of l book title.

l reader (borrowers) is identified. The library borrows this item (book).

L The new borrowed is recorded.

2, if the reader (borrowing people) is reserved:

l The reader is identified.

l book title is identified.

A obtained column (item) identified by the title of l book title.

L The library borrows the corresponding book (item).

L The new borrowed is recorded.

l Reserved is deleted.

In addition to the functional requirements of the system, use cases are often used to analyze whether the appropriate whole domain class (Domain classes) has been defined, and they are also used to determine if the technical solution to deal with the necessary functions during design. The use case can be visualized in the sequential diagram, and the sequential diagram will be described in detail.

Domain analyysis. An analysis also lists the entire domain (the main class of the system). To illustrate a domain analysis, reading requirement instructions and use cases, and browsing those "concepts" that should be processed by the system. Or organize users and domain experts to conduct a collective discussion, try to identify key concepts (issues) that must be processed (Issues), along with each other.

These library management systems are listed below: BorrowerInformation (So naming For the Reader / Borrowing Human Role), Title, Book Title, Magazine Title, Item, RESERVATION, and LOAN. They have been written as a graphical chart along with their relationship, as shown in Figure (2). The whole domain class is defined by "business object", and the business object is a set of custom class objects, which are part of the whole country key. Moreover, they should be long-lasting in the system.

Figure II)

Some classes have a UML state diagram to display different status of these objects, along with events that make them changing state. The class available in the online available state map is Item and Title. The sequence diagram of the use of the book (Lend Item, Reader does not reserve record) is shown in Figure (3). The sequence diagrams of all use cases are available online.

Figure (3)

When drawing the sequence diagram, it is necessary to provide a role as an interface as an interface. In this analysis, it is necessary to fully understand that the window interface is facing, save and also projects (book). The detailed user interface is no longer described here. In this analysis, in order to distinguish the form class and the whole country, the form class is placed in the "GUI Package" package, and the whole country is placed in the "Business Package" package. design

The design phase is to further explain the analysis model by parsing all technical implementation and constraint relationships. The purpose of the design is to describe a work-effective solution to program code as possible as possible.

Design can be divided into two parts:

Frame (structure) design. This is the advanced design defined by the package (subsystem), including the dependence (relationship) and the main communication mechanism between the package. Naturally, a clear and simple frame (structure) is the goal we design. If all possible, this frame package should be small, and the two-way dependence (relationship) should be avoided. detailed design. Here, all classes are fully described in detail; a clear manual gives a clear manual for programmers (people who write these classes). The dynamic model of the UML is often used in a particular situation in a particular situation.

* Frame (Structure) Design

A design excellent framework is based on an expandable and changeable system. The package can be involved is not to deal with a special functional area is to deal with special technical areas. The logic of the interval application logic (all domain class) and technical logic is critical so that any part of the change does not affect another part. One goal is to identify and establish rules between the package (e.g., subsystem) to establish a rule in order to be established between the packets (to avoid the binding between the packets). Another goal is to identify the needs of the standard library. Today, in the technical area development library (URL), such as user interfaces, databases, or communication, but more specific programs develop libraries are also expected.

The package or subsystem of this research case is shown in the following:

User-Interface Package. These classes are based on the Java Language AWT package, and AWT is a standard library in the Java language, designed to write user interface applications. This package and business-objects package collaborate, the business object package contains classes that actually store data. The UI package calls the operation method of the business object to retrieve and insert data.

Business-Objects Package. Includes a worldwind from an analysis model, such as BorrowerInformation, Title, Item, Loan, etc. Design completely define their operational methods and add to persistent support. Business Object Pack and Database Package Collaboration, because all business object classes must be inherited from the persistent class in the database package.

Database package. Database packages provide services to other classes of the business object package so that they can be kept. In the current version, persistent classes will store its subclass object in the file system.

Utility package. A practical package contains services (functions) for other packages in the system. Currently, the OBJID class is the only class of this package. It is used to mention the lasting object, throughout the system, including user interface, business object, and database package.

The intrinsic design of these packages is shown in Figure (4).

Figure (4)

*detailed design

Detailed designs describe the new technology class - user interface and database package; at the same time, the business object is enriched in the analysis process. Class, static and dynamic maps are often used in the analysis, but now they are defined more detailed and higher technology levels. The use case depiction of the analysis is often used in the case where the design of the design is processed; the sequence diagram is often used to illustrate how the system is implemented in technology.

Database package. The application must have a persistent storage, so a database layer must be joined to provide this service. For the sake of simplicity, we store the object in the form of a file on disk. The details of the storage are invisible from the application, and their calls are called, for example: Store (), update (), delete (), and find (). These methods are part of a persistent call class, and all classes that require persistent objects must inherit it.

One important role in persistence processing is an Objid class, which is applied to any object involved in the system (regardless of whether or not the object is still in the disk). Objid, a simple object, is a well-known technique in an application to elegantly refer to the processing object. With the use of an object identifier, an object's ID can be passed through a normal persistent.getObject () method, and the object will be re-returned from persistent storage. It is usually done through a getObject method in each persistent class, which also performs the necessary type of type check and conversion. The marker of an object is also easy to be used as a parameter between a method (for example, a search window, looking for a special object, can pass the results to another form by the object identifier).

Objid is a general class that is used by all packets (user interfaces, business objects and databases), so it has been placed in the packet instead of placing in the database package.

The current persistent class can be improved. Finally, the persistent class interface has been defined as an implementation of the lasting storage. Some alternative methods can be stored in a relational database, or stored in an object-oriented database, or using Java1.1 supporting persistent objects to store them.

Business-Objects Package. The design of the business object package is based on the analysis of the corresponding package (all domain class). Categories, their relationships and behaviors are protected, but these classes are described in more detail, including how to achieve their relationships and behaviors.

Some operations in the design model have been converted to several operations (methods), and some have changed the name. This is normal, because analysis is only a summary of each class, and is a detailed description of the system. Therefore, all operation methods in the design model must define the name and return value (due to space limit, they are not shown in Figure (5), but they are available online). Note the following changes between design and analysis:

Figure (5)

• The current version of the system does not check if a project is timely returns, and the system has no processing inventory classification. Therefore, in the Loan and the RESERVATION class, the date attribute is not implemented.

• The title of the magazine and books is the same, in addition to the period, do not have to be processed. In the analysis model, the words of the magazine and books think that it is not needed, just a TiTle class with a Type property indicates that a title is a magazine or a book. There is nothing in the object-oriented design, that is, the design cannot simplify the analysis. If the simplification of the above two points in the future version is considered to be required to be removed.

The state diagram from the analysis model is also detailed in the design, which is displayed in the operation system how to behave and process. The status map of the Title class in the design model is shown in Figure (6). Other objects can change the status of the Title object by calling the address () () method, as shown in the figure.

Figure (six)

User-Interface Package. The user interface is "top" of other packages. It will presen a user in the service and information of the system. As you know, this package is based on standard Java AWT (Abstract Window Toolkit) class.

The dynamic model of the design model has been placed in the Graphical User Interface (GUI) package, as all and the user interaction begins with the user interface. Once again, the sequence diagram is selected to display a dynamic model. The implementation of the use case design model is exactly detailed, including the true method of operation.

The sequence diagram is actually established in a series of repetitions. Things found during the implementation (encoding) leads to a deeper layer. Figure (7) Displays the sequence diagram of increasing the title in the design model. Operation methods and signals correctly indicate that they appear online code.

Figure (7)

The collaboration map can be used instead of the sequence diagram, as shown in Figure (8).

Figure (8)

User-interface design. A special to complete behavior is a user interface during the design phase. In the library application, the user interface is based on the case, and has been divided into the following sections. In the main window menu, each part has given a separate menu bar.

•Features. The main function window of the system is, that is, borrow, reply, and formulate reservations.

•information. Browse the system information window, information about the collected borrowers and book titles.

•maintain. Maintain the window of the system, that is, increase, update, and name, borrow people and projects.

Fig. (Nine) shows an example of a class diagram in the user interface. This figure contains a typical AWT event processor. Attribute buttons, title, edit box are not displayed.

Figure (9)

Each form typically presents a service of a system and mapping an initial use case (although not all user interfaces are mapped from one use case). Establishing a successful user interface beyond the scope discussed herein. Welcome readers to study the UI code of this application online, which is developed using the Symantec Visual Cafe environment.

achieve

The program is written in the system construction or implementation phase. The need for this system application specifies that this system can run in multiple different processors and operating systems, so Java is selected to implement this system. Java readily prepares mappings of logical class-to-code components because a pair of classes are shot into a Java code file.

Figure (10)

Figure (10) Examples Examples In the design mode, the components (for this case) contain a simple logical view class to the mapping of the component view components. The logical view is also mapped to the package of the component view accordingly. Each component contains a link to the class description in a logical view makes it easy to navigate between two different views (even, in this case, it is just a simple use of the file name). The dependency between the two components (except for the business object package) is not displayed because these dependencies can be obtained from the class diagrams from the logical view. For writing code, the specification summarizes the following various charts in the design model:

• Class specification: Each class, detailed display of the required properties and operation methods.

• Class diagram: Class diagram is the rendering of the class, showing its static structure and the relationship to other classes.

• Status diagram: The state diagram of the class, the display of possible status and the conversion that needs to be processed (along with the method of triggering this conversion).

• Dynamic charts (sequence diagrams, collaboration diagrams) in class objects, including: implementation or other objects of the chart display class or other objects using this class object.

• When developers need more about how this system is used (when the developer feels, he or her for detailed comprehensive context is being confused), the example shows the result of the system used.

Naturally, the lack of design is not guaranteed at the stage of code. New or modifications of demand may be identified, which means that developers will have to change the design model. This is happening in all items. It is important for synchronous design models and code so that this model can be used as a system final document.

The Java code example given here is the LOAD class and a part of the TitleFrame class. The Java code for the entire system application is available online. When studying the code, apply the UML model with your heart to read it, at the same time, try to see how the UML structure is converted into code. Consider these:

• The provisions of the Java package are equivalent to the specified of the package included in the component or logical view class.

• Private properties correspond to the description of the properties in the model; at the same time, naturally, the Java method corresponds to the model.

• The OBJID class (object identifier) ​​is called to achieve a combination, meaning that these joints are in the same way as this class (because this OBJID class is persistent).

The example of Listing 1 comes from the Loan class, which is a business object class to store information about the lending. This implementation is direct, because this class is mainly the place where information is stored, so the code is simple. Most of the functions are the persistence class inheritance from the database package. The only attribute of class is the union relationship of this object identifies the iTem and BorrowerInformation class, which is also stored in the Write () and READ () operation method.

You can test the addbutton_clicked () operation method of displaying the sequential diagram (Figure 7) context relationship between a title 2 in Listing 2. Read the code along with the sequence diagram, you will understand the description of the collaborative relationships described in more detail.

The code in all sequential diagrams in the design model is included in the source code (the operation method and class name are displayed in the sequence diagram).

Test and deployment

When the code is written, the role of the UML will not stop. For example, use the example map to verify that the completed application is very good for them. Moreover, a convenient document is provided for the deployment model of the system and the text of this article.

to sum up

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

New Post(0)