The Artima Developer Community
Sponsored Link

Scala Buzz
Using types to help refactor

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
Ricky Clarkson

Posts: 63
Nickname: rclarkson
Registered: Jul, 2006

Ricky Clarkson is a salsa-dancing, DJing programmer in Manchester, England.
Using types to help refactor Posted: Apr 28, 2010 6:57 AM
Reply to this message Reply

This post originated from an RSS feed registered with Scala Buzz by Ricky Clarkson.
Original Post: Using types to help refactor
Feed Title: Ricky's technical blog
Feed URL: http://rickyclarkson.blogspot.com/feeds/posts/default
Feed Description: A blog about programming languages, and Java.
Latest Scala Buzz Posts
Latest Scala Buzz Posts by Ricky Clarkson
Latest Posts From Ricky's technical blog

Advertisement
In some real code, I changed an int that was used to index into an array of ViewerPanels, so that the ViewerPanel was passed around instead of the int. I missed some cases in the first pass, so I had a think about how to make sure I don't do that again.

The cases I missed were PropertyChangeListeners. If you're not familiar with that type, you can use it with a PropertyChangeSupport to listen for changes in values. It has Object in its API, rather than using generics. I don't particularly like the idea of listening for changes, particularly if the listeners then end up interfering with the objects they're listening to, but that's what I have in existing code, so I need to get on with it for now.

The tests didn't pick it up, I found it by coming across a firePropertyChange and wondering what the listening end now looked like. The tests could be better, sure.

Here follows four versions of a simpler code sample. The refactor we want to do in this case is just to go from double to float. Version 2 shows what happens when one forgets to check the PropertyChangeListeners. Version 3 steps back to Version 1 but alters it to use a type-safe version of PropertyChangeListener. Version 4 does the refactor again, but this time the compiler forces the ChangeListener to be altered, because we're no longer based on PropertyChangeListener.

The below code is executable.

Read: Using types to help refactor

Topic: Mini-Parsers to the rescue Previous Topic   Next Topic Topic: Pimping Servlet and Jetty

Sponsored Links



Google
  Web Artima.com   

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