How to migrate from code-centric to model-centric development using Rational Software Architect

来源:互联网 发布:mysql配置引擎 编辑:程序博客网 时间:2024/05/22 13:02
 
In order to develop higher-quality software more efficiently, you and your organization can benefit from model-driven development. Using Rational Software Architect, you can migrate from a code-centric to a model-centric approach.

Model-centric development is one of the hottest topics discussed in software engineering circles today. A tenet of model-driven development (MDD), it is an extremely powerful way to create software when paired with model-driven architecture (MDA). And why shouldn't it be? There is a great deal of benefit to using models as part of your overall development lifecycle. To start, modeling your application can be extremely helpful in understanding your system as it is created, from two standpoints: that of the objects that you wish to use in your project, as well as the relationships that each of those objects have with the rest of your nascent system.

Also, the ability to see the overall system architecture while your application is being created is another significant advantage of MDD and MDA. Since you are able to view the overall design of your application, you are able to visually modify your system as you find problems, or if you need to extend its capabilities during program design and analysis. This extends into every aspect of your application, from initial design right down to the deployment layer. Why is this so important? It insures that you're efficiently designing the total application, thereby eliminating critical bottlenecks and defects before they become larger issues later in your development timetable.

If you'd like more information about MDD and MDA, or any of the products discussed in this article, I encourage you to read the material suggested in the Resources section.

Okay. I've spent a small amount of time detailing why MDD and MDA are important, and let's say -- for purposes of discussion -- that I have convinced you that it is something you should consider implementing in your hallowed halls of software.

But -- there's one small problem. Here's a question that you could ask regarding MDD and MDA:

"We don't use model-centric development techniques today -- we code and code and code. That's what we have always done. How can we bring all those modeling techniques you mention into our shop, so we can see the benefits and get a good return on investment?"

In taking that all-important question a step further, there are a number of obstacles that you will face as you make the transition from one paradigm to another. You must make sure that there is a straightforward way to bring your code into a model-driven development environment. As well, you need to ensure that you can improve upon it using these new concepts without a great deal of hassle. Your development environment should not only embrace model-driven best practices, but make it easy to apply and deploy them throughout your application(s) -- assisting you with the ability to make use of the aforementioned concepts in the most efficient way possible.

It is also important to give you as much information as you can read (and possibly more) about all of the new processes that you are implementing. This assists you in understanding:

  • The new paradigm that you have been thrust into
  • The just-out-of-shrink-wrap program that you're using (and spent a lot of money on) to propel your development efforts forward as much as possible, as quickly as possible

Introducing the Atlantic set of products and Rational Software Architect
If you've been keeping track of the happenings around the IBM® Rational® product line of development tools, we've just released a new set of products, code named Atlantic. Atlantic was specifically designed to take advantage of Eclipse 3.0, and to link the business, development, and operations areas of your organizations more tightly.

With the Atlantic release, a brand new product is on the market -- one that leverages model-driven development with the power of the Unified Modeling Language (UML) to create applications and related services that are architecturally sound. This is the IBM® Rational® Software Architect (RSA) product), and you'll be using it to take your first steps -- from the code-centric development model you are used to -- into the model-centric development world that we are introducing you to (or re-acquainting you with) in this article.

You'll be using RSA in order to import some previously developed code. Next, you'll see the migration of the code into the model-driven development arena by visualizing it as UML models within RSA. You will then continue your adventure into the model-centric development paradigm by further extending the model (created in Rational Software Architect) utilizing additional UML concepts along with application development best practices within MDD and MDA. Of course, no migration treatise would be complete without detailing some of the other ways you can be more productive with RSA and MDD; as described previously, we will be discussing the various tutorials, examples, and walkthroughs built into RSA to increase your productivity with the product and the aforementioned concepts that may not be familiar to you.

Enough about what you'll do. There is no better way to learn than by doing, so with that...

Bringing your application code into Rational Software Architect

Taking a look at your pre-existing code
You cannot get started on your adventure without a small bit of code to show you exactly what we're talking about. As a preparatory step, we've created a few classes in Java that access some of the Microsoft Windows® Internet diagnostic utilities -- ipconfig, finger, ping and tracert. We access them through a main Access class -- all standard, easy java tooling (for those of you interested in something more complex, don't worry, we will be tackling more meaty concepts in future articles on IBM® developerWorks® Rational®). Figures 1 and 2 show a listing of the created files, and a sample of our Java code in action.

Figure 1: The Java classes we have created


Figure 2: Run Java code, run!

While this code was very straightforward to write, we ran into a couple of issues when analyzing the thought process behind it. We knew that we wanted to write some code that accessed the Internet functionality, and it took a bit of time to get it right -- not because we had trouble writing the actual code, but because we wanted to design the code to be modular and efficient. Yes, we could have simply written one class and been done with it, but that was not the point. The point was to make it so that the overall effort could be expanded upon and enhanced at a moment's notice.

The first thing that you need to do before you can realize the benefits of using your new paradigm is to import this code into RSA. RSA looks similar to many of the other integrated development environments (IDEs) you may be used to: it runs in Eclipse 3.0, and utilizes perspectives to target specific areas you want to focus on while you are developing software.

What is Rational Software Architect?
While RSA may look similar to other IDEs you have used, its advanced features set it apart from the pack. While you undoubtedly have heard that statement before, let's cover a few of the differentiators that you'll find in this product:

  • Requirement artifact, concept, and association tracking (with IBM® Rational® RequisitePro®)
  • Model creation, diagramming, analysis and transformation using UML 2.0
  • Code development in C++, the Java™/J2EE™ platform, and Enterprise Generation Language (EGL)
    • Patterns, transformations and reusable assets
    • Runtime and static problem detection and analysis
    • Support for JSF, SDO and Web Services
  • Application testing and deployment
  • Software development process guidance (with the IBM® Rational Unified Process®, or RUP®)

It contains all of the functionality of the new IBM® Rational® Application Developer and IBM® Rational® Web Developer tools, as well as the new IBM® Rational® Software Modeler product, making it a very credible development solution for a variety of projects and development tasks. RSA even lets you extend its functionality, from adding Java pluglets, all the way to extending the very workbench you're using to develop your programs. We'll cover more of RSA's features -- and how you can use them when working on your projects -- in this and future articles on developerWorks Rational.

Importing code into Rational Software Architect and visualizing our application in a UML class diagram
After starting up RSA and creating a Project (Java, naturally) to hold your work, you can import your code using a menu item, as shown in Figure 3 following.

Figure 3: Importing our code into Rational Software Architect(click here to enlarge)

Tip: You can also use RSA to automatically look at any problems your application may have as you are coding, to help you maintain quality. Look for the Problems tab (visible from any of the perspectives you are in) to get started. For more information on this, look over the help files.

After importing your code into RSA, switch to the modeling perspective and create a UML model from it, so you can see how UML has characterized your work.

Now, you may be thinking, "But this is Java code. Why should I be seeing this in a UML model instead of a Java class diagram?" You are doing it this way to see how your code is visualized as an UML model. Because you are shifting paradigms, it is important to understand how your code looks as a UML model, and then build on that with other types of models to illustrate the benefits of adopting model-centric development.

From the Modeling perspective, make the Model Explorer active and right-click on the Project name, then click New > UML Model (Figure 4).

Figure 4: Creating a new UML model in Rational Software Architect(click here to enlarge)

Once you have done that, leave the defaults as they are (template type Blank Model, with a diagram type of Class Diagram, since we will be viewing our imported classes in the UML class diagram). We named our model ni_classdiagram (The ni stands for net_import, the name of our project in RSA), as shown in Figure 5 below.

Figure 5: Specifying the type of model

In order to visualize your classes in RSA, all you have to do now is drag each of the classes from the Model Explorer right onto the class diagram. UML visualization in RSA lets you populate UML class diagrams with Java. Class diagrams model the static structure of a system: the objects that comprise the system, as well as the relationships among the objects within the system. This will be perfect for seeing the overall structure of your code, as well as the relationships that your classes have to each other.

Looking at Figure 6, you can see your visualized application, and how your main Access class relates to all of the Internet access utilities we have written.

Tip: You can also quickly visualize your classes by right-clicking on them and clicking Visualize > Add to Current Diagram.

Figure 6: Viewing your application's structure as a UML class diagram(click here to enlarge)

When you see the application's architecture onscreen, there are a few things that are immediately apparent that you couldn't otherwise have seen (unless you were intimately familiar with every aspect of your code):

  • The Access class has one main function
  • Each of the helper classes contains a constructor class and a usage class
  • The Access class uses each of the helper classes in order to accomplish it's goal (characterized by the UML use dependency relationship diagrams, which look like partially lined arrows)

The key thing here is that you're able to see both the classes and their interactions visually. When doing model-centric development, this allows you to get a good idea how your system should function before you code. Even though you already have your code in this example, modeling your application allows you to understand its architecture and functionality better, making your coding easier and more efficient. Even though you may understand this example extremely well, seeing it visually gives you instant recognition of how your application is constructed.

Now, this may not matter much with a simple example like this, but imagine building a more complex system with lots of classes, full of subsystems and interfaces, and interacting with disparate data sources (such as databases). You would definitely want to take a visual look at your system to make sure you're doing things right -- sooner, rather than later.

Utilizing additional modeling in Rational Software Architect to understand and improve your application architecture
Alright. you have taken some Java code, imported it into RSA and, through UML visualization, were able to see your entire application in one class diagram. So, is this the entire benefit of model-centric development? In a nutshell, no. We were only looking at one way in which modeling a system can benefit your engineering efforts. To continue to realize how this method of software development can improve your efforts, let's bring in a couple of additional UML modeling types to help understand different ways to view and define our application.

Using use case diagrams to model application behaviour
We mentioned earlier that when writing code -- particularly when coding an application -- the hardest part is not actually writing the code, but figuring out how you want to write it so that it is flexible and efficient. One of the ways that MDD (and through that, RSA) can assist you is by helping you understand how you want your system to behave. To better understand model-centric development concepts, take a step back from the code and analyze the behaviour of your system. While it may seem strange to do this, starting at the beginning of the modeling process will help you not only understand your code better, but assist you in the future when modeling other systems. As such, let's take a look at your system using UML use case diagrams.

Use case diagrams are constructs that model the main functions of a system, and identify initial interactions between the system and its environment. Using your project and the class diagram you have already created as a starting point, create a use case diagram to make sure you understand the behaviour of your application.

Figure 7 shows how you create a use case diagram in RSA. From the Model Explorer, right click on the model in your project, and then click Add Diagram > Use Case Diagram.

Figure 7: Creating a use case diagram in Rational Software Architect(click here to enlarge)

Tip: if you forget to name your use case diagram, and later wish to change the name to something more palatable than the default, switch over to the Diagram Navigator within the Modeling perspective, navigate to your brand new use case model (which should be named Diagram 1), and right-click it to bring up the specific menu.

In this example, you will create a use case in your diagram for each of the previously modeled utility classes, since they represent the main functionality of our system. As the Access class serves as the part of your system that interacts with the other pieces, you'll model that as an actor within your diagram.

Your use case diagram can be seen in Figure 8.

Figure 8: Modeling the behaviour of your application as use cases(click here to enlarge)

You can see from the above use case that the behaviour of your system mirrors its implementation closely. It almost goes without saying that -- when creating an application -- expected system behaviour does not always match actual system implementation. Being able to begin your software development efforts by outlining system behaviour via a use case diagram really helps you create a quality application architecture and design. Because you are able to model application functionality and help capture requirements with use cases, you are able to design your system more efficiently earlier in its lifecycle.

Using sequence diagrams to model application execution flow
When you create a system using model-centric development techniques, one of the things you also want to be reasonably sure about is the execution flow of your application. It is not enough to model the desired functionality and the overall structure of your system; to get a real idea of what your application will do, you must elaborate on how you wish your application to execute said functionality.

Sequence diagrams take the capturing of application behaviour one step further, and let you see a closer view of the interactions between the classes that they are creating. It does this by modeling the logic flow within your system, detailing interactions between your application's class methods and allowing you to journal method entries and exits. You can create sequence diagrams that show expected application flow (modeling the application you are working on), as well as real-time application flow. (working with applications that are already deployed). Sequence diagrams can also be used to model other system activities, such as usage scenarios or additional application services (web services, business transactions). For more information on sequence diagrams, you can consult the help files or RUP documentation (see Resources).

We've taken our sample code and created a sequence diagram in order to show you a bit of the execution flow of the Access program. Figure 9 shows you a portion of the sequence diagram we've created, in which we detail how the methods of the Ipconfig class interact with the Access class. First, the Ipconfig's constructor method is called, and then the Ipconfig's showDHCP method is called to get the actual data that the Access class needs.

Figure 9: Modeling the flow of our application with a sequence diagram(click here to enlarge)

One of the invaluable abilities that a sequence diagram provides is clear in Figure 9: you can profile exactly how your application works (or should work). This is another way in which MDD and MDA make software engineering much more efficient, since you are able to have a more in-depth view of your application's functionality. You can make any necessary changes to your design prior to writing a line of code.

Within RSA, you can also utilize more of the UML 2.0 specification's other models and diagrams in order to further extend your design efforts. While we won't attempt to cover all of them in this article, it is important to know about them, for they may be able to assist you as you continue to adapt your development environment to include model-centric engineering concepts.

The UML 2.0 models and diagrams represented in RSA include the following:

  • Activity diagrams
  • State Machine diagrams
  • Composite Structure diagrams
  • Component diagrams
  • Deployment diagrams
  • Communication diagrams
  • Freeform diagrams

Transformations and how they can bring modeling efforts to code results in order to extend your system's design

Throughout this article, you have seen how modeling can be invaluable to efficient application architecture and design. You started by turning existing code into a class diagram so that you had a picture of how your code looks as a model. To further support MDD, you have seen how models can aid you in specifying your application's functionality through use case diagrams, as well as assist you in detailing your application's execution flow via sequence diagrams. (Finally, you were introduced to additional UML models that you can use to specify even more of the aspects of your system).

There is a bit more to it than simply that, however. With all of the above information must also come the following realization: the benefits that you are getting by using the model-centric approach must be also realized in the code that you create from the model(s). Otherwise, the efficiency gains that you are making by adapting from one paradigm to another will be for naught.

RSA allows you to get the maximum benefit out of your design efforts with its ability to transform elements from one type to another. It lets you transform anything from text files and UML models to UML, Java, EJBs, and even C++. (If you remember, the first part of this article dealt with the UML visualization of your Java code.)

Previously, you brought code into RSA, transformed it into UML, and created additional models. Coming full circle, you will use those models to extend your design by adding some functionality to your application.

Figure 10 shows your existing use case model, to which you have added a new behaviour: the addition of the Netstat Java class (this accesses the netstat Windows Internet utility) to your application design.

Figure 10: Adding the Netstat use case to our diagram(click here to enlarge)

Now that you have added this behaviour in the use case model, you should also revisit our class diagram and add the Netstat class in UML, as shown in Figure 11. You can also add a couple of operations to the Netstat class, mimicking the same level of functionality that your other classes have.

Figure 11: Updating the class diagram with the Netstat UML class(click here to enlarge)

To complete your updates, you should also update the sequence diagram to model your new method interactions with the Netstat class. Since it is similar to the others, it might be a pointless exercise, but it never hurts to be complete. Figure 12 shows the updated sequence diagram.

Figure 12: The updated sequence diagram (with Netstat operations added)(click here to enlarge)

Once you have made all the additions to the application models, and verified that the behaviour and interactions that you added are correct (meaning they do what you intended to do), you should complete the following to finish your updates:

  • Transform the Netstat UML class in your class diagram into a Java class
  • Add functionality to the Netstat Java class (and update the Access class)
  • Update your models to ensure that they are current
  • Verify that the results are the ones you expect

First, you will transform the UML, as shown in Figures 13 and 14. Figure 13 shows the transformation menu item being chosen. Figure 14 details the transformation window, covering things such as source UML class and the target UML element in which you want the Java to be placed. You can also specify transformation mapping details, as well as common transformation actions. For more information on this window, and regarding transformations in general, you can consult the help files.

Figure 13: Transforming the UML to Java(click here to enlarge)


Figure 14: The transformation window

Next, you can tackle giving your new class additional functionality.

Before you can test your changes to the application, you first have to add the functionality to your Netstat class, as seen in Figure 15. You also have to make sure that the Access class knows about the new class, so we will add extra functionality there as well.

Figure 15: Adding functionality to the Netstat Java class(click here to enlarge)

After you are done with that, you need to address the issue of keeping the model up to date. For that, you will use RSA's java editor, which gives you some special features for editing Java code. Though we won't cover all of its functionality here, its features include the following:

  • Code completion assistance
  • Integrated debugging
  • Syntax highlighting

For a full listing of the features of the Java editor, please see the help files.

Figure 16 shows how to use the Java editor to replace the UML class (modeled previously) with its actual Java counterpart in your class diagram.

Figure 16: Using the Java editor to update the class diagram(click here to enlarge)

Note: Java Editing is not an automatic process. When updating Java in RSA, you will have to update your diagrams manually.

Now, after all of that, you may wonder if the new code you added will actually work. You should definitely test this in RSA. To do that, switch over to the debug perspective and test your updated application from there.

Figure 17 shows the Run dialog box from the debug perspective. Note that the project and main class are already specified.

Figure 17: The run dialog box accessed from the debug perspective

Once you are finished configuring the dialog box, Figure 18 illustrates how it looks running in RSA.

Figure 18: Testing the new changes by running your code(click here to enlarge)

Success!

Excellent. You have used RSA to successfully migrate an application from code-centric principles to a model-centric paradigm by introducing and applying MDD concepts, and that's a very good thing.

Using the Help system, RUP Process Advisor and Process Browser to increase your knowledge of model-centric development concepts and Rational Software Architect
Wow. We have taken quite the tour of RSA to work on our application, and introduce the model-driven development paradigm. One of the things you need to be aware of while you are doing this is that there are a lot of other functions -- that we did not cover -- that you can use in your specific development projects. RSA can help you with them, particularly if you are trying to include them in your current or future slate of engineering projects.

Within RSA is a good amount of information on developing application types such as portals, EJB applications, and portlets, to name a few. RSA can help you understand additional modeling concepts and help you with team development concepts. To begin with, RSA's help files can assist you with the concept of reusing artifacts you may be working on. The help system contains guides, tutorials, samples, and other content that is extremely useful.

In addition, RSA contains two other powerful tools that can help you understand the concepts we have been talking about. These are the RUP Process Browser and the RUP Process Advisor. The Process Browser window displays RUP help in a separate window, letting you browse through topics that you might find useful while developing software. The Process Advisor gives you context-sensitive guidance on any of the elements in your diagram. You can reach both of these extremely helpful tools from RSA's help menu.

Figures 19 shows the Process Advisor tab in the Modeling perspective, and Figure 20 takes you to the Tutorial gallery inside of RSA's help menu. Please spend some time referencing these valuable resources. You can also refer to developerWorks Rational for regular updates on RSA, as well as look at up-to-date information on the rest of the tools in the Atlantic product release.

Figure 19: The Process Advisor in the modeling perspective(click here to enlarge)


Figure 20: The Tutorials gallery (click here to enlarge)

Conclusion
It is one thing to introduce a new product in an article and ask you to use it. Articles do that all the time. It is another thing, however, to assist you in migrating to a new paradigm, which unquestionably will lead to improvements in your software engineering efforts. To adapt your application creation environment from code-centric to model-centric development can be difficult and confusing, and there are few tools that let you do it as easily -- and allow you to do it in such a robust manner -- as RSA.

These products and technologies (yes, even the new ones) are key components of IBM's Software Development Platform -- a comprehensive set of products, services, and processes that let you maximize your software development capabilities across your entire organization.

Resources

Articles:
"An introduction to Model Driven Architecture - Part I: MDA and today's systems" (DeveloperWorks, January 2004) will broaden your understanding of MDA.

To help you make sense of what we've been discussing in this article, read "The Holy Grail of model-driven development".

Another modeling article that may be useful is "The Value of Modeling".

In order to get a little more information on what Rational Software Architect is, in addition to reading this article, please take a look at its product information page on developerWorks Rational, or view some recently published information here .

Documentation:
For more information on the Rational Unified Process methodology and related product, you can peruse the online documentation available here.

Press Release:
For more information on the Atlantic products, see the main press release here.

Websites:
Main Atlantic product page - located at:
http://www.ibm.com/software/awdtools/architect/swarchitect/index.html

developerWorks Rational Software Architect product page - located at:
http://www.ibm.com/developerworks/rational/products/RSA

For more information on Rational Software Architect's implementation of UML 2.0 diagrams, or on UML 2.0 itself, consult the help files or the UML website at http://www.uml.org

For more information on the Software Development Platform, take a look at this developerWorks website.

Webcasts:
Newest Features & Capabilities of the IBM Software Development Platform - located at:
http://www-106.ibm.com/developerworks/offers/lp/wc/?S_TACT=104AHWS_CMP=

Atlantic product discussion forums:
You can find discussion forums for all of our products - located at:
http://www.ibm.com/developerworks/forums/dw_rforums.jsp

Demos:
Setting up the Eclipse Development Environment -- located at:
http://www.devx.com/DevDemos/Door/22166

Training:
Classes on Rational Software Architect, UML 2.0 and the rest of the 'Atlantic' software release:
http://www.ibm.com/developerworks/rational/training

Acknowledgements
Thanks to Lee Ackerman, Khawar Ahmed and Gary Clarke for all of their help in making this article happen.

Take care, and it has been a pleasure having you read this!

原创粉丝点击