Write a Java application using UML

xiaoxiao2021-03-06  148

Introduction Unified Modeling Language (Unified Modeling Language) is a universal analog language that can be used to determine, show and record software system design processes. The graphical tag in the unified modeling language, especially for object-oriented software design. It has two advantages: (1) UML is a widely recognized standard for international software industry. It unifies the markings and meaning of object simulation, so that software design tools can play more functions, and existing object design can also More easily reuse. (2) UML Bozi, set local balanced simplicity and embarrassment, UML has become a separate system to evolve, unlike the previous various standard systems. Therefore, as a software developer, it is necessary to learn, understand UML. This article provides a case study. I just want to use this case study to give you a sense of sensibility to UML, understand how to use UML in the real world to write applications. So I want to find a relatively complicated case, I found it, discovering that the library handles lending and the application of books and magazines are considerable examples, which is enough to explain how UML is used in the real world. I just use the case (Use case) and discussion domain analysis to analyze an application in an analysis model, I extend it into a design model, used to describe a representative part of the technical solution, and finally, we use Java language. Code. But remember, I have given only a possible solution, and many other solutions require you to discover in a smart mind, and this world is not suitable for all situations. Of course, some solutions will be better than others, but only have enough experience and many difficult things that have encountered and will accumulate knowledge. Ok, let's go to the case study. In general, it is a representative of the ultimate user using the system to write requirements. For library applications, request specifications should be as follows: 1. The library application should be the support system of the library. 2, the library will borrow books and magazines to borrowers (readers). Of course, readers should be registered in the system. The same books and magazines should also be registered in the system. 3. Library handles the purchase of new books or magazines, best-selling books or magazines should purchase more books, old books and magazines, should be appropriately put down from the bookshelf when they are outdated or broken. 4. Book administrator is the staff in the library. His responsibilities are to deal with customers (borrowers) and complete their work through this system. 5. Borrowing books can be presented in a book or magazine currently not in the library. When this book is returned or purchased into the library, he will receive a notice; when the borrowers borrow this When books or magazines, it is scheduled to be canceled; or the display procedure can be used to cancel the pre-borrowing. 6, the library can easily create, update, and delete information in the system, borrowers, borrowing, and pre-borrowing information 7, which can run all popular operating systems, including UNIX, Windows, and OS / 2, it should also have advanced friendly graphical user interface (GUI). 8, the system should be easily expanded using new features. In this case analysis, the first version of the system does not need to handle a reader's pre-borrow book to send a message to the reader, and do not need to check if a book is timeout. The purpose of analysis and analysis is to obtain and describe all requirements in the system, and generate a model that defines a critical domain class in the system. Its goal is to establish mutual understanding and communication between developers and the required people, and therefore analyzed is a typical behavior that cooperates with users or customers.

At this stage, developers should not consider the specific code or program details; this is just the first step in truly understanding the actual situation of the system and the design of the system. The first step in the first quarter analysis requires that the system should be to determine what the system will be used and who will use it. This is the so-called use case and actor. Use the case describe which features should be provided in the library system, that is, the functional requirements of the system. A case analysis process includes reading and analyzing specifications and discussing potential users (customers) of the system. The actors in the library are book administrators and borrowers. The library administrator is the system of the system and the borrowers are customers, views and book books and magazines should be borrowers, but sometimes it is possible. It is a library or another library. The borrowers don't need to be dealt with directly to the system, and the books of the bibliots are completed through the library administrator. The case of the library system is: borrowing books Generate booking Delete Book Add Bibliographic Update or Delete Bibliographic Add Book Delete Book Add Borrowers Update or Delete Borrowers because of a good selling book in the library, often have several books, Therefore, the system must distinguish the bestseller from the ordinary book. If the branch is not presented to book: Identify the name of the book like the book to be borrowed. Identify the book identifies the book identifier Borrower library from this book to lend this book. Register the procedure just happen. If the borrowers have preused to borrow a book: Identify the borrowers. Identify the name of the presence. Identify books currently borrowed in the library. The library lends a book that borrowers. Register the lending situation. Remove the record of the pre-borrowing book. In addition to defining the functional requirements of the system, use cases are also used to analyze whether the appropriate discussion domain class has been defined, and whether they can be used in the design process to confirm that the technical solution can handle the required Features. Using a case can be seen on the sequence diagram to implement some technical details. In the second section, the discussion domain analysis analysis must also list the discussion domain (the key class in the system). In order to discuss domain analysis, it is necessary to fully understand the specifications and use cases and focus on the "concept" that the system will process; Or organize a collective seminars with users and discussion experts, try to find all the key concepts that must be handled and the interrelationships between them. The discussion domain class in the library system is as follows: BorrowerInformation (this name is to distinguish between actors in the case chart), Title, Book Title, Magazine, Item, RESERVATION, and LOAN. Figure 2 is a class diagram that marks their interrelationships. These discussion domains are user-defined classes, specifying the objects of this class being part of a critical domain and will be kept in the system. Figure 2 explanation: the domain structure. Domain analysis To list the key classes in the system. For each object, it calls another object, which is to explain their relationship between the class. Each rectangular frame used to indicate the class is horizontally separated from three parts. The top one is the name of the class, the middle is the properties of the class, and the bottom is a method of class. The association between the two classes uses a connection representative that symbolizes an object to call another object. If you carefully observe, you will also find "0..1" of the Loan end associated with Item, representing the number of objects that can be taken at the end. Some types of UML state diagrams show different states of these classes and events that can make them change, as described herein is Item and Title. Figure 3 is a sequence diagram of the use of lend items (the book is not pre-borrowed). Figure 3 Interpretation: Sequence diagram of borrowing books. This scenario gives the specific process of using the case, and the scenario is always the beginning of an actor, that is, the system other than the system.

Then record the complete route that is completed through the system until the action of all actors. UML notary method for labeling a scenario is a sequence diagram. This sequence diagram is used to illustrate a scenario, that is, the borrowers do not have a borrowing scenario when a book is borrowed. When we model the sequence diagram, it is obvious that we need to provide the actors with an interface interface with the window or dialog. In this case analysis, in order to distinguish the window class from the discussion domain class, put the window class into a package called "GUI Package", and put the discussion domain class into a "business package" The package should be clearly needed to provide borrowing, pre-borrowing books, and bibli interface windows, and there is no need to define specific user interfaces. Design When all technical details and restrictions have been considered, we can enter the design phase, and the design phase 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 programming codes. Design phases can be divided into two parts: 1. Structural design This is a very advanced design, explaining where the package (subsystem), and the interdependence and communication mechanism between the package and the package. Naturally, our goal is to build a clear and simple architecture, the dependence between the bags and bags is less, if possible, try to avoid bidirectional dependence. 2. Detailed designs All classes should describe enough details to clearly define who codes these classes. The dynamic model in UML is used in the behavior of objects of objects in a specific environment. I will explain it in detail below. The first section structure design a well-designed architecture is the basis for developing an extensible, variable system. The package needs to be cared for either dealing with a specific functional area, or dealing with a specific technical area. It is extremely important to distinguish the application logic (domain class) in the technical logic, which is in order to modify a certain part of the program without affecting the other part: a goal is to identify and set the package and package The interdependent rules between (eg "subsystems") are not creating two-way dependencies (in order to avoid tightness of the package integration), and another goal is to represent the needs of the standard class library. The application library available now emphasizes the main technical field, such as user interface, database or communication mechanism, etc., but we also hope that more specific application libraries. Packages or subsystems in this case study are as follows: 1. User-Interface These classes are based on Java AWT packages in Java to write a standard class library for writing user interface applications. This package is collaborated with the business object package, and the business object package contains classes that actually stored data, and the user interface package calls the method in the commercial object to get and insert data to the business object. 2, business object, which includes discussion domain classes from analysis models, such as BorrowerInformation, Title, Item, Loan, etc. This design fully defines their operations and adds support for persistence. Business object packages work with database packages, all business object classes must inherit from the Persistent class in the database package. 3, Database Package Database Package to another class in the business object package to make them sustainable storage information. In the current version, the Persistent class will store its subclass object to the file in the file system.

4, the Utility Package Utility package contains the service for another package in the system, now only Objid classes in this package, which is used to reference the persistent objects throughout the system, including user interface, business Objects and database packages. The internal design of these packages is shown in Figure 4. Figure 4 Interpretation of the Structure of the Library Application Structure. This is a class diagram that describes the relationship between the application package and between them. The database package provides persistence, the public package provides the Object ID class, and the commercial object package contains discussion domain classes, which will be detailed in Figure 5. Finally, insert data from them in the middle of the UI packet of the standard Java AWT library. Section 2 Detailed Design Detailed Design Description New Class - In the user interface and the class, people outside the commercial object class depicted in this analysis. The status and dynamic charts of this class use the same chart as in the analysis process, but they are defined in more detail and higher technical levels, and the use cases during the analysis process are used to verify the use cases in the design phase. Using a sequence chart illustrates how each case is implemented technically implemented. The database package application must have a persistent storage object, so you must add a database layer to provide this service. For the sake of simplicity, we store the object as a file on disk, and you don't need to be known by the application. Call common operation, such as Store (), update (), delete (), and Find (), etc. These are part of the class calling the Persistent class, and all classes require inheritance of the Persistent (persistent object). An important factor in persistence processing is the OBJID class, which is used to reference the persistent object in any system (regardless of the object is on the disk or has been read into the application). Objid is an Object Identity, is a well-known technique for processing object references in the application. By using an object identifier, an object identification number can be passed to the persistent.getObject () operation, and then the object will be retrieved from the persistent memory. Typically, this is done through the getObject operation in each persistent class, which also performs the necessary type of type check and conversion. The object identification number can also be easily passed as a parameter (for example, a search window for a specific object can pass through the object identification number to another window). Objid Identification System (User Interface, Business Object, and Database) A conventional class used, so it is placed in the design phase instead of database packets. The current implementation of the Persistent class is not perfect. Its ultimate goal is to change the implementation of the persistent memory. The current alternative is to use the object exhibit a relational database or object-oriented database, or use Java's lasting Object supports them. The business object package in the design phase is based on the corresponding package - discussion domain class. Categories and their interrelationships and behaviors have not changed, but the class is described more detailed, including their interrelationship and behavior. Some operations have been translated into several operations in several design models, and some have been changed, which is normal, because analysis is just the ability of each class, and design is a detailed description of the system, so design All the operations in the model must have a definition feature and return value, note that the design and analysis is given below. Figure 5 explains the design of the business object. This chart enrichs the design of a variety of different classes of the business object package. The interface is more accurate, and the data type of the property is selected. The current version of the system does not have to check if a book is timely returns, and there is no need to deal with orders for pre-borrowing books, so the date attribute of the Loan and the RESERVATION class is not implemented.

The process of processing of magazines and books is exactly the same, in addition to the borrowing period, and it does not have to be processed. In the analysis, the Magazine and Book Title subclasses have been considered unnecessary and only one type attribute in the Title class specifies whether the book name indicates a book or magazine. In the later application versions, these two simplification can be deleted if necessary. The status chart in the analysis process is refined in the design phase, which is displayed in the working system how to be represented and processed. The design status chart of the Title class is shown in Figure 6. Other objects can change the status of the Title by calling addRservation () and removeRVATION (), as shown in this chart. Figure 6 Interpret Design Title's state diagram User Interior Bag User Interior Fair is always in the system, which provides services and information to users, apparently, this package based on standard Java AWT (Abstract Window Toolkit) class. The dynamic model in the design model has been assigned to the GUI package, because all of the user's interaction starts through the user interface, in addition, we also select a sequence chart to illustrate the dynamic model, the implementation of the design model of this case All described in detail, including the actual operations in the class. The sequence chart is actually created in the form of a series of iterations. Discovering on more details in the implementation (ie, the encoding) phase will produce a further iteration. Figure 7 shows the results of the results of add title design sequence chart. Figure 7 Explains the sequence diagram of add title. We can also use the collaborative chart instead of the sequence chart, like Figure 8. Figure 8 explains the cooperation map of the 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 case, and has been divided into the following sections. On the main window, each of its part has been given a separate menu bar: 1, the main unit The window is used to borrow books, also books, and registration work with books. 2. Information of Viewing Information in this system is the information used to collect book names and borrowers. 3. Maintaining the window of the system is used to add, update, and delete book names, borrowers, and books. Figure 9 is an example of a class diagram in a user interface. Figure 9 explains the function class diagram model. In general, each window provides services in a system and maps to a case (even if all user interfaces must be mapped from a case), create a successful user interface beyond the scope of this article Reader friends, please refer to the code provided after Wen. I will also discuss this issue in the future. The implementation program is designed to construct or implement the stage, the application requirements require that the system can run in a variety of different processors and operating systems, so the Java language is the best choice for this system. Java can map logic class-to-code components because one of the one-to-one mapping of the Java code file. Figure 10 illustrates a simple mapping of component charts in this example model containing the components of the class to the component view in a logical view. Each component contains links to the description of the class in a logical view, so that positioning between different views is easy (even, in this example, it is just a simple use of file name). The dependence between components is not expressed in the component chart (except for the business object package), because the dependencies between the logical view can be derived from the class diagrams in the logical view. Figure 10 intends to coding, to get specifications from the design model: Class Specification: Each class specification is used to illustrate the necessary attributes and operations in detail. Class diagram: The class diagram of the class it wants to explain, indicating its static structure and interrelationships with other classes. State diagram: The state diagram of the class, illustrates the possible state and the transition period that needs to be processed (and the operation of the transition period).

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

New Post(0)