3. #gdg_dnipro_art
What do “GOF Patterns” mean?
"Each pattern describes a problem which occurs over and over again in our environment,
and then describes the core of the solution to that problem, in such a way that you can use
this solution a million times over, without ever doing it the same way twice"
- Christopher Alexander
6. #gdg_dnipro_art
Principles
1. Class versus Interface Inheritance
2. Program to an interface, not an implementation
3. Favor object composition over class inheritance
4. Aggregation -> having or being part of
5. Acquaintance -> knows of (association, using)
6. Delegation
7. Inheritance versus Parameterized Types (generics, templates)
7. #gdg_dnipro_art
Applications of reuse
1. Toolkits - code reuse -> you write the main body of the application and
call the code you want to reuse
2. Frameworks - design reuse -> you reuse the main body and write the
code it calls
19. #gdg_dnipro_art
In Android
new AlertDialog.Builder(this)
.setTitle("Metaphorical Sandwich Dialog")
.setMessage("Metaphorical message to please use the spicy mustard.")
.setNegativeButton("No thanks", new DialogInterface.OnClickListener() { …
}})
.setPositiveButton("OK", new DialogInterface.OnClickListener() {...}})
.show();
Builder
24. #gdg_dnipro_art
Adapter
Convert the interface of a class
into another interface clients
expect. Adapter lets classes
work together that couldn't
otherwise because of
incompatible interfaces.
25. #gdg_dnipro_art
public class TribbleAdapter extends RecyclerView.Adapter {
private List mTribbles;
public TribbleAdapter(List tribbles) { this.mTribbles = tribbles; }
@Override public TribbleViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
LayoutInflater inflater = LayoutInflater.from(viewGroup.getContext());
View view = inflater.inflate(R.layout.row_tribble, viewGroup, false);
return new TribbleViewHolder(view); }
@Override public void onBindViewHolder(TribbleViewHolder viewHolder, int i) { viewHolder.configure(mTribbles.get(i));}
@Override public int getItemCount() { return mTribbles.size(); }
}
Adapter
29. #gdg_dnipro_art
Facade
Provide a unified interface to a set of interfaces in a subsystem. Facade
defines a higher- level interface that makes the subsystem easier to use
34. #gdg_dnipro_art
public class MySpecificEvent { /* Additional fields if needed */ }
eventBus.register(this);
public void onEvent(MySpecificEvent event) {/* Do something */};
eventBus.post(event);
Command
51. #gdg_dnipro_art
Model-View-Presenter (MVP)
● Model - interface defining the data
● Presenter - retrieves data from
repositories (model), and formats it for
display in the view
● View - passive interface that displays data
(the model) and routes user commands
(events) to the presenter
54. #gdg_dnipro_art
Links and books on GOF
- Joshua Kerievsky - Refactoring To Patterns
- Bruce Eckel - Thinking in Patterns with Java
- Eric Freeman - Head First Design Patterns
- Erich Gamma - Design Patterns: Elements
of Reusable Object-Oriented Software
- https://sourcemaking.com/design_patterns
- https://dzone.com/refcardz/design-patterns
- https://github.com/iluwatar/java-design-patterns
55. #gdg_dnipro_art
Links and books on Android Patterns
- Android Design Patterns https://unitid.nl/androidpatterns/
- Alex Lockwood http://www.androiddesignpatterns.com/
- Android Performance Patterns
https://www.youtube.com/playlist?list=PLWz5rJ2EKKc9CBxr3BVjPTPoDPLdPIFCE
- TutsPlus
https://code.tutsplus.com/articles/introduction-to-android-design-patterns--cms-20808
- Ray Wenderlich
https://www.raywenderlich.com/109843/common-design-patterns-for-android
56. #gdg_dnipro_art
Links and books on UI Patterns
- Material Design Guidelines
https://material.io/guidelines/material-design/introduction.html#
- UI Patterns http://ui-patterns.com/patterns
- UI Pttrns https://pttrns.com/android-patterns
57. “Patterns are everywhere -
from enterprise applications
to games and even devices,
the most important is to see them
Alexey Rybakov, DataArt Technical Evangelist