SlideShare a Scribd company logo
1 of 42
Download to read offline
Requirements
MVP
View Controller
Model
Android framework
Activity
Fragment
…
How can I test easy ?
MVC(basic)
Manager
MVP
Manager
(Android component)
View Model
(business logic)
(POJO) (POJO)
Presenter
(middle man between view
and model)
Easy to test
MainActivity BeerProductItem
ServiceManager
MVP
MainActivityPresenter
MVP
PresenterInterface
MainActivity BeerProductItem
ServiceManager
MainActivityPresenter
ViewInterface
Base class
BaseMvpInterface.Presenter
BaseMvpActivity BaseMvpPresenter
BaseMvpInterface.View
Presenter getPresenter( );
V getView( );
void attachView( mvpView );
void detachView( );
void onViewCreate( );
void onViewDestroy( );
void onViewStart( );
void onViewStop( );
One Single responsibility
Presenter createPresenter( );
Int getLayoutView( );
void bindView( mvpView );
void setupInstance( );
void setupView( );
void initialize( );
void restoreView( savedInstanceState );
void onCreate( … );
void onRestoreInstanceState( … );
BaseMvpActivity
BaseMvpInterface.View
One Single responsibility
Presenter createPresenter( );
Void onRestoreInstanceState( … );
void onCreate( … );
void onCreateView( … );
void onViewCreated( … );
Int getLayoutView( );
void bindView( mvpView );
void setupInstance( );
void setupView( );
void initialize( );
void restoreView( savedInstanceState );
BaseMvpFragment
BaseMvpInterface.View
Template
BaseMvpInterface.Presenter
BaseMvpActivity BaseMvpPresenter
BaseMvpInterface.View
CustomActivity
<extend>
CustomPresenter
<extend>
CustomInterface.View
<extend>
CustomInterface.Presenter
<extend>
Adapter
BaseMvpInterfaceAdapter.Presenter
BaseMvpAdapter BaseMvpAdapterPresenter
BaseMvpAdapterInterface.View
Presenter getPresenter();
void notifyDataSetChanged();
void notifyItemInserted( int index );
void notifyItemRemoved( int index );
BaseMvpInterfaceAdapter.Presenter
BaseMvpAdapter BaseMvpAdapterPresenter
BaseMvpAdapterInterface.View
void setAdapter( A adapter );
A getAdapter();
int getItemViewType( int pos );
int getItemCount();
boolean hasItems();
List<BaseItem> getItems();
BaseItem getItem( int pos );
void setItems( List<BaseItem> items,
boolean isNextAvailable );
void addItem( BaseItem item );
void removeItem( int index );
void removeAllItems();
BaseMvpAdapterPresenter
@Override
public void addItem( BaseItem item ){
getPrivateItems( ).add( item );
getAdapter( ).notifyItemInserted( getItemCount() - 1 );
}
Example
public abstract class BaseViewHolder extends RecyclerView.ViewHolder{
public BaseViewHolder( ViewGroup parent, int layout ){
super( LayoutInflater
.from( parent.getContext() )
.inflate( layout, parent, false ) );
bindView( itemView );
}
public abstract void bindView( View view );
public Context getContext(){
return itemView.getContext();
}
}
BaseViewHolder
Example
public BeerProductHolder( ViewGroup viewGroup ){
super( viewGroup, R.layout.holder_beer_product );
}
@Override
public void bindView( View view ){
…
}
BeerProductHolder
public class BaseItem {
protected int type;
public BaseItem( int type ){
this.type = type;
}
public int getType(){
return type;
}
}
BaseItem
@Override
public int getItemCount(){
return getPresenter().getItemCount();
}
@Override
public int getItemViewType( int position ){
return getPresenter().getItemViewType( position );
}
@Override
public BaseViewHolder onCreateViewHolder( ViewGroup viewGroup, int viewType ){
switch( viewType ){
case TYPE_BEER_PRODUCT:
return new BeerProductHolder( viewGroup );
}
return null;
}
BeerAdapter
BaseItem
BeerProductItem
<extend>
Example
TYPE_BEER_PRODUCT
Load more
public interface OnLoadMoreListener{
void onLoadMore();
}
@Override
public VH onCreateViewHolder( ViewGroup parent, int viewType ){
if( viewType == BaseItemType.TYPE_PROGRESS ){
return (VH) new ProgressHolder( parent );
}
throw new RuntimeException( "View type not found: " + viewType );
}
@Override
public void onBindViewHolder( VH holder, int position ){
if( getItemViewType( position ) == BaseItemType.TYPE_PROGRESS ){
if( loadMoreListener != null ){
loadMoreListener.onLoadMore();
}
}
}
Load more
@Override
public void onBindViewHolder(
BaseViewHolder viewHolder, final int position ){
super.onBindViewHolder( viewHolder, position );
…
}
@Override
public BaseViewHolder onCreateViewHolder(
ViewGroup viewGroup, int viewType ){
…
return super.onCreateViewHolder( viewGroup, viewType );
}
Example
Template
BaseMvpAdapterInterface.Presenter
BaseMvpAdapter BaseMvpAdapterPresenter
BaseMvpAdapterInterface.View
CustomAdapter
<extend>
CustomAdapterPresenter
<extend>
CustomAdapterInterface.View
<extend>
CustomAdapterInterface.Presenter
<extend>
Converter
Normally
Raw
DataNetwork
If you want to custom?
Adapter
Converter
Network Adapter
Raw
Data Converter Adapter
Data
Response Body Adapter item
Easy to maintain
String id;
String name;
int price;
String id;
String name;
int price;
int amount = 1;
boolean isAdded = false;
Converter
Network Adapter
Raw
Data Converter Adapter
Data
BeerResult BeerItem
Easy to maintain
RxBus
MainActivity BeerFragment
ClearAddedButtonStateEvent
ClearAddedButtonStateAllEvent
AddBeerToCartEvent
RemoveBeerFromCartEvent
Test
Phase 1 Phase 2 Phase 3
Test must
done
Test must
done
MVP MVP
PresenterInterface
MainActivity BeerProductItem
ServiceManager
MainActivityPresenter
ViewInterface
Unit test
Activity/Fragment
PresenterInterface
MainActivity BeerProductItem
ServiceManager
MainActivityPresenter
CUT
MOCK
Unit test
MOCK
MOCK
Activity/Fragment
ViewInterface
PresenterInterface
BeerAdapter BeerAdapterPresenter
AdapterInterface
Unit test
Adapter
PresenterInterface
BeerAdapter
Unit test
Adapter
MOCK
CUT
AdapterInterface
BeerAdapterPresenter
PresenterInterface
MainActivity BeerProductItem
ServiceManager
MainActivityPresenter
CUT
ViewInterface
MOCK
Integration test
MOCK
MOCK
Activity/Fragment
PresenterInterface
MainActivity BeerProductItem
ServiceManager
MainActivityPresenter
CUT
ViewInterface
MOCK
Integration test
MOCK
CUT
Activity/Fragment
NongBeer MVP Demo application

More Related Content

What's hot

Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJS
Wei Ru
 
AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developers
Kai Koenig
 
Guice tutorial
Guice tutorialGuice tutorial
Guice tutorial
Anh Quân
 

What's hot (20)

Practical AngularJS
Practical AngularJSPractical AngularJS
Practical AngularJS
 
The AngularJS way
The AngularJS wayThe AngularJS way
The AngularJS way
 
Upgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.xUpgrading from Angular 1.x to Angular 2.x
Upgrading from Angular 1.x to Angular 2.x
 
Solid angular
Solid angularSolid angular
Solid angular
 
AngularJS in 60ish Minutes
AngularJS in 60ish MinutesAngularJS in 60ish Minutes
AngularJS in 60ish Minutes
 
Angular 2.0 forms
Angular 2.0 formsAngular 2.0 forms
Angular 2.0 forms
 
[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법
 
[2019] 스몰 스텝: Android 렛츠기릿!
[2019] 스몰 스텝: Android 렛츠기릿![2019] 스몰 스텝: Android 렛츠기릿!
[2019] 스몰 스텝: Android 렛츠기릿!
 
AngularJS Internal
AngularJS InternalAngularJS Internal
AngularJS Internal
 
[2019] 벅스 5.0 (feat. Kotlin, Jetpack)
[2019] 벅스 5.0 (feat. Kotlin, Jetpack)[2019] 벅스 5.0 (feat. Kotlin, Jetpack)
[2019] 벅스 5.0 (feat. Kotlin, Jetpack)
 
AngularJs Crash Course
AngularJs Crash CourseAngularJs Crash Course
AngularJs Crash Course
 
Databinding and Performance-Tuning in Angular 2
Databinding and Performance-Tuning in Angular 2Databinding and Performance-Tuning in Angular 2
Databinding and Performance-Tuning in Angular 2
 
Angular 2.0 Dependency injection
Angular 2.0 Dependency injectionAngular 2.0 Dependency injection
Angular 2.0 Dependency injection
 
AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developers
 
Sharper Better Faster Dagger ‡ - Droidcon SF
Sharper Better Faster Dagger ‡ - Droidcon SFSharper Better Faster Dagger ‡ - Droidcon SF
Sharper Better Faster Dagger ‡ - Droidcon SF
 
Guice tutorial
Guice tutorialGuice tutorial
Guice tutorial
 
AngularJS Basic Training
AngularJS Basic TrainingAngularJS Basic Training
AngularJS Basic Training
 
I os 11
I os 11I os 11
I os 11
 
Modules and injector
Modules and injectorModules and injector
Modules and injector
 
Performance Optimization In Angular 2
Performance Optimization In Angular 2Performance Optimization In Angular 2
Performance Optimization In Angular 2
 

Similar to NongBeer MVP Demo application

Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development
Mahmoud Hamed Mahmoud
 
Apple Templates Considered Harmful
Apple Templates Considered HarmfulApple Templates Considered Harmful
Apple Templates Considered Harmful
Brian Gesiak
 

Similar to NongBeer MVP Demo application (20)

[22]Efficient and Testable MVVM pattern
[22]Efficient and Testable MVVM pattern[22]Efficient and Testable MVVM pattern
[22]Efficient and Testable MVVM pattern
 
Android Design Patterns
Android Design PatternsAndroid Design Patterns
Android Design Patterns
 
Fun with RecyclerView
Fun with RecyclerViewFun with RecyclerView
Fun with RecyclerView
 
Dicoding Developer Coaching #30: Android | Mengenal Macam-Macam Software Desi...
Dicoding Developer Coaching #30: Android | Mengenal Macam-Macam Software Desi...Dicoding Developer Coaching #30: Android | Mengenal Macam-Macam Software Desi...
Dicoding Developer Coaching #30: Android | Mengenal Macam-Macam Software Desi...
 
Building a Native Camera Access Library - Part II.pdf
Building a Native Camera Access Library - Part II.pdfBuilding a Native Camera Access Library - Part II.pdf
Building a Native Camera Access Library - Part II.pdf
 
ButterKnife
ButterKnifeButterKnife
ButterKnife
 
Practical Protocol-Oriented-Programming
Practical Protocol-Oriented-ProgrammingPractical Protocol-Oriented-Programming
Practical Protocol-Oriented-Programming
 
Practialpop 160510130818
Practialpop 160510130818Practialpop 160510130818
Practialpop 160510130818
 
MCE^3 - Natasha Murashev - Practical Protocol-Oriented Programming in Swift
MCE^3 - Natasha Murashev - Practical Protocol-Oriented Programming in SwiftMCE^3 - Natasha Murashev - Practical Protocol-Oriented Programming in Swift
MCE^3 - Natasha Murashev - Practical Protocol-Oriented Programming in Swift
 
Vaadin DevDay 2017 - DI your UI
Vaadin DevDay 2017 - DI your UIVaadin DevDay 2017 - DI your UI
Vaadin DevDay 2017 - DI your UI
 
Building impressive layout systems with vaadin
Building impressive layout systems with vaadinBuilding impressive layout systems with vaadin
Building impressive layout systems with vaadin
 
Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development Windows Store app using XAML and C#: Enterprise Product Development
Windows Store app using XAML and C#: Enterprise Product Development
 
ASP.NET MVC Internals
ASP.NET MVC InternalsASP.NET MVC Internals
ASP.NET MVC Internals
 
Getting Started with Combine And SwiftUI
Getting Started with Combine And SwiftUIGetting Started with Combine And SwiftUI
Getting Started with Combine And SwiftUI
 
Net conf BG xamarin lecture
Net conf BG xamarin lectureNet conf BG xamarin lecture
Net conf BG xamarin lecture
 
SwiftUI and Combine All the Things
SwiftUI and Combine All the ThingsSwiftUI and Combine All the Things
SwiftUI and Combine All the Things
 
Apple Templates Considered Harmful
Apple Templates Considered HarmfulApple Templates Considered Harmful
Apple Templates Considered Harmful
 
Swift Delhi: Practical POP
Swift Delhi: Practical POPSwift Delhi: Practical POP
Swift Delhi: Practical POP
 
Rcp by example
Rcp by exampleRcp by example
Rcp by example
 
Patterns Are Good For Managers
Patterns Are Good For ManagersPatterns Are Good For Managers
Patterns Are Good For Managers
 

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu SubbuApidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
Apidays Singapore 2024 - Modernizing Securities Finance by Madhu Subbu
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

NongBeer MVP Demo application