Download - Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo
![Page 1: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo](https://reader034.vdocument.in/reader034/viewer/2022052514/58a31c1b1a28ab1d068b6697/html5/thumbnails/1.jpg)
Refactoring the BlackBerry’s GaugeField component
Mohammad Talha Khalid
All respective BlackBerry images and logos are the property of BlackBerry (Research In Motion)
![Page 2: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo](https://reader034.vdocument.in/reader034/viewer/2022052514/58a31c1b1a28ab1d068b6697/html5/thumbnails/2.jpg)
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).
![Page 3: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo](https://reader034.vdocument.in/reader034/viewer/2022052514/58a31c1b1a28ab1d068b6697/html5/thumbnails/3.jpg)
GaugeField component
• UI Components team
– Makes UI Components for the BlackBerry
![Page 4: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo](https://reader034.vdocument.in/reader034/viewer/2022052514/58a31c1b1a28ab1d068b6697/html5/thumbnails/4.jpg)
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
![Page 5: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo](https://reader034.vdocument.in/reader034/viewer/2022052514/58a31c1b1a28ab1d068b6697/html5/thumbnails/5.jpg)
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
![Page 6: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo](https://reader034.vdocument.in/reader034/viewer/2022052514/58a31c1b1a28ab1d068b6697/html5/thumbnails/6.jpg)
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
![Page 7: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo](https://reader034.vdocument.in/reader034/viewer/2022052514/58a31c1b1a28ab1d068b6697/html5/thumbnails/7.jpg)
#1: Adding Classes
Original GaugeField class
![Page 8: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo](https://reader034.vdocument.in/reader034/viewer/2022052514/58a31c1b1a28ab1d068b6697/html5/thumbnails/8.jpg)
#1: Adding Classes
• Adding 2 aggregate classes
– GaugeField “has a” GaugeFieldView
![Page 9: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo](https://reader034.vdocument.in/reader034/viewer/2022052514/58a31c1b1a28ab1d068b6697/html5/thumbnails/9.jpg)
#2: Method Extraction
1. Select code
2. Place it in a new (private) method
3. Call the new method
private void clone(){
}
![Page 10: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo](https://reader034.vdocument.in/reader034/viewer/2022052514/58a31c1b1a28ab1d068b6697/html5/thumbnails/10.jpg)
#2: Method Extraction
GaugeField(){
//constructor…
}
TrackBall_Input (){
//handle trackball events…..
}
Paint_ProgressBar(){
//paint the progress bar…
}
Controller
View
![Page 11: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo](https://reader034.vdocument.in/reader034/viewer/2022052514/58a31c1b1a28ab1d068b6697/html5/thumbnails/11.jpg)
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…
}
![Page 12: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo](https://reader034.vdocument.in/reader034/viewer/2022052514/58a31c1b1a28ab1d068b6697/html5/thumbnails/12.jpg)
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
![Page 13: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo](https://reader034.vdocument.in/reader034/viewer/2022052514/58a31c1b1a28ab1d068b6697/html5/thumbnails/13.jpg)
GaugeField(){
GaugeFieldController _controller;
GaugeFieldView _view;
}
TrackBallInput (){
_controller.TrackBallInput()
}
GaugeFieldController
TrackBallInput(){
//handle trackball events…..
}
Method Extraction
Redirecting to the Controller
2
![Page 14: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo](https://reader034.vdocument.in/reader034/viewer/2022052514/58a31c1b1a28ab1d068b6697/html5/thumbnails/14.jpg)
A note about re-directing
• Cannot destroy current methods
– Developers rely on the API
• But old methods can redirect to the new methods
![Page 15: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo](https://reader034.vdocument.in/reader034/viewer/2022052514/58a31c1b1a28ab1d068b6697/html5/thumbnails/15.jpg)
Just re-directing?
• Many methods were self-contained
– Extraction
– Re-direction
• There was code that was not self-contained
![Page 16: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo](https://reader034.vdocument.in/reader034/viewer/2022052514/58a31c1b1a28ab1d068b6697/html5/thumbnails/16.jpg)
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
![Page 17: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo](https://reader034.vdocument.in/reader034/viewer/2022052514/58a31c1b1a28ab1d068b6697/html5/thumbnails/17.jpg)
Beneficial for the View
Progress Bar View Pyramid View
![Page 18: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo](https://reader034.vdocument.in/reader034/viewer/2022052514/58a31c1b1a28ab1d068b6697/html5/thumbnails/18.jpg)
Beneficial for the Controller
Trackball Trackpad Touch-screen
![Page 19: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo](https://reader034.vdocument.in/reader034/viewer/2022052514/58a31c1b1a28ab1d068b6697/html5/thumbnails/19.jpg)
Beneficial for the Controller
GaugeFieldController
TrackBall_Input(){
//handle trackball events…..
}
TouchEvents(){
//handle touchscreen events…
}
Trackpad(){
//handle trackpad…
}
![Page 20: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo](https://reader034.vdocument.in/reader034/viewer/2022052514/58a31c1b1a28ab1d068b6697/html5/thumbnails/20.jpg)
Beneficial for BlackBerry?
![Page 21: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo](https://reader034.vdocument.in/reader034/viewer/2022052514/58a31c1b1a28ab1d068b6697/html5/thumbnails/21.jpg)
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
![Page 22: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo](https://reader034.vdocument.in/reader034/viewer/2022052514/58a31c1b1a28ab1d068b6697/html5/thumbnails/22.jpg)
The End
All respective BlackBerry images and logos are the property of BlackBerry (Research In Motion)
![Page 23: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo](https://reader034.vdocument.in/reader034/viewer/2022052514/58a31c1b1a28ab1d068b6697/html5/thumbnails/23.jpg)
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