Introduction
Unified Modeling Language (UML) is a common simulation language that can be used to determine, display, and record the design process of software systems. Graphic markup in a unified modeling language, especially for Object-Oriented software design. It has two advantages:
(1) UML is a widely recognized standard in the international software industry. It unifies the mark and meaning of object simulation and enables software design tools to play a greater role, the existing object design can also be more easily reused.
(2) UML has been widely used, and it balances the conciseness and conciseness. In short, UML has become a separate system for evolution, unlike the problems caused by the previous multi-standard system.
Therefore, as software developers, it is absolutely necessary to learn and understand UML. This article provides a case study. I just want to use this case study to give you a perceptual knowledge of UML and learn how to use UML to write applications in the real world. So I tried to find a relatively complicated case and found that the Library's applications dealing with lending and pre-lending books and magazines are quite large examples, it is sufficient to explain how UML is used in the real world.
I used use cases and domain analysis to analyze and describe an application in an analysis model. I expanded it into a design model, it is used to describe a representative part of the technical solution. Finally, we use the Java language for encoding. But remember, what I provide is only a possible solution. There are many other solutions that you need to use your mind to explore, in addition, there are no solutions suitable for all situations in the world. Of course, some solutions will be better than others, but it will only accumulate knowledge after you have enough experience and many difficult things you encounter and solve them. Okay. Next we will go to the case study.
Requirements
Generally, the requirements are written by the representative of the end user of the system. For Library applications, the requirements should be as follows:
1. The library application should be the library support system.
2. The conditions for the library to lend books and magazines to the borrower (readers) are of course that the reader should have registered the books and magazines in the system.
3. The library handles the purchase of new books or magazines. The best-selling books or magazines should be bought several more books, old books and magazines should be properly removed from the shelf when they are outdated or broken.
4. The librarian is a member of the library. His role is to deal with the customer (borrower) and complete the work through the system.
5. The borrower can borrow a book or magazine that is not in the library currently. When the book is returned or bought from the library, he will receive a notification; when the borrower borrows the book or magazine, the reservation is canceled. You can also use the display program to cancel the reservation.
6. The library can easily create, update, and delete information such as the name of the book in the system, borrower, borrower, and preborrow.
7. The system can run on all popular operating systems, including UNIX, windows, and OS/2. It should also have an advanced and friendly GUI (GUI ).
8. The system should easily use new function extensions.
In this case study, the first version of the system does not need to process a pre-borrowed book by a reader and send a message to the reader when the book is available, you do not need to check whether a book has timed out.
Analysis
The purpose of analysis is to obtain and describe all the requirements of the system and generate a model that defines key domain classes in the system. The goal is to establish mutual understanding and communication between developers and those who set requirements. Therefore, analysis is a typical behavior of cooperating with users or customers. At this stage, developers should not consider specific code or program details; this is only the first step to truly understand the requirements and the actual situation of the system being designed.
Section 1 Analysis Requirements
The first step of analysis should be to determine what the system will be used for and who will use it. These are the so-called use cases and actors ). Use Cases describe the specific functions of the library system, that is, the functional requirements of the system. A use case analysis process includes reading and analyzing specifications and discussing potential users (customers) of the system ). The actors in the library are librarians and borrowers. the librarians are users of the system, while the borrowers are customers. The readers who view and book books and magazines should be borrowers, but sometimes it may be a librarians or another library. The borrower does not need to deal with the system directly. The function of the borrower is done by the librarian.
The Use Cases of the library system are:
Borrow Books
Return books
Generate reservation
Delete reservation
Add Bibliography
Update or delete a bibliography
Add books
Delete books
Add borrower
Update or delete the borrower
Because there are often several best-selling books in the library, the system must differentiate the best-selling books from the normal bibliography.
If the borrower does not preborrow a book:
Identify the name of a book to borrow.
Identify books currently available in a library
Identify the borrower
The library lent the book.
Register the lending situation that has just occurred.
If the borrower has preborrowed a book:
Identify the borrower.
Identify the name of a preborrow.
Identify the books currently available in a library.
The library lent the corresponding books to the borrower.
Registration and lending.
Delete the record of a pre-Borrow book.
In addition to defining the functional requirements of the system, use cases are also used to analyze and check whether the appropriate discussion domain class has been defined, and whether they can be used during the design process to confirm that the technical solution can handle the required features. Use Cases can be seen in the sequence diagram to implement some technical details.
Section 2 Domain Analysis
During the analysis, we also need to list in detail the domain (the key class in the system). To analyze the domain, it is necessary to fully understand the specifications and use cases and focus on the "Concepts" to be handled by the system; or to organize a collective seminar with users and discussion domain experts, try to find out all the key concepts that must be processed and their relationships.
The domain categories of discussion in the library system are as follows: borrowerinformation (this name is used to distinguish the actors borrower in the use case chart), title, book title, magazine, item, reservation, and loan. Figure 2 is a class chart that shows the relationships between them. These discussion domain classes are user-defined classes, specifying the objects of these classes as part of key domains and saving them permanently in the system.
Figure 2 explains the domain class structure. Domain analysis should detail the key classes in the system. For each object, when it calls methods on another object, it must add a line between classes to describe their relationship. Each rectangle frame used to represent a class is divided horizontally into three parts. The top one is the class name, the middle is the class attribute, and the bottom one is the class method. The association between the two classes is represented by one implemented connection, indicating that an object calls the method of another object. If you observe it carefully, you will also find that "0 .. 1" on the loan end associated with the item represents the number of Desirable Objects on that end.
Some Classes use UML state diagrams to display the different states of these class objects and events that can change their State. For example, the examples in this article are item and title. Figure 3 is a sequence diagram of the use case of lend item (the borrower has not preemptible books ).
Figure 3: A Sequence diagram of the borrowing scenario. This scenario shows a specific process of using cases. The scenario is always started with an actor, that is, a person outside the system. Then record the complete routes that have been completed through the system until all actors are taken. The UML notation used to mark a scenario is a sequence diagram. This sequence diagram illustrates a scenario where the borrower did not preborrow a book.
When modeling a sequence diagram, it is obvious that we need to provide an interface with a window or dialog box to the actors. In this case study, in order to distinguish window classes from the discussion domain classes, we put the window classes into a package named "Gui package, when we put the discussion domain class into a package named "business package", we should clearly provide the borrow, pre-borrow, and return interface windows. At this time, we do not need to define a specific user interface.
Design
When all technical details and restrictions have been taken into account, we can enter the design stage. The design stage needs to expand and refine the analysis model. The purpose of the design is to illustrate a work solution that can be easily translated into program design code.
The design phase can be divided into two parts:
1. structure design this is a very advanced design that describes where the package (subsystem) is defined and the dependency and communication between the package and the package. Naturally, our goal is to build a clear and simple architecture with less dependencies between packages. If possible, we should avoid two-way dependencies.
2. The detailed design of some classes should describe enough details to specify who will encode these classes. The dynamic model in UML is used to demonstrate the behavior of objects in a specific environment.
I will describe it in detail below.
Section 1 Structure Design
A well-designed architecture is the basis for developing a scalable and changeable system. The focus of a package is either to process a specific functional area, either process a specific technical area. It is extremely important to distinguish the application logic (domain class) from the technical logic in order to modify a part of the program without affecting the other part: one goal is to identify and set the dependency rules between packages (such as "subsystems, instead of creating two-way dependencies between packages (to avoid too tight integration of packages), another goal is to represent the needs of standard class libraries. Currently, the available application libraries focus mainly on technical fields, such as user interfaces, databases, or communication mechanisms. However, we also look forward to more specific application libraries.
The packages or subsystems in this case study are as follows:
1,User Interface package(User-interface) these classes are based on the Java AWT package, a standard class library used to write user interface applications in Java. This package works with business object. A business object package contains classes used to store data, the User Interface package calls methods in commercial objects to obtain and insert data into commercial objects.
2,Business Object package(Business Object) It includes domain classes from analysis models, such as borrowerinformation, title, item, and loan. This design completely defines their operations and adds support for durability. The commercial object package cooperates with the database package. All commercial object classes must be inherited from the persistent class in the database package.
3,Database packageDatabase package provides services to another class in the Business Object package so that they can store information permanently. In the current version, the persistent class stores its subclass objects in files in the file system.
4,Utility package(Utility package) the utility package contains services used for another package in the system. Currently, this package only contains the objid class, which is used to reference persistent objects throughout the system, including the user interface, business Objects and database packages.
The internal design of these packages is shown in Figure 4.
Figure 4 An overview of the library application structure. This is a class diagram that describes the application packages and their relationships. The database package provides durability, the public package provides the Object ID class, and the commercial object package contains the discussed domain class, which will be listed in detail in Figure 5. Finally, the UI package based on the standard Java AWT class library calls the operations in commercial objects to insert data into them.
Section 2 Detailed Design
Design and describe the new class in detail-the class in the user interface and database package, and the person other than the commercial object class described in this analysis. The status and dynamic charts of this category use the same charts as those in the analysis process, but they are defined at a more detailed and higher technical level, the use case description in the analysis process is used to verify the use cases processed in the design phase, and uses a sequence chart to illustrate how each use case is technically implemented in the system.
Database package applications must have persistent storage objects, so a database layer must be added to provide this service. For simplicity, we store objects as files on disks, the details about the storage do not need to be known by the application. It calls general operations, such as store (), update (), delete (), and find, these are part of a class that calls persistent. All classes must inherit the persistent (Persistent Object ).
An important factor in persistence processing is the objid class. Its objects are used to reference persistent objects in any system (whether the objects are on disk or have been read into the application ). Objid is short for Object Identity and is a well-known technique used to process object references in applications. By using an object ID, an object ID number can be passed to persistent. GetObject (), and the object will be retrieved from persistent storage. Generally, this is done through the GetObject operation in each persistent class. It also needs to perform necessary type checks and conversions. The object identification number can also be easily passed as an operation parameter (for example, a search window for a specific object can pass its results to another window through the object identification number ).
Objid System(User interface, business object, and database) All packages use a common class, so it is put into the utility package in the design phase rather than in the database package. The current implementation of the persistent class is not perfect yet. Its ultimate goal is to easily change the implementation of persistent memory, currently, the alternative is to store objects in relational databases or object-oriented databases. You can also use persistent objects in Java to store them.
Business Object packageIn the design phase, the commercial object package is based on the corresponding package in the analysis process-discussion domain class. Classes and their relationships and behaviors have not changed, but classes are described in more detail, including how they interact and act.
Some operations have been translated into several operations in the design model, and some have been renamed. This is normal because analysis only depicts the capabilities of each class, the design is a detailed description of the system. Therefore, all the operations in the design model must have defined features and return values. Note that the differences between design and analysis are given below.
Figure 5 explains the design of business objects. This chart enriches the design of various classes for Business Object packages. The interface is more precise, and the Data Type of the attribute is selected.
The current version of the system does not have to check whether a book is returned in a timely manner, nor does it have to process orders for books in advance. Therefore, the date attribute of the loan and reservation classes is not implemented.
The process of processing a magazine and a book is the same. In addition to the different borrowing periods, it does not need to be processed. In the analysis, the magazine and book title sub-classes have been considered unnecessary and only one type attribute in the title class specifies whether the title indicates a book or magazine. In future application versions, both of these two features can be deleted if they are considered necessary.
The status chart in the analysis process is refined in the design phase, showing how the status is represented and processed in the work system. Title class design status chart 6. Other objects can change the title status by calling addreservation () and removereservation (), as shown in this chart.
Figure 6 explain the status chart of the Design Title
User Interface package the user interface package always provides services and information in the system before other packages. Obviously, this package is based on the standard Java AWT (Abstract Window Toolkit) class. The dynamic model in the design model has been allocated to the GUI package, because all interactions with users start from the user interface. In addition, we also select a sequence chart to describe the dynamic model, the implementation of the design model in this case is described in detail, including the actual operations in the class. Sequence charts are actually created in a series of iterations. Further iterations will be generated when more details are explored in the implementation (encoding) phase. Figure 7 shows the sequence chart of the result of adding title.
Figure 7 sequence diagram of adding Title
We can also use a collaboration chart instead of a sequence chart, as shown in figure 8.
Figure 8 illustrates the collaboration diagram of Add title.
Section 3 User Interface Design
In the design phase, we use a specific activity to create a user interface.
The user interface in the library application is based on this use case and has been divided into the following parts. On the main window, each of its parts has been given a separate menu bar:
1. The window that functions the main functions of this system is used for borrowing, returning books, and registering with and borrowing books.
2. The window for viewing information in the information system is used to collect information about the title and borrower.
3. Maintain and maintain the system window to add, update, and delete titles, borrowers, and books.
Figure 9 is an example of a class diagram in the user interface package.
Figure 9 describes the function graph model.
In general, each window provides a service in the system and maps it to a use case (even if not all user interfaces must be mapped from a use case ), A successfully created user interface is beyond the scope of this article. For more information, see the Code provided later. I will discuss this issue in a special article later.
Implementation
The program design starts in the construction or implementation phase. Application requirements require that the system can run on a variety of processors and operating systems, therefore, the Java language is the best choice for implementing the system. Java can easily map logical classes to code components, because a class has a one-to-one ing to Java code files. Figure 10 shows the simple ing between the class in a logical view and the component in the component view in the component chart of the design model in this example. Each component contains a link to the class description in a logical view, which makes it easy to locate between different views (even if, as in this example, it simply uses the file name ). Dependencies between components are not expressed in component charts (except for commercial object packages), because dependencies between components can be derived from class diagrams in the logical view.
Figure 10
To code, you need to obtain the specification from the following charts in the design model:
Class Specification: the specification of each class, used to describe necessary attributes and operations in detail.
Class diagram: class diagram of the class to be introduced, which describes its static structure and its relationship with other classes.
Status chart: The status chart of the class, indicating the possible status and the transition period to be processed (and the operation to trigger the transition period ).
The dynamic diagram (sequence diagram, collaboration diagram, and activity diagram) contained in the class object ): A chart that describes the implementation of a specific method of a class, or a chart that describes how other objects use class objects.
Use Case charts and specifications: when developers need to know the system usage information, describe the results of the system being used (when developers feel confused by the details of the entire system ).
Obviously, the deficiencies in the design phase will be exposed in the encoding phase. We need to find out which operations need to be updated and which operations need to be modified, which means developers will have to change the design model. This kind of problem occurs in all project development. What's important is that we need to synchronize the design model and code so that the design model can be called the final design of the system.
Consider the following points:
The Java package specification specifies the equivalent code of the component or logical view to which the class belongs.
Private attributes comply with the attributes specified in the model. In addition, the Java method conforms to the operations in the model.
The objid class (object identifier) is called to implement Association, which means that the Association is usually saved together with the class (because the objid class is a persistent class ).