YOUR FEEDBACK
José D'Andrade wrote: "...it may never be released..." Why? "...if Midori isn’t heir to Windows Mi...
AJAXWorld RIA Conference
$300 Savings Expire August 8
Register Today and SAVE!

SYS-CON.TV
TOP THREE LINKS YOU MUST CLICK ON


The Necessity of OOSE Design Patterns
You Wouldn't Try to Cook Without a Recipe, Right?


Figure 2: A UML example of violating the Expert and Polymorphism patterns

Translating the UML design from Figure 2 would generate a Java structure like the one shown in Figure 3.


Figure 3: A Java example, violating Expert and Polymorphism

One solution: The State pattern

The GoF pattern catalog offers a possible solution for our design challenge. The pattern is called State.

First we verify that the pattern meets our needs and read the intend, application, and consequences sections of the pattern. Because the pattern says that it "Allows an object to alter its behavior when its internal state changes. The object will appear to change its class [GoF]," we go ahead and apply this pattern to our problem.

One of the benefits of applying the State pattern is that it can resolve the if-statement situation difficulty shown in Figure 3 by isolating the various states. The UML state-machine notation helps us depict and investigate the various states. Initially our timesheet was fairly simple and we isolated two states out of our existing structure, Approved and Not Approved.

 


Figure 4: UML state-machine diagram for timesheet (two states)

Instead of asking the object which value is nested in an attribute (in our case is Approved) and make a decision based on that (which violate the principle of polymorphism) we instead tell the object what to do and simply send the message to it and let the Timesheet object deal with the event. What we would like to design is some way to send a message, as shown below, where ts is a Timesheet object.


Figure 5: New responsibility assignment for timesheet (Java)

After we isolate the various states, remove the if-construct from the Timesheet object, and assign the three responsibilities (enter, approve and reject), we then want to apply the State pattern to our solution. Using the RSA pattern explorer we navigate to the State pattern, which shows us the participating classes in the pattern.

 

Figure 6: State pattern and participating classes within the RSA pattern explorer

In order to get an overview of the structure of the State pattern, the pattern explorer provides us the following layout:


 

Figure 7: State pattern structure within the RSA pattern explorer

The cookie-cutter solution for the State pattern needs to be adjusted to accommodate our application's specific needs. After dragging the pattern from the pattern explorer directly into our workspace, we can assign the participating classes from our application-specific class model. The following diagram contains now the Timsheet as a context object, the Java interface ITimesheetState for the State and both concrete states from our timesheet application (Approved and Not Approved).

 
About Jochen Krebs
Jochen (Joe) Krebs (http://www.jochenkrebs.com) is a Senior IT Specialist for the Rational Software Brand within the IBM Software Group. He is responsible for successful enablement of Rational products and services for clients in the financial sector. Prior to joining IBM Rational he worked as an Instructor and Senior Consultant with a focus on project management, requirements management, software engineering processes and object-oriented technologies using Smalltalk and Java. He holds his MSc in Computing for Commerce and Industry at the Open University.

YOUR FEEDBACK
WebSphere Journal News Desk wrote: IBM WebSphere Application Server - WAS for z/OS and DB2. Most WebSphere Application Server (WAS) for z/OS customers use DB2 for z/OS as the backend or data store. DB2 for z/OS is a high-performance DBMS, with a strong reputation for handling high-volume data access transactions. Picking the right WAS for z/OS and DB2 Subsystem connectivity architecture can greatly improve the system's performance, availability, scalability, security, and transactional capability.
WEBSPHERE LATEST STORIES . . .
Mike Neil is general manager for virtualization strategy in the Windows Server Division at Microsoft. Mike is focused on the delivery of the Windows virtualization technology, including Windows Server 2008 Hyper-V, Microsoft Hyper-V Server and Virtual PC 2007. Mike also directs the tec...
Unify announced the expansion of its Composer for Lotus Notes solution through a partnership with CASAHL Technology. Partnering with CASAHL extends the Composer solution to include an assessment of the Lotus Notes infrastructure in order to inventory, categorize and analyze the types o...
Two of the biggest launches in Rich Internet Application history took place in 2007/2008 when Adobe launched AIR 1.0 in February '08 and Microsoft launched Silverlight (September '07). At the 6th International AJAXWorld RIA Conference & Expo in October SYS-CON Events is delighted to be...
Reminding people of how its backing was the making of Linux, IBM, to no one's surprise, has thrown its support behind cloud computing, that delicious nexus of every chi-chi buzzword technology currently in vogue: Web 2.0, rich Internet applications, software-as-a-service, SOA, grid com...
IBM claims to have created new species of custom-built, industry-standard, Linux-based rack server for Web 2.0 and Cloud Computing companies with massive data centers and tens of thousands of servers, like online gaming, social networks, search and Internet firms. A relatively limited ...
A standard from OASIS called Web Services for Remote Portlets (WSRP) is used so portlets can be decoupled from a portal. In part one (JDJ, Volume. 13, issue 3) of this article, we introduced the relevant standards and specifications and then demonstrated WSRP's capabilities by consumin...
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS
SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021

SYS-CON FEATURED WHITEPAPERS

ADS BY GOOGLE
BREAKING WEBSPHERE NEWS
IBM (NYSE: IBM) today announced that Princess Cruises, a subsidiary of Carnival Corporation (NYSE: C...