Identification of Refused Bequest Code Smells E. Ligu, A. Chatzigeorgiou, T. Chaikalis, N. Ygeionomakis Department of Applied Informatics University of Macedonia, Greece ICSM’2013, Early Research Achievements Track, September 24, 2013 o C 0 10 20 30 40 AbstractSuperclass /Interface -O ve rriding -Failures -Som e overriding -N o failures -N o overriding -Som e failures -inv ocation ofsuper -N o overriding -Som e failures -N o invocation ofsuper - N o overriding - N o failures R ef us e d Beq uestInd ic a to r
9
Embed
Identification of Refused Bequest Code Smells E. Ligu, A. Chatzigeorgiou, T. Chaikalis, N. Ygeionomakis Department of Applied Informatics University of.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Identification of Refused Bequest Code Smells
E. Ligu, A. Chatzigeorgiou, T. Chaikalis, N. Ygeionomakis
Department of Applied Informatics
University of Macedonia, Greece
ICSM’2013, Early Research Achievements Track, September 24, 2013
oC
0
10
20
30
40
Abstract Superclass / Interface
- Overriding- Failures
- Some overriding
- No failures
- No overriding- Some failures
- invocation of super
- No overriding- Some failures
- No invocation of super
- No overriding- No failures
Ref
used
Beq
uest
Indi
cato
r
Context
In the world of OO systems, inheritance is not a panaceaMammal
Goal: Identification of Refused Bequest Code Smells
Refused Bequest: “a subclass does not want to support the interface inherited from its parent class” [Fowler]
non-trivial problem to resolve
Appropriate Refactoring: Replace Inheritance with Delegation
Famous quote: “Favor Composition over Inheritance” [GoF]
Key Concept
public interface which is inherited
is the subclass using the inherited interface?
Alpha
+ m1()+ m2()+ m3()
Beta
+ m4()+ m5()
+ m1()+ m2()+ m3()
OK
indication of Refused Bequest
Smell Thermometer
Refused Bequest is highly improbable: -inherited methods have been re-implemented to provide functionality that is specific to the subclass -> goal is to enable polymorphism. -the presence of errors -> inherited functionality is actually employed.
Signs of Refused Bequest : -no superclass method is overridden-no inherited method is invoked on subclass instances-no super class method invocationsNo argument in favor of inheritance
oC
0
10
20
30
40
Abstract Superclass / Interface
- Overriding- Failures
- Some overriding- No failures
- No overriding- Some failures- invocation of super
- No overriding- Some failures- No invocation of super
- No overriding- No failures
Re
fuse
d B
eque
st In
dica
tor
oC
0
10
20
30
40
Abstract Superclass / Interface
- Overriding- Failures
- Some overriding- No failures
- No overriding- Some failures- invocation of super
- No overriding- Some failures- No invocation of super
- No overriding- No failures
Re
fuse
d B
eque
st In
dica
tor
Example
SweetHome 3D v.4.0LOC: 76K, 460 classes, 69 hierarchies, 42 test cases