Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
That Fresh Mobile Smell
Search
Fred Medlin
February 20, 2014
Programming
1
61
That Fresh Mobile Smell
Android Presenter First talk at TriDroid West.
Fred Medlin
February 20, 2014
Tweet
Share
Other Decks in Programming
See All in Programming
プロポーザル駆動学習 / Proposal-Driven Learning
mackey0225
1
100
JSONataを使ってみよう Step Functionsが楽しくなる実践テクニック #devio2025
dafujii
0
230
testingを眺める
matumoto
1
130
250830 IaCの選定~AWS SAMのLambdaをECSに乗り換えたときの備忘録~
east_takumi
0
360
速いWebフレームワークを作る
yusukebe
3
1.5k
OSS開発者という働き方
andpad
5
1.6k
Ruby×iOSアプリ開発 ~共に歩んだエコシステムの物語~
temoki
0
120
KessokuでDIでもgoroutineを活用する / Go Connect #6
mazrean
0
130
ECS初心者の仲間 – TUIツール「e1s」の紹介
keidarcy
0
150
DockerからECSへ 〜 AWSの海に出る前に知っておきたいこと 〜
ota1022
5
1.9k
実用的なGOCACHEPROG実装をするために / golang.tokyo #40
mazrean
1
130
【第4回】関東Kaggler会「Kaggleは執筆に役立つ」
mipypf
0
1k
Featured
See All Featured
A better future with KSS
kneath
239
17k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
234
17k
4 Signs Your Business is Dying
shpigford
184
22k
What's in a price? How to price your products and services
michaelherold
246
12k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
51
5.6k
jQuery: Nuts, Bolts and Bling
dougneiner
64
7.9k
Designing for humans not robots
tammielis
253
25k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
358
30k
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
185
54k
Code Review Best Practice
trishagee
70
19k
Large-scale JavaScript Application Architecture
addyosmani
512
110k
Reflections from 52 weeks, 52 projects
jeffersonlam
351
21k
Transcript
That Fresh Mobile Smell ! TriDroidWest 2.20.2014 Fred Medlin
None
None
None
NOT BUGS SYMPTOM OF A DEEPER PROBLEM WEAKNESS THAT SLOWS
DOWN DEVELOPMENT CODE SMELLS
976 LINES KNOWS TOO MUCH DOES TOO MUCH LARGE CLASS
=> GOD OBJECT
BUSINESS DATA AND LOGIC MODEL USER STORY BEHAVIOR USER INTERACTIONS
PRESENTER VIEW PRESENTER FIRST
BUSINESS DATA AND LOGIC MODEL USER STORY BEHAVIOR USER INTERACTIONS
PRESENTER VIEW PRESENTER FIRST
BUSINESS DATA AND LOGIC MODEL USER STORY BEHAVIOR USER INTERACTIONS
PRESENTER VIEW PRESENTER FIRST
HOW IT’S DONE 1.Start with a user story 2.Stub a
presenter 3.Write interface methods for model and view 4.Add presenter tests to confirm the methods were called
1. USER STORY Using my current latitude and longitude, find
and display the nearest geo-tagged wikipedia entry.
2. STUB PRESENTER public class GeoWikiPresenter {! private GeoWikiModel model;!
private GeoWikiView view;! ! public GeoWikiPresenter(GeoWikiModel model, GeoWikiView view) {! this.model = model;! this.view = view;! }! }!
3. MODEL/VIEW INTERFACE METHODS public interface GeoWIkiModel {! !void findLocation();!
!void queryArticles(float latitude, float longitude);! }! ! public interface GeoWikiView {! !void showProgress();! !void hideProgress();! !void displayPage(String url);! }!
4. PRESENTER TESTS public class GeoWikiPresenterTest {! !@Mock GeoWikiModel model;!
!@Mock GeoWikiView view;! !GeoWikiPresenter presenter;! ! !@Before! !public void setup() {! !!Mockito.initAnnotations(this);! !!presenter = new GeoWikiPresenter(model, view);! !}! }!
4. PRESENTER TESTS (2) @Test! ! public void searchesForLocation() {!
! ! verify(model).findLocation();! ! ! verify(view).showProgress();! ! }! ! ! @Test! ! public void queryWikiLocation() {! ! ! presenter.onLocationFound(new FoundLocationEvent(lat, lon));! ! ! verify(model).queryArticles(lat, lon);! ! }!
4. PRESENTER TESTS (3) public class GeoWikiPresenter {! private GeoWikiModel
model;! private GeoWikiView view;! ! public GeoWikiPresenter(GeoWikiModel model, GeoWikiView view) {! this.model = model;! this.view = view;! model.findLocation();! view.showProgress();! ! @Subscribe! public void onLocationFound(FoundLocationEvent event) {! ! model.queryArticles(event.getLatitude(), event.getLongitude());! }! ! @Subscribe! public void onArticleFound(FoundArticleEvent event) {! ! view.hideProgress();! ! view.displayPage(event.getUrl());! }! }! }!
None
3. MODEL/VIEW INTERFACE METHODS public interface GeoWIkiModel {! !void findLocation();!
!void queryArticles(float latitude, float longitude);! }! ! public interface GeoWikiView {! !void showProgress();! !void hideProgress();! !void displayPage(String url);! }!
FRESH public class MainActivity extends Activity {! ! ! GeoWikiPresenter
presenter;! ! ! @Override! ! public void onCreate(Bundle savedInstanceState) {! ! ! super.onCreate(savedInstanceState);! ! ! setContentView(R.layout.activity_main);! ! ! presenter = new GeoWikiPresenter(new GeoWikiModelImpl(), new GeoWikiViewImpl());! ! }! ! ! @Override! ! public void onPause() {! ! ! super.onPause();! ! ! BusProvider.unregister(presenter);! ! }! ! ! @Override! ! public void onResume() {! ! ! super.onPause();! ! ! BusProvider.register(presenter);! ! }! }!
• Traditional SW mistake • Focuses on invisible things MODEL
FIRST • Seems reasonable, but… • Views attract strong feeling • High rate of changes • Hard to test VIEW FIRST ALTERNATIVES?
None
Fred Medlin
[email protected]
@fmedlin
LINKS Mockito - https://code.google.com/p/mockito/ Otto - http://square.github.io/otto/
All photos via Creative Commons Licenses from flickr.com ! -
Attribution-NonCommercial-NoDerivs 2.0 Generic (CC BY-NC-ND 2.0) - (mbshane) http://www.flickr.com/photos/mbshane/3165456548/ - (reid-bee) http://www.flickr.com/photos/reid-bee/5521024764/ - (captain_chickenpants) http://www.flickr.com/photos/captain_chickenpants/320441513/ - (RosenRakuen) http://www.flickr.com/photos/91134569@N05/8365293556/ ! Attribution-NonCommercial-ShareAlike 2.0 Generic (CC BY-NC-SA 2.0) - (clintjcl) http://www.flickr.com/photos/clintjcl/2708117471/ ! Attribution 2.0 Generic (CC BY 2.0) - (jeffreyww) http://www.flickr.com/photos/jeffreyww/4867984686/ - (quietlyurban.com) http://www.flickr.com/photos/83118222@N06/9689975423/ ! Attribution-NonCommercial 2.0 Generic (CC BY-NC 2.0) - (hatalmas) http://www.flickr.com/photos/hatalmas/6094281702/ PHOTO CREDITS