Click here to load reader

Refactoring for design smells

  • View
    5.267

  • Download
    3

Embed Size (px)

DESCRIPTION

 

Text of Refactoring for design smells

  • 1. S G Ganesh, Girish Suryanarayana, Tushar Sharma Refactoring for Design Smells - With Examples from OpenJDK S G Ganesh Tushar Sharma Girish Suryanarayana
  • 2. S G Ganesh, Girish Suryanarayana, Tushar SharmaSlide 2 Outline 9-May-13 Introduction Abstraction smells Encapsulation smells Modularization smells Hierarchy smells Key takeaways and conclusion
  • 3. S G Ganesh, Girish Suryanarayana, Tushar SharmaSlide 3 Why care about smells? Quality Attributes Reusability Flexibility Understandability Extendibility 9-May-13 Product Quality Design Quality Design Smells Maintainability: Affected by flexibility & extendibility Reliability: Impacted by poor understandability Indicators Rigidity & Fragility Immobility & Opacity Needless complexity Needless repetition
  • 4. S G Ganesh, Girish Suryanarayana, Tushar Sharma What is a smell? Smells have been defined differently We embrace all the following definitions! 9-May-13 We suggest that, like any living creature, system designs are subject to diseases, which are design smells (code smells and anti-patterns). Design smells are conjectured in the literature to impact the quality and life of systems. Hassaine et al. [HKGH10] Smells are certain structures in the code that suggest (sometimes they scream for) the possibility of refactoring. M. Fowler [Fow99] Code and design smells are poor solutions to recurring implementation and design problems. Moha et. al. [MGDM10] Design smells are the odors of rotting software. R C Martin [Mar03]
  • 5. S G Ganesh, Girish Suryanarayana, Tushar Sharma Design smells aka 9-May-13
  • 6. S G Ganesh, Girish Suryanarayana, Tushar Sharma Symptoms of rotting design 9-May-13
  • 7. S G Ganesh, Girish Suryanarayana, Tushar Sharma Why care about design quality? 9-May-13 * http://sqgne.org/presentations/2012-13/Jones-Sep-2012.pdf Design quality is important Our organization develops critical, large, and/or reusable software A good designer is one who knows the design solutions A great designer is one who understands the impact of design defects/smells and knows how to address them Design quality means: flexibility, extensibility, understanda bility, reusability,...
  • 8. S G Ganesh, Girish Suryanarayana, Tushar Sharma Capers Jones on design errors in industrial software 9-May-13 * http://sqgne.org/presentations/2012-13/Jones-Sep-2012.pdf
  • 9. S G Ganesh, Girish Suryanarayana, Tushar SharmaSlide 9 So, what causes design smells? 9-May-13 Design is impacted by changing requirements. Often, a holistic approach is not adopted resulting in different parts of design evolving in isolation Changing requirements Either design principles are not applied or are applied wrongly Misapplication of design principles Refactoring that is done incompletely or inappropriately Lack of proper refactoring Often teams lack competent resources or the budget for supporting the above practices Lack of competent resources
  • 10. S G Ganesh, Girish Suryanarayana, Tushar SharmaSlide 10 Smells as violations of fundamental principles 9-May-13 Why does smell indicate something problematic? Because they indicate violation of fundamental design principles We use Boochs fundamental principles for classification and naming of smells This helps identify cause of the smell and potential refactoring as well
  • 11. S G Ganesh, Girish Suryanarayana, Tushar SharmaSlide 11 Principle-based approach to design smells 9-May-13 This presentation on design smells is based on research work completed over a period of two years The focus of our work is only on structural design smells Published in Journal of Object Technology (Vol. 12, No. 2, 2013) S G Ganesh, Tushar Sharma, Girish Suryanarayana. Towards a Principle-based Classication of Structural Design Smells. In Journal of Object Technology, vol. 12, no. 2, 2013, pages 1:129.doi:10.5381/jot.2013.12.2.a1 URL: http://www.jot.fm/issues/issue_2013_06/article1.pdf (open access) Creational Structural Behavioral Architectural Design Implementation
  • 12. S G Ganesh, Girish Suryanarayana, Tushar SharmaSlide 12 Abstraction smells 9-May-13
  • 13. S G Ganesh, Girish Suryanarayana, Tushar SharmaSlide 13 Encapsulation smells 9-May-13
  • 14. S G Ganesh, Girish Suryanarayana, Tushar SharmaSlide 14 Modularization smells 9-May-13
  • 15. S G Ganesh, Girish Suryanarayana, Tushar SharmaSlide 15 Hierarchy smells 9-May-13
  • 16. S G Ganesh, Girish Suryanarayana, Tushar SharmaSlide 16 A note on examples in this presentation 9-May-13 Only around 50% of the smells are described with examples Cannot cover all of them in detail due to lack of time All examples are from OpenJDK 7.0 (open source) All illustrations are mostly as UML diagrams so no need to know Java (though youll appreciate more if you know Java)
  • 17. S G Ganesh, Girish Suryanarayana, Tushar SharmaSlide 17 How smells are related to technical debt? When, due to constraints, I design quickly and dirty, my project is loaded with technical debt Ward Cunningham, 1992 14 August 2013
  • 18. S G Ganesh, Girish Suryanarayana, Tushar SharmaSlide 18 Outline 9-May-13 Introduction Abstraction smells Encapsulation smells Modularization smells Hierarchy smells Key takeaways and conclusion
  • 19. S G Ganesh, Girish Suryanarayana, Tushar SharmaSlide 19 Incomplete abstraction 9-May-13 This smell arises when a type does not support a responsibility completely Specifically, the public interface of the type is incomplete in that it does not support all behavior needed by objects of its type
  • 20. S G Ganesh, Girish Suryanarayana, Tushar SharmaSlide 20 Incomplete abstraction Example 9-May-13 In this case, the MutableTreeNode supports only setUserObject but no corresponding getUserObject (which is provided in its derived class!) Hence, MutableTreeNode has Incomplete Abstraction smell How to fix it? Provide all the necessary and relevant methods required for satisfying a responsibility completely in the class itself In case of public APIs (as in this case), it is often too late to fix it!
  • 21. S G Ganesh, Girish Suryanarayana, Tushar SharmaSlide 21 Can you find this smell in this GoF pattern? 9-May-13
  • 22. S G Ganesh, Girish Suryanarayana, Tushar SharmaSlide 22 How to refactor & in future avoid this smell? 9-May-13 For each abstraction (especially in public interface) look out for symmetrical methods or methods that go together For example, methods for comparing equality of objects and getting hash code (in Java/C#) Look out for missing matching methods in symmetrical methods (see table) min/max open/close create/destroy get/set read/write print/scan first/last begin/end start/stop lock/unlock show/hide up/down source/target insert/delete first/last push/pull enable/disable acquire/release left/right on/off

Search related