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
Remix on Hono on Cloudflare Workers
yusukebe
1
300
ActiveSupport::Notifications supporting instrumentation of Rails apps with OpenTelemetry
ymtdzzz
1
240
Creating a Free Video Ad Network on the Edge
mizoguchicoji
0
120
Arm移行タイムアタック
qnighy
0
330
型付き API リクエストを実現するいくつかの手法とその選択 / Typed API Request
euxn23
8
2.2k
TypeScript Graph でコードレビューの心理的障壁を乗り越える
ysk8hori
2
1.1k
ヤプリ新卒SREの オンボーディング
masaki12
0
130
AWS Lambdaから始まった Serverlessの「熱」とキャリアパス / It started with AWS Lambda Serverless “fever” and career path
seike460
PRO
1
260
よくできたテンプレート言語として TypeScript + JSX を利用する試み / Using TypeScript + JSX outside of Web Frontend #TSKaigiKansai
izumin5210
6
1.7k
距離関数を極める! / SESSIONS 2024
gam0022
0
280
リアーキテクチャxDDD 1年間の取り組みと進化
hsawaji
1
220
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
190
Featured
See All Featured
Writing Fast Ruby
sferik
627
61k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
27
4.3k
Save Time (by Creating Custom Rails Generators)
garrettdimon
PRO
27
840
The Invisible Side of Design
smashingmag
298
50k
Building a Modern Day E-commerce SEO Strategy
aleyda
38
6.9k
The Pragmatic Product Professional
lauravandoore
31
6.3k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Facilitating Awesome Meetings
lara
50
6.1k
Unsuck your backbone
ammeep
668
57k
Rails Girls Zürich Keynote
gr2m
94
13k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
44
2.2k
The Straight Up "How To Draw Better" Workshop
denniskardys
232
140k
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