Uml 2 toolkit phần 6 pdf

55 258 0
Uml 2 toolkit phần 6 pdf

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

In terms of which diagrams to use, the bulleted list below provides sugges- tions. Whatever helps the project succeed you should pursue. Again, do not duplicate information unnecessarily. Look for the most elegant way to capture the system and communicate with the project’s stakeholders. ■■ The use-case diagram references behavior through a set of activities. Use this diagram to make certain that the work remains in scope. The stick- men and circles provide a good scoping mechanism for the project, but do not have the ability to show detailed flow. Do not misuse this tool and try to turn it into a flow or business-analysis mechanism. ■■ The activity diagram provides a high-level overview of a system not tied to system classifiers. Use this diagram to show the flow of a system, even for things going on outside of the system you build. The diagram can provide a useful “you are here” map for everyone communicating about the project. In addition, the diagram can help in the definition of domain entities with the input and output pins that can link to real sys- tem elements. ■■ Object diagrams and internal structure diagrams can provide some impor- tant information about which classes have active behavior. These dia- grams provide a required input for the interaction diagrams and state machines. ■■ The interaction diagrams can show the detailed messages that occur in a specific action or set of actions. Such detail gets very close to the code level and provides a good way to communicate about the interaction between objects. Use this diagram for review of issues closer to the implementation code. You can link the sequence to an action in your system, which lets you move easily from an activity diagram down to a sequence diagram. ■■ The state machine shows the complex life cycle of an object. Use this to review active objects or the internal dynamics of the more complicated objects in your system. Some use state machines as the core diagram for code generation. ■■ The protocol state machine shows how an entity relies not only on the environment but also on the current circumstances for execution. Use this machine to show how components work with ports in a distributed environment. UML 2 introduced the notion of ports as well as protocol state machines, which modelers use to show how classes relate to their environment and to behavior. These new features support object-oriented methods specifically tar- geted at real-time systems not well supported in UML 1.x. Advanced Dynamic Modeling Illustrated by Real-Time Systems 245 Much of the modeling with ports reflects approaches long pursued by other designers and only recently explicitly imported into the core of UML. In particular, the ROOM (Real-Time Object-Oriented Modeling) language is a mature modeling approach (Selic et al., 1994) complemented with heuristics and work organization guidelines for creating models of real-time systems. This approach provides the main influence on the ports and protocol state machines in UML 2. The language is based on an actor concept (not to be con- fused with actors in use cases) that is an active class. These actors, or active classes, are described as a state machine that can have nested substates. The active class is defined with interface components called ports. Each port defines a protocol: input and output messages and their legal ordering. An active class can have several ports and can thus reflect different roles of that class. Passive data objects can also be modeled, and the active classes can be placed in layers. If you review the protocol state machine, it is easy to see the influence of the ROOM method. Other approaches that might be of interest to those who want to pursue the intellectual tradition of this topic include OCTOPUS (Awad et al., 1996), which is an adaptation of OMT (Rumbaugh et al., 1991) to real-time systems. A more recent approach to real-time development emphasizing UML in a more light- weight process is ROPES (Rapid Object-Oriented Process for Embedded Sys- tems). Whatever approach and diagrams you decide to pull from the toolkit, they should further the goals of the project. For the discussion of the impor- tance of process in software development, see Chapter 10. Performance Optimization The use of pure forms of abstraction can unfortunately lead to degradation of performance. When performance optimization is important, a conflict might arise between the “ideal” object-oriented model on one hand and performance on the other, so that the actual implementation has to be optimized. That includes taking shorter routes in the communication between objects (so that an object gains direct access to an object to which it normally does not have access) and merging classes to decrease the number of layers between different parts of the software. This strategy can improve the performance, though at the cost of decreasing the modularity of the software. The emphasis in UML on components helps to address these trade-offs; a well-designed system of com- ponents (including Web services) can provide optimal behavior. Given the complexity of real-time systems, the need to design precise and descriptive models is more important than it is in normal systems. Good mod- els, even if complex, allow a client to understand the trade-offs made during optimization. If the decision has an impact on the client’s business, the mod- eler has the responsibility to communicate the options clearly. As usual, opti- mizing in one area requires a trade-off in another part of the system. 246 Chapter 6 Design Optimization As part of optimization, review the active objects. Preferably, review the design with an internal group to walk through the system before presenting to a client. Also, consider using one of a variety of automated tools to assess the performance of the existing program. If possible, active objects should be implemented as threads rather than as processes. Threads can execute together in the same memory space are definitely “cheaper” for the operating system in terms of performance. It is also necessary to check if active objects can be merged, thereby avoiding the sharing of passive objects, with all the synchro- nization handling this requires. Other guidelines for achieving higher perfor- mance include: ■■ Using synchronous communication (for example, operation calls) instead of asynchronous communication ■■ Reusing message objects or other frequently used objects instead of continuously recreating them ■■ Avoiding copying objects between different memory spaces TIP To guide you to the “right” places, consider a tool such as a profiler (a profiler shows where the processor spends its execution of a program, that is, which parts of the program are most often used). Make sure to review the new design and your assumptions with other software architects. Such detailed optimization work might be necessary when trying to achieve maximum performance. However, the first place to look for optimization pos- sibilities is at the overall design level. Often an improved overall design can mean huge gains in performance, gains that are almost impossible to achieve by optimizing the lowest level. That said, if your design is deployed in an envi- ronment that does not effectively support your strategy for handling your active objects, performance still suffers. Optimization and the Operating System Complications arise when the underlying environment does not have ade- quate support for real-time constructs, such as processes or threads as well as communication and synchronization mechanisms. Real-time operating sys- tems also require optimization and trade-offs. A tight system such as that used for embedded systems might perform very fast but might not extend to other environments so easily. The operating system can be either a standard system that supports real- time constructs, such as Windows, Linux, or Unix, or a specialized operating system optimized for embedded systems. The operating system could also be Advanced Dynamic Modeling Illustrated by Real-Time Systems 247 a Java Virtual Machine running on one of these systems. The quality of the real-time services (performance, reliability, ease of programming) depends on the operating system used and is not a property of the object-oriented lan- guage or method. Object-oriented design models the system under construc- tion and maps models onto the services provided by the operating system. With a platform-specific model, as used in Model Driven Architecture, or MDA (see Chapter 9), the model can fit very closely with the platform’s method of handling these constructs, by employing the correct set of UML extensions. Whatever system you use, focus on the performance elements most needed for achieving the system’s goals. Modeling helps communicate issues and helps validate ways to solve problems. Review the use cases to make certain that the design is not missing something crucial that the users need from the system. Keep the client’s goals in mind when deciding on how to optimize a system. Present the trade-offs and walk the client through the implications of the different strategies. If the client wants 99.99 percent availability, for exam- ple, walk them through the design implications of such performance and see if their system really needs such support. Relevant Changes in UML 2 This chapter reflects more change from the first edition than any of the other chapters so far. UML 2 now handles a number of concepts related to complex design in dynamic systems. Relevant changes include the following: ■■ Activity diagrams have been rebuilt so they now provide powerful tools to model concurrent behavior. Based on Petri Nets, the new activ- ity diagrams model dynamic flow relying on the notion of tokens. Activity diagrams can now easily show interruptible activities, multiple flows, exception handling, and protected regions. ■■ Active classes and objects are now represented with the addition of a thin vertical line in the class rectangle rather than as a thick line. ■■ Sequence diagrams now include defined combined fragments that show areas where message ordering is critical. Sequence diagrams can also show areas where parallel processing is possible. ■■ Concurrent execution in a state machine and parallel processing is now shown by orthogonal regions on a composite state. These orthogonal regions add up to the total state machine for a classifier. ■■ The protocol state machine includes firmer definitions of the rules for the ordering of operations for interfaces and ports. This feature helps when working with components. 248 Chapter 6 ■■ The new timing diagram provides a way to handle time along one axis of an interaction diagram. This diagram allows for mapping state and behavior to clear time units, which helps in the analysis of real-time design issues. ■■ A state machine has clearer extension rules so that portions of a state machine can be used in a number of places and can work with a classi- fier that is part of an inheritance hierarchy. ■■ A substate machine has clear rules for entry and exit points, making it easier to reuse the submachine in different diagrams. ■■ The new interaction overview diagram provides an advanced way to model all the issues for a given interaction. This diagram helps consoli- date the many different strands and fragments of interactions the mod- eler needs to review for UML 2. ■■ Events are now called triggers to emphasize it is how the event is han- dled, not the event itself, that drives behavior. ■■ UML now includes standard features for observing and creating con- straints based on the time and duration of behaviors. Summary To specify a model for a real-time system, you must consider time require- ments, concurrency, asynchronous communication, and synchronization. A real-time system is often embedded, meaning that the software is tightly inte- grated with specialized hardware. UML has concepts to address these real- time issues. Real time and object orientation are integrated through the definition of active classes and objects. An active class has its own thread of control and thus can initiate actions by itself. That is in contrast to “normal” passive objects, which execute only when some other object performs some operation on it and passes back the control when the operation returns. Active classes and objects are implemented through processes or threads supported by the operating system. Active objects communicate either through ordinary operation calls (called synchronous messages in the object-oriented world) or through specialized mechanisms such as mailboxes or message queues in which messages can be delivered asynchronously. An asynchronous message means that the sender doesn’t wait for the receiver to be ready to accept the message, nor does it automatically wait for any return result. The behavior of active objects is mod- eled using triggers that launch events. Advanced Dynamic Modeling Illustrated by Real-Time Systems 249 Synchronization mechanisms are things such as semaphores or critical regions that protect a specific code area, which in turn protects some shared resource, such as a passive object or a device. Synchronization mechanisms are used to prevent problems such as conflicts in parallel usage of shared objects, deadlocks, or just inefficient resource usage of the processor caused by having threads executing in endless “busy wait” loops. UML can let you work with basic real-time constructs in a variety of dia- grams. Activity diagrams provide the high-level workflow with the ability to model concurrency. Static diagrams are needed to show the active and passive classes. The interaction diagrams provide detail on the messages between actual system objects. The state machine shows the transitions in the life cycle of a class or object. The protocol state machine shows the rules for shifting between states often used with ports to help show the environmental requirements. In designing a real-time system, it is important to determine a basic model for separating processes/threads from objects. You need to identify and define active classes, and communication among and synchronization of the active classes. Be ready to recognize the trade-off between performance and design, discussing the options openly with the client. This chapter has focused on the static and dynamic modeling required by real-time systems to illustrate advanced features. With the emergence of dis- tributed enterprise computing and Web applications, deployment architecture has become critical to project success. The next chapter looks more closely at how you can use UML to model the logical and physical architecture of your system. 250 Chapter 6 251 A system architecture is a blueprint of the parts that together define the system: their structure, interfaces, and the mechanisms that they use to collaborate. By defining an appropriate architecture, you make it easier to navigate the sys- tem, to find the location of a specific function or concept, or to identify a loca- tion to which to add a new function or concept so that it fits into the overall architecture. The architecture must be detailed enough so that it can be mapped to the actual code. An architecture that is both easy to navigate and sufficiently detailed must also be scalable, meaning that it can be viewed on different levels. The architecture, for example, should provide a top-level view that includes only a few parts. From there, the developer should be able to select one part and examine its internal architecture, which consists of more parts. Using a tool, it should be possible to “zoom into” different parts of the system to study them in greater detail. A well-defined architecture allows the insertion of new functions and con- cepts without imposing problems on the rest of the system. This is unlike an old monolithic system where one small change in one part of the system could cause something seemingly unrelated to stop working because of complex relationships across the system. The architecture serves as a map for the developers, revealing how the sys- tem is constructed and where specific functions or concepts are located. Over time, this map may have to be changed because of important discoveries and experiences along the way. The architecture must “live” with the system as the Representing Architecture CHAPTER 7 system is being developed and constantly reflect the system’s construction in all phases and generations. Naturally, the base architecture is defined in the first version of the system, and the quality of this initial architecture is vital for enabling developers to change, extend, and update the functionality of the sys- tem. In private communication, Grady Booch, one of the leaders of the defini- tion of the UML, has said, “It is possible for an inexperienced team to succeed within a well-structured architecture, while an expert team will be hard pressed to succeed without such a roadmap.” The UML definition of architecture is as follows (as taken from the UML 1.4 specification): Architecture is the organizational structure and associated behavior of a system. An architecture can be recursively decomposed into parts that interact through interfaces, relationships that connect parts, and constraints for assembling parts. Frank Buschmann and his coauthors in the text Pattern-Oriented Software Architecture, Volume 1: A System of Patterns (Buschmann et al., 1996) offer another definition of software architecture: A software architecture is a description of the subsystems and components of a software system and the relationships between them. Subsystems and compo- nents are typically specified in different views to show the relevant functional and nonfunctional properties of a software system. The software architecture of a sys- tem is an artifact. It is the result of the software design activity. Although the architecture must have sufficient detail, it must also serve as an abstraction of the detailed design. Len Bass and his coauthors in their text Software Architecture in Practice (Bass et al., 1997) remark as follows: Software architecture must abstract away some information from the system (otherwise there is no point looking at the architecture, we are simply viewing the entire system) and yet provide enough information to be a basis for analysis, deci- sion making, and hence risk reduction. While one must be able to demonstrate that the architecture can support the functional requirements of the system, other systemic concerns drive architec- tural decisions. A particular architectural element or architectural pattern might have been selected to best support the basic precepts of quality engi- neering such as loose coupling, understandability, and minimal redundancy. Other architectural decisions can be traced to specific nonfunctional require- ments such as performance, scalability, or security. The architecture is described in a number of views, and each view concen- trates on a specific aspect of the system. The complete picture of the system can be made only by defining all views. In UML, these views are usually defined as follows: 252 Chapter 7 ■■ Use-case view ■■ Logical view ■■ Concurrency view ■■ Component view ■■ Deployment view A broader separation usually divides the architecture into the following: ■■ Logical architecture ■■ Physical architecture These architectures are described further in this chapter. So, with all these definitions in mind, what constitutes a good architecture? Here are some guidelines for answering that question: ■■ A correct description of the parts that define the system, both in terms of the logical architecture and the physical architecture. ■■ A map of the system within which a developer can easily locate where a specific functionality or concept is implemented. The functionality or concept may be either application oriented (a model of something in the application domain) or design oriented (some technical implemen- tation solution). This also implies that requirements of the system should be traceable to the code that handles it. ■■ Changes and extensions should be easy to make in a specific location, without the rest of the system being negatively affected. ■■ Simple, well-defined interfaces and clear dependencies between differ- ent parts are provided so that an engineer can develop a specific part without having a complete understanding of all the details in the over- all system. ■■ Reuse is supported by both incorporating reusable parts into the design and allowing the design of generic parts that can be used in other systems. An architecture that comprises all these qualities is not easy to design, and sometimes compromises have to be made. But defining a good base architec- ture is one of the most important steps in the development of a successful sys- tem. If it is not done conscientiously, the architecture comes to be defined from the bottom up by the code, resulting in a system that is difficult to change, extend, maintain, and understand. Representing Architecture 253 Logical Architecture The logical architecture contains the application logic, but not the physical dis- tribution of that logic into different environments across different computers. The logical architecture gives a clear understanding of the construction of the system to make it easier to administrate and coordinate the work (to use the human developer resources as efficiently as possible). Not all parts of the log- ical architecture have to be developed within the project; class libraries, binary components, and patterns can often be bought. The logical architecture answers questions such as: ■■ What is the overall structure of the system? ■■ What functionality does the system deliver? ■■ What are the key classes, and how are those classes related to one other? ■■ How do these classes and their objects collaborate to deliver the functionality? ■■ How are common mechanisms applied consistently across the design? ■■ What would be a suitable plan for a number of developers to follow to develop this system? Remember that the logical architecture is not the complete logical design; the architecture as described in these diagrams provides focus on the answers to the questions posed in the preceding bulleted list. The architecture intro- duces organization, constraints, and a set of common tools to the design. While a complete design might be described as an “as-is” model describing a system, the architecture always has a “to-be” tone. The architecture doesn’t so much say, “Here it is,” as it says, “This is how you do it.” In UML, the diagrams used to describe the logical architecture are class, state, activity, and sequence. These diagrams have all been described in previ- ous chapters. Logical Architecture Structure Class diagrams describing architecture can focus on the structure of the over- all system by showing packages, components, and their dependencies and interfaces. A common architecture is the three-layered structure where the system is divided into a presentation layer, an application layer, and a domain layer. A diagram showing such a logical architecture is shown in Figure 7.1. From the packages, other diagramsthat describe the classes in each package and their internal collaboration can be reached. 254 Chapter 7 [...]... proxy controls access to 26 1 26 2 Chapter 7 this “real” object Thus, it solves the problem when an object (the real object) cannot always be instantiated directly due to performance, location, or access restrictions It is a rather simple pattern, but it suits the purposes of describing and demonstrating patterns in UML Figure 7.7 shows a class diagram for the Proxy pattern in UML The representation of... expressed UML 2 uses the standard collaboration icon for these modeling elements The composite structure diagram is a new addition in UML 2 and is used to show the runtime architecture for a particular classifier The nodes on this diagram, parts, are also new UML 2 adds fidelity to how deployment issues are described with the addition of the deployment specification Execution environments are also new in UML. .. participate in several patterns If the collaboration is expanded, the participants are shown “playing” their roles in the pattern, as shown in Figure 7.13 26 5 Chapter 7 Statistics Interface Sales t ec bj pr ox y su lsu bj ec t Proxy Sale Statistics re a 26 6 Figure 7. 12 The Proxy pattern used in a class diagram, where the Statistics Interface class has the participating role of subject, the Sales class has the... different nodes A distributed object system such as J2EE or NET enables the creation of such systems Relevant Changes in UML 2 Earlier versions of UML called out a special modeling element called a subsystem that was both a classifier and a package Furthermore, these earlier versions used components only to structure the model in the physical architecture UML 2 consistently uses components across all parts... for a special subsystem modeling element In UML 2, a component is notated by a classifier symbol that no longer has two protruding rectangles Instead, a keyword notation is used Optionally, a component icon that is similar to the UML 1.4 icon can still be used in the upper-right corner of the component symbol 27 7 27 8 Chapter 7 Earlier versions of UML had a special icon for parameterized... refersTo.Request (); } } Modeling Patterns in UML A pattern is documented as a collaboration in UML A collaboration describes both a context and an interaction The context is a description of the objects involved in the collaboration, how they are related to each other, and of which classes they are instances The interaction shows the communication that the 26 3 26 4 Chapter 7 objects perform in the collaboration... corner a component icon can be displayed, a classifier rectangle with two smaller rectangles protruding from its left side Figure 7 .2 shows a simple component providing one interface and requiring another 25 5 25 6 Chapter 7 «component» TitleImpl Title java.sql.Connection Figure 7 .2 External view of a component The internal (or white box) view shows the internal classifiers, how they are connected, and how... other projects The patterns are naturally described as collaborations in UML DB Connection su bs DB Query ys tem cla ss DBSystem subsystem class em Façade façade ss cla yst DB Statement Quote Graph Window s ub s StockQuote Server observer Observer subject GetCurrentPrice() GetHistoricalPrices() Figure 7.14 Patterns as generators 26 7 26 8 Chapter 7 Here are some suggestions for using design patterns: ■ ■... «TC P/IP P» P/I » Application Server: Silicon Graphics O2 C «T ClientB: Compaq Pro PC Figure 7.19 Communication associations between nodes «DecNet» Database Server: VAX 27 5 27 6 Chapter 7 :AppServer «artifact» ShoppingApp.ear «artifact» «artifact» ShoppingCart.jar Order.jar «deployment spec» «deployment spec» application.xml ejb-jar.xml Figure 7 .20 Artifacts deployed within nodes Allocating Artifacts... understanding of the basic properties of good design, which you can then emulate in your own designs Car leftFront : Tire rightFront : Tire leftBack : Tire rightBack : Tire Figure 7 .6 Parts and connectors inside a car 25 9 26 0 Chapter 7 Design patterns in the software community were inspired by the work of the architect Christopher Alexander Alexander has defined a “pattern language” to describe successful . really needs such support. Relevant Changes in UML 2 This chapter reflects more change from the first edition than any of the other chapters so far. UML 2 now handles a number of concepts related. The next chapter looks more closely at how you can use UML to model the logical and physical architecture of your system. 25 0 Chapter 6 25 1 A system architecture is a blueprint of the parts that. system. The local client is unaware of this and sees only the Proxy. 26 2 Chapter 7 Figure 7.7 The Proxy design pattern described as a UML class diagram. The Proxy pattern is varied in even more ways:

Ngày đăng: 09/08/2014, 16:20

Tài liệu cùng người dùng

Tài liệu liên quan