technical presentation - blackberry - refactoring the gaugefield component - university of waterloo
TRANSCRIPT
Refactoring the BlackBerry’s GaugeField component
Mohammad Talha Khalid
All respective BlackBerry images and logos are the property of BlackBerry (Research In Motion)
Presentation Background
I originally created this presentation for my SE 464 Software Architecture class, based on my co-op experience at BlackBerry.
I subsequently entered it into the SFF Technical Speaking Competition (2nd Place Award).
GaugeField component
• UI Components team
– Makes UI Components for the BlackBerry
Project Overview
• Refactor the GaugeField component to adhere to the MVC pattern
– Restructure & Rearrange the code
– Splitting up into M, V, C
• SE 464 Relevance
– Refactoring
– MVC Design Pattern
Why refactor the GaugeField?
• Code will be easier to understand
– All the code was in one class... messy
• MVC makes sense for a UI component
– Easier to modify the component
– Add more input controllers
• Support touch-screen devices
– Add more Views
Refactoring Process
Applying behavior-preserving transformations
1) Adding new classes
– Controller & View
2) Method extraction
– Identify all the code relevant to M, V, C
– Extract code
– Put it in the View and Controller classes
1
2
#1: Adding Classes
Original GaugeField class
#1: Adding Classes
• Adding 2 aggregate classes
– GaugeField “has a” GaugeFieldView
#2: Method Extraction
1. Select code
2. Place it in a new (private) method
3. Call the new method
private void clone(){
}
#2: Method Extraction
GaugeField(){
//constructor…
}
TrackBall_Input (){
//handle trackball events…..
}
Paint_ProgressBar(){
//paint the progress bar…
}
Controller
View
GaugeField(){
GaugeFieldController _controller;
GaugeFieldView _view;
}
TrackBall_Input (){
_controller.TrackBall_Input()
}
Paint_ProgressBar(){
_view.Paint_ProgressBar()
}
GaugeFieldController
TrackBall_Input(){
//handle trackball events…..
}
GaugeFieldView
Paint_ProgressBar(){
//paint the progress bar…
}
GaugeField(){
GaugeFieldController _controller;
GaugeFieldView _view;
}
TrackBallInput (){
_controller.TrackBallInput()
}
PaintProgressBar(){
_view.PaintProgressBar()
}
GaugeFieldController
FooTrackBallInput(){
//handle trackball events…..
}
GaugeFieldView
PaintProgressBar(){
//paint the progress bar…
}
Adding Classes GaugeField has a
Controller and View
1
GaugeField(){
GaugeFieldController _controller;
GaugeFieldView _view;
}
TrackBallInput (){
_controller.TrackBallInput()
}
GaugeFieldController
TrackBallInput(){
//handle trackball events…..
}
Method Extraction
Redirecting to the Controller
2
A note about re-directing
• Cannot destroy current methods
– Developers rely on the API
• But old methods can redirect to the new methods
Just re-directing?
• Many methods were self-contained
– Extraction
– Re-direction
• There was code that was not self-contained
Benefits
• Code is neatly organized
– Split up into M, V, C
• Beneficial for the Controller & View
– Easier to add more methods in the future
1
2
Beneficial for the View
Progress Bar View Pyramid View
Beneficial for the Controller
Trackball Trackpad Touch-screen
Beneficial for the Controller
GaugeFieldController
TrackBall_Input(){
//handle trackball events…..
}
TouchEvents(){
//handle touchscreen events…
}
Trackpad(){
//handle trackpad…
}
Beneficial for BlackBerry?
Summary
• Restructured the GaugeField code
• Added Classes
• Method Extraction
– Old methods re-directed to the new methods
– Helped preserve the API
• MVC allows you to enhance the View & Controller with more functionality
1
2
The End
All respective BlackBerry images and logos are the property of BlackBerry (Research In Motion)
Image References
Images in this presentation were extracted from the Internet, and are the property of their respective owners, including BlackBerry.
A non-exhaustive list of miscellaneous image references follows. Caveat: Some of the labels in the domain names are a bit peculiar.
Peculiar URL References:
• http://2.bp.blogspot.com/_xhI2QKKA6cY/ScFMZdFhxMI/AAAAAAAAAWI/YsmJKn7Doz4/s400/image.axd+%281%29.png
• http://www.stopgettingcheated.com/images/easy-button.jpg
• http://www.stop-age.com/userfiles/image/syringe2.jpg
• http://www.code-magazine.com/article.aspx?quickid=0401071&page=2
• http://www.dreamstime.com/doctor-with-syringe-needle-image5290308