|
YOUR FEEDBACK
Did you read today's front page stories & breaking news?
SYS-CON.TV |
TOP THREE LINKS YOU MUST CLICK ON Feature Practical Adoption of Design Patterns
Practical Adoption of Design Patterns
By: Walter Hurst
Aug. 7, 2003 10:54 AM
Often there is a distinction between concepts and how those concepts are applied in the real world. Design patterns are no exception. Design patterns are everywhere. It's hard to read a technology publication or Web site without seeing some reference to design patterns. By now you have probably read (or at least paged through) some of the design pattern books, such as Core J2EE Design Patterns or Design Patterns by the Gang of Four. At this point you are possibly asking some questions about design patterns. How will design patterns help me? Are they a silver bullet? Are there any problems with design patterns? Don't I get design patterns from my integrated development environment (IDE)? All of these are good questions to ask as you go through the process of adopting design patterns. Often there is a distinction between concepts and how those concepts are applied in the real world. Design patterns are no exception. In this article we'll look at the real world adoption of design patterns. This information should help you make the right decisions about successfully adopting design patterns in your project.
Quick Overview The concept of design patterns originated in the construction industry. Architects (the ones that design buildings, not computer systems) realized they needed to share ideas about correct design techniques. These ideas were captured in design patterns that allowed the architect community to benefit from shared experiences and lessons learned. Design patterns made the leap from construction to computer systems in the late '80s. Object-oriented (OO) philosophies were gaining popularity and design patterns were a way to educate the new OO followers on best practices. The book that launched design patterns into the limelight is Design Patterns: Elements of Reusable Object-Oriented Software by Richard Gamma, et al (the authors are commonly referred to as the Gang of Four [GoF]). As design patterns have grown in popularity, the number of flavors they come in has also ballooned in what could be described as the "Ben and Jerry" effect. For those of you not familiar with the popular ice cream brand, Ben and Jerry's is a purveyor of fine ice cream products that come in every imaginable combination of ingredients (including some you would never have ever imagined). So it is with design patterns, which originated with the general OO design patterns from the GoF book but now include design patterns that are specific for development languages, application servers, industry verticals, and so on.
Categorizing Design Patterns For our discussion of the practical adoption of design patterns, we need to divide design patterns into two categories: broad exposure and isolated use. This division is based on the visibility of the design pattern to the designers and developers of the application and the dependency of multiple parts of the application on the design pattern.
Broad exposure design patterns are distinguished by affecting
the designs and development of more than just one team member or more
than one area of the application. Some qualities of this type of
design pattern are: Some examples of this type of design pattern are the Model-View-Controller (MVC) pattern, the Value Object J2EE pattern, and the Data Access Object (DAO) J2EE pattern.
Isolated use refers to design patterns for which the use of the design pattern is a hidden detail. Some qualities of this type of design pattern are: Some examples of this type of design pattern are the Singleton GoF pattern or the Intercepting Filter J2EE pattern. Dividing design patterns into these categories provides a quick approach for understanding the scope of the design pattern. Understanding scope makes it easy to assess the impact of the design pattern. Is it a design pattern that can be used and discarded? Is it a design pattern that once adopted will impact the design of the application? Is it a design pattern that affects multiple parts of my application and possibly other applications? Understanding these impacts up front provides guidance for adopting the design pattern.
Design Pattern Adoption AntiPatterns In this section, we'll look at AntiPatterns that apply to the adoption of design patterns. Understanding these AntiPatterns should help you avoid the pitfalls of design pattern adoption. Like design patterns, the AntiPatterns here may be entirely new to you, in which case they provide some foresight; or they may be situations you are somewhat familiar with, in which case they can add color to your experiences and let you know that you're not alone. If you are interested in reading more AntiPatterns, see the resource list at the end of this article.
AntiPattern Checklist Applies To: Both broad exposure and isolated use design patterns. Context: A developer has been introduced to design patterns and wants to use them on a project. Forces: Two forces are usually the source for this AntiPattern. One is the desire of the developer to improve the project by including best practices from design patterns. The other is that innate curiosity drives the developer to use the project for research on design patterns. Supposed Solution: All known design patterns are used on the project. A checklist is formed from the design pattern book and the motivating goal is to be able to check off all of the design patterns. Resulting Context: The project team and the delivered application suffer from the unnatural introduction of too many design patterns. This results in designs and development that are overly complex. This unnecessary complexity can impact the development effort in terms of the amount of work that has to be done, the ability of the development team to understand what is happening, and the actual performance and functional correctness of the application. Design Rationale: Design patterns are a great source of expert knowledge. If using them is good, then using all of them is mistakenly thought of as better. Real Solution: The description of a design pattern includes the context for which the pattern is targeted. Thought must be given to ensure that the design pattern is a match for the project. Second, design patterns are often incorporated not from someone reading a design pattern book and asking "where can I use this design pattern?" but from someone looking for a solution to a problem they have discovered.
Implementation per Developer/Project AntiPattern Problem: Controlling the implementation of design patterns within a project and across projects. Applies To: Both broad exposure and isolated use design patterns benefit from addressing this situation. However, broad exposure design patterns should definitely have controlled implementations. Context: The development team is incorporating design patterns into the project. The team consists of many experienced developers who understand when to use design patterns. The correct design patterns are being used. If multiple projects are involved, there is no design pattern - implementation sharing between projects. Forces: There are tight deadlines and the team is very efficient individually. Team efficiency might be impacted if they have to reuse implementations. It is assumed that since they are experts, their implementation will be good anyway. In the case of multiple projects, the cross-team communication and code sharing either is not considered or is dismissed as a potential impact on schedules. Supposed Solution: The team can include and implement the design patterns they need as individuals. Resulting Context: Even though the correct design patterns were used, they were implemented in many different ways. There are incompatibilities between the implementations that restrict integration and reuse efforts. More time and effort than necessary will have to be spent maintaining, debugging, and extending the various implementations. Eventually the various implementations will have to be consolidated. Design Rationale: A team of experts should be allowed to work alone. Including design patterns is good enough, there is no reason to share implementations. Real Solution: The development team should coordinate their use of design patterns. Sharing a common implementation of a design pattern can lower costs in the future, but more important, it should result in cross-developer compatibility today. If necessary, this sharing could be limited to design patterns that fall into the broad exposure category we discussed earlier. Reusing implementations is also valuable across projects, especially if they are expected to integrate in the future.
Role of IDEs in Design Pattern Adoption Some IDEs have pull-down menus that allow you to select design patterns to include in your application. While this can expedite the inclusion of a design pattern, it might just result in writing bad code faster. There are a couple of factors to remember in evaluating this feature. One is that design patterns describe problems in the abstract and require some interpretation to arrive at the correct implementation. However, they often include a "sample implementation" and it is this sample class structure that the IDEs insert into your application. This is probably not the implementation that you need and just dropping it into your application will introduce more confusion and require more editing and refactoring than just putting thought into your own original implementation. Another problem with the IDE drag-and-drop design pattern approach is the two AntiPatterns we already discussed. Expediting the implementation of design patterns is more likely to result in rampant inclusion of design patterns and multiple versions of the same design pattern than it is to solve any problems. The challenge with design patterns isn't just in getting a quick implementation, but making sure you are using a correct implementation, and ideally an implementation that already exists in your organization.
BEA WebLogic Workshop 8.1 and Design Patterns WebLogic Workshop Controls are a way to package functionality so that it can be easily included in your application using the Workshop IDE. The packaging includes the visual elements required for the IDE, the runtime behavior, the configuration required, and more. How do Controls impact your inclusion of design patterns? Remember the earlier segregation of design patterns into isolated use and broad exposure? Design patterns that fall into the isolated use category may be candidates to be packaged as Workshop Controls. Packaging the design pattern as a Control would allow other users of the Workshop IDE to share an implementation, avoiding the Implementation per Developer/Project AntiPattern. You may be wondering why the broad exposure category cannot be implemented as Controls. The reason is that the broad exposure design patterns result in the creation of many other classes or in some dependence with other applications. This situation does not lend itself to the plug-and-play aspect of Controls. Adoption of the broad exposure design patterns should be done with much thought and consideration, and once adopted cannot be undone easily. These requirements do not match with the WebLogic Workshop Control goals. WebLogic Workshop also comes with many pre-implemented design patterns, such as Pageflow and the user interface structure. From within Workshop, you can create JSPs and define Pageflows to control the navigation between the pages of your Web application. Under the hood, WebLogic Workshop uses the popular Apache Struts presentation layer framework. This aspect of Workshop (which uses Struts) provides a Model-View-Controller (MVC) design pattern implementation, which means you won't have to create your own MVC implementation. Workshop includes other functionality that will probably replace your own design pattern implementations. While it is nice to get some of these design patterns implemented out-of-the-box, you should validate that you are comfortable with not only the implementation but with any dependency on WebLogic Workshop that the implementation creates.
Three Steps for Successful Design Pattern Adoption
Strong Communication and Education
Mentored Design Pattern Adoption Mentoring adoption is especially critical for the broad exposure category of design patterns. These are the design patterns that have more associated risk because they will create dependencies. These dependencies may be within a class of objects, such as data access objects (DAOs) that only work within the scope of a broader DAO design pattern implementation, or across application boundaries, such as use of the Value Object design pattern to communicate data between applications and application layers. These design patterns are also ones that may have been implemented by somebody else on the project or by a different project, and that implementation should be reused versus creating another unique implementation.
Reuse Implementations, Not Just Design Patterns This reuse is more important (and sometimes essential) for the broad exposure category. These design patterns are the ones that create external dependencies (where integration would benefit from a common implementation) or result in a whole library of custom classes (that would be reusable if there was a common foundation). The isolated use category would benefit from reuse but they might be more difficult to reuse if they were strongly customized to their specific situation. Something you may ask yourself is, "If reuse is better, why don't design patterns come with a reusable implementation?" We touched on this when we talked about how design patterns are provided for the benefit of the largest audience. Achieving this goal of broad applicability would be difficult, if not impossible, if it came with a predetermined implementation. However, once the design patterns are applied to a particular problem domain or technical infrastructure, the resulting implementation may be reusable within that environment.
Design Patterns Through Architecture
Summary Following the steps outlined in this article will put a process in place that can be used to promote the successful adoption of design patterns on your team and within your organization.
Resources BEA WEBLOGIC LATEST STORIES
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS BREAKING NEWS FROM THE WIRES
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||