Part 4 – Analyzing a Legacy Application with Altova UModel
In Part 1 of this series we imported source code into Altova UModel to create a UML project and we examined a class diagram of our legacy ATM application. In Part 2 we created a series of UML use case diagrams to describe user interactions with the system and we planned an application enhancement to implement a withdrawal fee. In Part 3 we designed a UML state machine diagram to further analyze and document the operation of our system. In this installment we will return to our planned enhancement. We’ve been assigned to implement an ATM withdrawal fee of $2 for withdrawals less than $100 and $4 for withdrawals of $100 or more. In Part 2 we drew a use case diagram to show how users will interact with the new feature: From our original analysis of the object-oriented classes in Part 1, we know our system contains a Withdrawal class, which is the logical place to implement our new feature. We can display a new class diagram for the Withdrawal class by selecting it in the Model Tree and choosing from the right-click context menu to create a new diagram. We chose to create a hierarchy diagram so all the properties of the Withdrawal class are visible, including inherited properties from the Transaction class. Before implementing the fee feature, we have a related leftover question to investigate. We wanted to verify that the current code includes a test to make sure a withdrawal amount requested by the user does not exceed the current account balance. A UML sequence diagram will let us trace the execution flow of a withdrawal. UModel can automatically generate sequence diagrams from the operations of reverse-engineered classes. We can select the execute operation in our class diagram and choose Generate Sequence Diagram from the UModel right-click context menu to create the diagram we need. The UModel Sequence Diagram Generation dialog offers several options that will assist with our implementation of the new feature. We selected Automatically update because we will want to update the diagram later after we modify the code, and showing the code in a separate layer can help us focus on the withdrawal logic. The size of the scroll handles indicates we are only seeing a small portion of the sequence diagram in the current window. We can shrink the view to fit the window, but the text will probably be illegible. Instead, let’s take advantage the flexible UModel user interface to auto-hide the Diagram tree and Properties windows, which allows us to enlarge the Overview helper window: We can explore the sequence diagram by dragging the red square in the Overview window. This lets us quickly locate the comparison of the withdrawal amount and account balance. We can also see the error messages that display if the ATM does not contain enough cash or if the account balance is too low. Returning to the Withdrawal class diagram, we can add the fee property and set its default value: We’ll make a first pass through implementation of the fee logic without including the user cancel option. Updating the source code from our model adds the fee property to the Withdrawal class. Then we’ll jump into our favorite source code editor to implement the fee logic directly in the Withdrawal.java file. Testing our recompiled application shows the following: The starting balance was $147. After withdrawing $100, the new balance is $43. The fee is displayed in a new message, and the ending balance is correct. But now the sequence diagram in our UML model is inaccurate because it doesn’t include the fee feature. We can correct the sequence diagram by updating the UML project from the revised source code. The UModel Messages window indicates that changes in the Withdrawal.java file caused the sequence diagram to be regenerated. And, we can easily navigate the diagram to locate our new test of the withdrawal amount to see if the fee needs to be increased to $4. Now that our modified sequence diagram graphically represents updated operation of the ATM, we can be assured the harried driver we met in Part 3 of this series has enough cash to buy that ice cream cone! In our next installment we’ll take advantage of another UModel feature to generate rich project documentation for our work so far – one more advantage of keeping our UML model and application source code synchronized. If you’re ready to try Altova UModel on your own Java, C#, or Visual Basic legacy application, click here to download a free fully functional 30-day trial.