technical presentation - blackberry - refactoring the gaugefield component - university of waterloo

23
Refactoring the BlackBerry’s GaugeField component Mohammad Talha Khalid All respective BlackBerry images and logos are the property of BlackBerry (Research In Motion)

Upload: talha-khalid

Post on 14-Feb-2017

145 views

Category:

Software


2 download

TRANSCRIPT

Page 1: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo

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

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

GaugeField component

• UI Components team

– Makes UI Components for the BlackBerry

Page 4: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo

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

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

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

#1: Adding Classes

Original GaugeField class

Page 8: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo

#1: Adding Classes

• Adding 2 aggregate classes

– GaugeField “has a” GaugeFieldView

Page 9: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo

#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

#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

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

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

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

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

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

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

Beneficial for the View

Progress Bar View Pyramid View

Page 18: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo

Beneficial for the Controller

Trackball Trackpad Touch-screen

Page 19: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo

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

Beneficial for BlackBerry?

Page 21: Technical Presentation - BlackBerry - Refactoring the Gaugefield Component - University of Waterloo

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

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

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