Presentation for Automated Software Engineering - ASE 2019 technical track paper https://2019.ase-conferences.org/details/ase-2019-papers/14/Empirical-Study-of-Programming-to-an-Interface
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Empirical study of programming to an interface
1. EMPIRICAL STUDY OF PROGRAMMING TOEMPIRICAL STUDY OF PROGRAMMING TO
AN INTERFACEAN INTERFACE
B. Verhaeghe1, Christopher Fuhrman2,
L. Guerrouj2, N. Anquetil3 and S. Ducasse4
1Berger-Levrault, France
2École de technologie supérieure, Montreal, Canada
3University of Lille, CRIStAL
4RMoD - Inria Nord Europe
1
Empirical study of programming to an interface
2. MOTIVATIONMOTIVATION
Heuristic from Design Patterns book (GoF 1994).
Clients are less fragile if implementations change.
We have been teaching this to students for decades,
but is there any empirical evidence to support it?
“Program to an interface, not an
implementation.”
2
Empirical study of programming to an interface
4. WHAT IT LOOKS LIKEWHAT IT LOOKS LIKE
Beginner design in Java
Client
«interface»
List
ArrayList TreeList
Coupling to
implementation
ArrayList myList = new ArrayList();
4 . 1
Empirical study of programming to an interface
5. WHAT IT LOOKS LIKEWHAT IT LOOKS LIKE
Improved design…
Client
«interface»
List
ArrayList TreeList
Coupling to
interface
«creates»
Coupling to
implementation
List myList = new ArrayList();
4 . 2
Empirical study of programming to an interface
6. WHAT IT LOOKS LIKEWHAT IT LOOKS LIKE
Factory design decouples client from implementation
Client
«interface»
List
ArrayList
TreeList
ListFactory
Coupling
to interface
creates
creates
uses
List myList = ListFactory.create("...");
4 . 3
Empirical study of programming to an interface
7. CONSEQUENCES OF PTICONSEQUENCES OF PTI
Protect clients changing implementation(s)
Favor extensions to implementations
Simplify the API, overcome single-inheritance
limitation
Speculative Generality (code smell)
Additional level of hierarchy
Factories decouple clients from implementations
Changed interface breaks clients and
implementations
5
Empirical study of programming to an interface
8. EMPIRICAL STUDY OF THE CONSEQUENCESEMPIRICAL STUDY OF THE CONSEQUENCES
Human studies: qualities such as
understandability, ease of extensibility, etc.
Observational studies: Code repositories to see if
client code is protected (change propagation), fault
location, etc.
6
Empirical study of programming to an interface
9. OBSERVATIONAL STUDY: PROTECTED VARIATIONOBSERVATIONAL STUDY: PROTECTED VARIATION
Cochange in Java projects (GitHub)
Static analysis identi es cochange pairs (client,
implementation)
Unprotected pairs (direct coupling)
Protected pairs (no coupling)
Client A Client B
«interface»
ISomething
Implementation
7 . 1
Empirical study of programming to an interface
10. RESEARCH QUESTIONRESEARCH QUESTION
Do unprotected pairs cochange more often than
protected pairs?
Client A Client B
«interface»
ISomething
Implementation
7 . 2
Empirical study of programming to an interface
11. COCHANGE HISTORYCOCHANGE HISTORY
H is the history of commits.
Cochanged Protected Dependencies ratio
CPD(%) =
|H∩P|
|P|
Cochanged Unprotected Dependencies ratio
CUD(%) =
|H∩U|
|U|
.
7 . 3
Empirical study of programming to an interface
12. RESULTSRESULTS
126 (popular) Java projects on GitHub
Ratios of CPD and CUD
p < 0.001 and effect size (Cliff’s) d = 0.32 (small)
7 . 4
Empirical study of programming to an interface
13. FUTURE WORKFUTURE WORK
Observational studies with more context
Classify projects (abstractness)
Microarchitectures (e.g., factories)
Natural experiments for quality aspects
8
Empirical study of programming to an interface