Pertemuan 12 Refactoring Mata kuliah: T0144 – Advanced Topics in Software Engineering Tahun: 2010.

Slides:



Advertisements
Similar presentations
12-Dec-14 Refactoring IV. Previously discussed bad smells Duplicated code — and other forms of redundancy Long method — use short methods that delegate.
Advertisements

About Me – Frank Xu Education ▫ North Dakota State University  Ph.D. in Software Engineering ▫ Towson University  MS in Computer Science ▫ Southeast.
© 2010 Shawn A. Bohner Software Construction and Evolution - CSSE 375 Even more Bad Smells in Code Shawn & Steve Q1 Shawn & Steve Hint 
You want me to do what??? Refactoring legacy applications aka : fixing someone else’s “bad” code Niel Zeeman Team Foundation Consulting
Gregor Gisler-Merz BrownBag Session Refactoring.
Refactoring Overview  What is refactoring?  What are four good reasons to refactor?  When should you refactor?  What is a bad smell (relative to refactoring.
Software Construction and Evolution - CSSE 375 Bad Smells in Code Shawn Bohner & Steve Chenoweth.
Refactoring By: Brian Smith. What is Refactoring? Definition: a change to the internal structure of software to make it easier to understand and cheaper.
1 Software Maintenance and Evolution CSSE 575: Session 1, Part 4 Even more Bad Smells in Code Steve Chenoweth Office Phone: (812) Cell: (937)
Introduction to Refactoring Excerpted from ‘What is Refactoring?’ by William C. Wake and Refactoring: Improving the Design of Existing Code by Martin Fowler.
George Blank University Lecturer. REFACTORING Improving the Design of Existing Code Supplement to Ian Sommerville, Software Engineering, Chapter 20 Prepared.
XP and Refactoring David Talby. Development Methodologies The Software Crisis – 84% of software projects are not on time – 31% of software projects never.
25-Jun-15 Refactoring III. General philosophy A refactoring is just a way of rearranging code Refactorings are used to solve problems If there’s no problem,
REFACTORING Improving the Design of Existing Code Atakan Şimşek e
“Blink-factoring”: Software engineering meets pop psychology Presented by Jamie Hohman EECS 816: Object-Oriented Software Development April 22, 2008.
Leiden University. The university to discover. Leiden University. The university to discover. Leiden University. The university to discover. Software Engineering.
Maintenance Refactoring and Code Smells. Where are we? Over the semester we have talked about Software Engineering. The overall goal of software engineering.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
What is Refactoring? CSE301 University of Sunderland Harry R. Erwin, PhD.
Refactoring Cristescu Marilena. Definitions Loose Usage: Reorganize a program(or something) As a noun: a change made to the internal structure of some.
Software Refactoring Part I: Introduction Bartosz Walter Advanced Object-Oriented Design Lecture 5.
1 Software Maintenance and Evolution CSSE 575: Session 1, Part 3 Bad Smells in Code - 1 Steve Chenoweth Office Phone: (812) Cell: (937)
LECTURE 38: REFACTORING CSC 395 – Software Engineering.
Refactoring - A disciplined approach to rework for better design.
Refactoring Improving the structure of existing code Refactoring1.
Refactoring (continued) Source: "Refactoring: Improving the Design of Existing Code", Martin Fowler.
SWE 316: Software Design and Architecture Objectives Lecture # 20 Improving the existing design: Refactoring SWE 316: Software Design and Architecture.
When and How to Refactor? Refactoring Patterns Alexander Vakrilov Telerik Corporation Senior Developer and Team Leader.
Refactoring1 Improving the structure of existing code.
Pertemuan 10 Enterprise Application Patterns Mata kuliah: T0144 – Advanced Topics in Software Engineering Tahun: 2010.
The effectiveness of refactoring based on a compatibility testing taxonomy and a dependency graph Steve Counsell and Robert Hierons, Brunel University,
Introduction to Refactoring Jim Cooper Falafel Software.
Informatics 122 Software Design II
Incremental Design Why incremental design? Goal of incremental design Tools for incremental design  UML diagrams  Design principles  Design patterns.
Software Engineering CS3003 Lecture 4 Code bad smells and refactoring.
Refactoring and such ● (Side note) Specialization ● Key terms ● Abstraction, state, persistence and association and their relationship to software development.
Refactoring: Code Smells. Admin Notes REGISTER FOR BLACKBOARD Watch blackboard site for updates on class as hurricane season approaches.
Refactoring. Refactoring Overview  What is refactoring?  What are four good reasons to refactor?  When should you refactor?  What is a bad smell (relative.
Refactoring 2. Admin Blackboard Quiz Acknowledgements Material in this presentation was drawn from Martin Fowler, Refactoring: Improving the Design of.
REFACTORINGREFACTORING. Realities Code evolves substantially during development Requirements changes 1%-4% per month on a project Current methodologies.
NJIT 1 Test Driven Development and Refactoring Larman, Chapter 21.
Refactoring II Dealing with Polymorphism. Switch in Rental Switches on Movie! class Rental … public double getCharge() { double result = 0; switch (getMovie().getPriceCode()){
Module 3. Smells Between Classes Course: Refactoring.
1 Software Maintenance and Evolution CSSE 575: Session 2, Part 1 Refactoring Principles Steve Chenoweth Office Phone: (812) Cell: (937)
1 Software Maintenance and Evolution CSSE 575: Session 3, Part 3 Dealing with Generalization Steve Chenoweth Office Phone: (812) Cell: (937)
SEG 4110 – Advanced Software Design and Reengineering Topic T Introduction to Refactoring.
Refactoring. Mathematics: Factor ● fac·tor – One of two or more quantities that divides a given quantity without a remainder, e.g., 2 and 3 are factors.
Refactoring1 Improving the structure of existing code.
Refactoring. 2 Process of changing a software system in such a way that it does not alter the external behavior of the code, yet improves its internal.
CSSE 375 Organizing Data – Part 1 Shawn and Steve Q1.
Software Construction and Evolution - CSSE 375 Dealing with Generalization Steve and Shawn Left – In the 1990 movie “The Freshman,” Matthew Broderick,
Refactoring. DCS – SWC 2 Refactoring ”A change made to the internal structure of software to make it easier to understand and cheaper to modify without.
A (Very) Simple Example Consolidate duplicate conditional fragments if (isSpecialDeal()) { total = price * 0.95; send (); } else { total = price * 0.98;
Principles and examples
Steve Chenoweth Office Phone: (812) Cell: (937)
Steve Chenoweth Office Phone: (812) Cell: (937)
Refactoring and Code Smells
Software Construction and Evolution - CSSE 375 Composing Methods
بازآرایی برنامه Code Refactoring
Refactoring III 27-Nov-18.
Code Smells 1.
Improving the structure of existing code
Refactoring and Code Smells
Refactoring III 25-Dec-18.
Advanced Programming Behnam Hatami Fall 2017.
Refactoring.
Refactoring and Code Smells
Refactoring.
Refactoring and Code Smells
Presentation transcript:

Pertemuan 12 Refactoring Mata kuliah: T0144 – Advanced Topics in Software Engineering Tahun: 2010

3 Learning Outcomes Pada akhir pertemuan ini, diharapkan : Mahasiswa dapat menerapkan prinsip prinsip Refactoring dalam software development

4 Outline Material Refactorings Definition Why should you refactor? When should you refactor? “Code Smells” Partial list of refactorings suggestion for common code smells

What is Refactoring? “A change made to the internal structure of software to make it easier to understand and cheaper to modify without changing its observable behavior” (Martin Fowler)

What is Refactoring? (2) “A change to the system that leaves its behavior unchanged, but enhances some nonfunctional quality – simplicity, flexibility, understandability, performance” (Kent Beck)

Why should you refactor? Refactoring Improves the Design of Software –Without refactoring, the design of the program will decay. As people change code—changes to realize short-term goals or changes made without a full comprehension of the design of the code—the code loses its structure. –Poorly designed code usually takes more code to do the same things, often because the code quite literally does the same thing in several places. Thus an important aspect of improving design is to eliminate duplicate code. By eliminating the duplicates, you ensure that the code says everything once and only once, which is the essence of good design.

Why should you refactor? Refactoring Makes Software Easier to Understand –Refactoring helps you to make your code more readable. When refactoring you have code that works but is not ideally structured. A little time spent refactoring can make the code better communicate its purpose. Refactoring Helps You Find Bugs Refactoring Helps You Program Faster

When should you refactor? The Rule of Three –The first time you do something, you just do it. –The second time you do something similar, you wince at the duplication, but you do the duplicate thing anyway. –The third time you do something similar, you refactor. Refactor When You Add Function Refactor When You Need to Fix a Bug Refactor as You do a Code Review

“Code Smells” Indicators that something may be wrong in the code Can occur both in production code and test code Needs “deodorant” as soon as possible

List of “Code Smells” Alternative Classes with Different Interfaces Comments Data Class Data Clumps Divergent Change Duplicated Code Feature Envy Inappropriate Intimacy Incomplete Library Class Large Class Lazy Class Long Method Long Parameter List Message Chains Middle Man Parallel Inheritance Hierarchies Primitive Obsession Refused Bequest Shotgun Surgery Speculative Generality Switch Statements Temporary Field

Example: Comments Often used as deodorant for other smells Not necessarily bad in and of themselves but may indicate areas where the code is not as clear as it could be Refactorings –Extract Method –Introduce Assertion

Example: Duplicated Code Code repeated in multiple places Refactorings –Extract Method –Extract Class –Pull Up Method –Form Template Method

Example: Data Class A class whose only purpose is holding data Class has instance variables, getters, and setters Refactorings –Move Method –Encapsulate Field –Encapsulate Collection

Example: Data Clumps Sets of variables usually passed together in multiple places Refactorings –Extract Class –Introduce Parameter Object –Preserve Whole Object

Example: Inappropriate Intimacy Classes using too many things that should be private in other classes Refactorings –Move Method –Move Field –Change Bidirectional Association to Unidirectional –Replace Inheritance with Delegation –Hide Delegate

Example: Large Class A class with too many instance variables or too much code Refactorings –Extract Class –Extract Subclass –Extract Interface –Replace Data Value with Object

Example: Lazy Class A class that isn’t doing enough work to justify its maintenance Refactorings –Inline Class –Collapse Hierarchy

Example: Long Method Methods with many statements, loops, or variables Refactorings –Extract Method –Replace Temp with Query –Replace Method with Method Object –Decompose Conditional

Example: Middle Man One class simply delegates many of its requests to another class Refactorings –Hide Middle Man –Inline Method –Replace Delegation with Inheritance

Etc, etc Read up!

22 References Refactoring: Improving the Design of Existing Code Martin Fowler Addison-Wesley The Pragmatic Programmer: From Journeyman to Master Andrew Hunt, David Thomas Addison-Wesley Professional (October 30, 1999) Code Complete 2: A Practical Handbook of Software Construction Steve McConnell Microsoft Press; 2nd edition (June 9, 2004) Smells to Refactorings