The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Extending the PrintConverter

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
Extending the PrintConverter Posted: Apr 15, 2007 11:36 AM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Extending the PrintConverter
Feed Title: David Buck - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/buck-rss.xml
Feed Description: Smalltalk can do that
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From David Buck - Blog

Advertisement

There's a discussion on the VisualWorks NC mailing list talking about extending the PrintConverter. The only way to make the PrintConverter handle new formats is to either override the existing methods in the PrintConverter or to subclass the PrintConverter. Subclassing the PrintConverter could end up with a plethora of subclasses classes that can all handle a subset of the formats. Overriding the existing methods is a nightmare if you want to add several new formats from different packages.

This is a good place to use a Pragma. First, define a new class method for PrintConverter to allow it to support Pragmas.

formatPragma
	<pragmas: #class>
	^#(#format:send:) 
 

Now, in the PrintConverter class>> for:withFormatString: method, add the following before the last line:

   (Pragma allNamed: #format:send: in: self class) do: [:pragma |
      pragma withArgumentsDo: [:formatString :selector |
         aSymbol == formatString 
            ifTrue: [^self new perform: selector with: aString]]]. 
 

Now, you can extend the PrintConverter to your heart's content. Any time you want to add a new converter, extend PrintConverter and add a class method like this:

sampleExtendedFormat
    <format: #sample send: #initForSample:> 
 

Now, define initForSample: as an instance method in the class extension of PrintConverter and get it to do the formatting you want.

Read: Extending the PrintConverter

Topic: Acceptance and Regression Testing With Selenium: Part II - Selenium Specifics Previous Topic   Next Topic Topic: Screencast - software complexity on agile projects

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use