Refactoring and such ● (Side note) Specialization ● Key terms ● Abstraction, state, persistence and association and their relationship to software development.

Slides:



Advertisements
Similar presentations
Ch:8 Design Concepts S.W Design should have following quality attribute: Functionality Usability Reliability Performance Supportability (extensibility,
Advertisements

12-Dec-14 Refactoring IV. Previously discussed bad smells Duplicated code — and other forms of redundancy Long method — use short methods that delegate.
©Ian Sommerville 2000 Software Engineering, 6th edition. Chapter 12Slide 1 Software Design l Objectives To explain how a software design may be represented.
Test-Driven Development and Refactoring CPSC 315 – Programming Studio.
© 2010 Shawn A. Bohner Software Construction and Evolution - CSSE 375 Even more Bad Smells in Code Shawn & Steve Q1 Shawn & Steve Hint 
Abstraction Lecture-4. ADT example: London Underground Map.
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.
1 Software Maintenance and Evolution CSSE 575: Session 3, Part 4 Big Refactorings Steve Chenoweth Office Phone: (812) Cell: (937)
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.
REFACTORING Improving the Design of Existing Code Atakan Şimşek e
WEL COME PRAVEEN M JIGAJINNI PGT (Computer Science) MCA, MSc[IT], MTech[IT],MPhil (Comp.Sci), PGDCA, ADCA, Dc. Sc. & Engg.
© 2006 Pearson Addison-Wesley. All rights reserved2-1 Chapter 2 Principles of Programming & Software Engineering.
Chapter 9 – Software Evolution and Maintenance
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.
GENERAL CONCEPTS OF OOPS INTRODUCTION With rapidly changing world and highly competitive and versatile nature of industry, the operations are becoming.
What is Refactoring? CSE301 University of Sunderland Harry R. Erwin, PhD.
CS 350 – Software Design The Object Paradigm – Chapter 1 If you were tasked to write code to access a description of shapes that were stored in a database.
Copyright 2002 Prentice-Hall, Inc. Modern Systems Analysis and Design Third Edition Jeffrey A. Hoffer Joey F. George Joseph S. Valacich Chapter 20 Object-Oriented.
LECTURE 38: REFACTORING CSC 395 – Software Engineering.
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.
Refactoring - A disciplined approach to rework for better design.
Refactoring Improving the structure of existing code Refactoring1.
17-Oct-15 Refactoring. 2 Refactoring is: restructuring (rearranging) code......in a series of small, semantics-preserving transformations (i.e. the code.
SE: CHAPTER 7 Writing The Program
Refactoring (continued) Source: "Refactoring: Improving the Design of Existing Code", Martin Fowler.
Refactoring1 Improving the structure of existing code.
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
Software Engineering CS3003 Lecture 4 Code bad smells and refactoring.
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.
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)
© 2006 Pearson Addison-Wesley. All rights reserved 2-1 Chapter 2 Principles of Programming & Software Engineering.
Software Construction and Evolution - CSSE 375 Making Method Calls Simpler Shawn and Steve Below – “Be the character!” The late acting teacher Lee Strasberg.
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.
OO in Context Lecture 13: Dolores Zage. Confused about OO Not alone, there is much confusion about OO many programs are claimed to be OO but are not really.
Refactoring1 Improving the structure of existing code.
Pertemuan 12 Refactoring Mata kuliah: T0144 – Advanced Topics in Software Engineering Tahun: 2010.
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.
Module 9. Dealing with Generalization Course: Refactoring.
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)
Programming paradigms
CHAPTER 5 GENERAL OOP CONCEPTS.
Steve Chenoweth Office Phone: (812) Cell: (937)
Refactoring and Code Smells
Computer Programming.
Code Smells 1.
Chapter 20 Object-Oriented Analysis and Design
Improving the structure of existing code
Refactoring and Code Smells
Refactoring.
Refactoring and Code Smells
Refactoring.
Refactoring and Code Smells
Presentation transcript:

Refactoring and such ● (Side note) Specialization ● Key terms ● Abstraction, state, persistence and association and their relationship to software development ● Evolution and its relation to iteration ● Refactoring and its relation to abstraction and iteration ● Refactoring ● Code Smells ● Refactoring catalogue ● Composing Methods ● Moving features between objects ● Organizing data ● Simplfying conditional expressions ● Making method calls simpler ● Dealing with Generalization ● Big refactorings

Abstraction ● The act of abstracting, separating, or withdrawing, or the state of being withdrawn; withdrawal. ● The act process of leaving out of consideration one or more properties of a complex object so as to attend to others; analysis. Thus, when the mind considers the form of a tree by itself, or the color of the leaves as separate from their size or figure, the act is called abstraction. So, also, when it considers whiteness, softness, virtue, existence, as separate from any particular objects. ● Abstraction is necessary to classification, by which things are arranged in genera and species. We separate in idea the qualities of certain objects, which are of the same kind, from others which are different, in each, and arrange the objects having the same properties in a class, or collected body. - Webster's Revised Unabridged Dictionary (1913)

State ● The circumstances or condition of a being or thing at any given time. ● State is the generic term, and denotes in general the mode in which a thing stands or exists. The situation of a thing is its state in reference to external objects and influences; its condition is its internal state, or what it is in itself considered. Our situation is good or bad as outward things bear favorably or unfavorably upon us; our condition is good or bad according to the state we are actually in as respects our persons, families, property, and other things which comprise our sources of enjoyment. ● A state may be considered to be a point in some space of all possible states. A simple example is a light, which is either on or off. A complex example is the electrical activation in a human brain while solving a problem. In computing and related fields, states, as in the light example, are often modelled as being discrete (rather than continuous) and the transition from one state to another is considered to be instantaneous. Another (related) property of a system is the number of possible states it may exhibit. This may be finite or infinite. A common model for a system with a finite number of discrete state is a finite state machine.

Persistence/Persistent & Association ● The quality or state of being persistent; staying or continuing quality ● Persistent: Inclined to persist; having staying qualities ● Persist: To stand firm; to be fixed and unmoved; to stay; to continue steadfastly; especially, to continue fixed in a course of conduct against opposing motives ● Association: The act of associating, or state of being associated; union; connection, whether of persons of things.

Evolution ● A general name for the history of the steps by which any living organism has acquired the morphological and physiological characters which distinguish it; a gradual unfolding of successive phases of growth or development. ● That series of changes under natural law which involves continuous progress from the homogeneous to the heterogeneous in structure, and from the single and simple to the diverse and manifold in quality or function. The process is by some limited to organic beings; by others it is applied to the inorganic and the psychical. It is also applied to explain the existence and growth of institutions, manners, language, civilization, and every product of human activity. The agencies and laws of the process are variously explained by different philosophers ● a process in which something passes by degrees to a different stage (especially a more advanced or mature stage)

Iteration and Refactoring ● Doing or saying again; a repeated performance ● Repetition; To utter or do a second time or many times; to repeat; as, to iterate advice. ● Software evolves through iteration. ● Refactoring: Refactoring is the process of changing a software system in such a way that it does not alter the external behavior of the code, yet improves the internal structure. It is a disciplined way to clean up code that minimizes the chances of introducing bugs. In essence, when you refactor you are improving the design of the code after it has been written. ● With refactoring, you can take a bad design, chaos even, and rework it into well designed code. Each step is simple, even simplistic. [...] Yet the cumulative effect of these small changes can radically improve the design. It is the exact reverse of the normal notion of software decay.

Refactoring and Unit Testing ● The first step of refactoring is always the same: build a solid set of tests for that section of code. The tests are essential because even though refactorings have been created in such a manner as to reduce the opportunities to make errors, humans still make mistakes. ● Modifying existing code changes its design. In the case of refactoring, we want to change the design of code so that it is better structured. We are not trying to change WHAT the code does. Unit tests help us to ensure that what the code is doing remains the same. Your strength of judgement in this respect is is solely based on the strength of your unit tests ● Unit tests need to be fully automatic and check their own results.

Software Evolution ● When developing software using refactoring, you are essentially performing 2 functions: ● Adding new functionality ● Refactoring ● When you add functionality, you should not change existing code ● When you refactor, you should not add or change functionality ● When to refactor? ● Refactor when you add a function to the software ● Refactor when you need to fix a bug ● Refactor when you do a code review

Refactoring ● When developing software using refactoring, you are essentially performing 2 functions: ● Adding new functionality ● Refactoring ● When you add functionality, you should not change existing code ● When you refactor, you should not add or change functionality ● When to refactor? ● Refactor when you add a function to the software ● If adding a new function is difficult, refactor to make it easy ● Refactor when you need to fix a bug ● Bugs can hide in bad code. Improve the code to help make bugs easier to find and fix ● Refactor when you do a code review

Code Smells ● Knowing what to refactor can be the difficult part. ● Experience has shown us that poor code tends to contain certain structures or features which alert the programmer to refactoring possibilities ● Based on judgement of the programmer, but the idea of “code smells” helps an abstract concept to a more concrete state.

Catalogue of Code Smells ● Duplicated Code ● Long Method ● Large Class (Cohesion) ● Long Parameter List ● Divergent Change (Cohesion) ● Shotgun surgery (opposite to divergent change) ● Feature envy (Cohesion/Coupling) ● Data Clumps (Cohesion) ● Primitive Obsession ● Switch statements ● Parallel Inheritance Hierarchies ● Lazy class ● Speculative Generality ● Temporary field (State issues) ● Message chains ● Middle man ● Inappropriate intimacy ● Alternative Classes with Different Interfaces ● Incomplete Library Class ● Data Class ● Refused Bequest ● Comments

Refactoring Catalogue ● Chapters 6-12 form the catalogue of refactorings. Each refactoring contains: ● A name ● A summary ● A motivation ● The mechanics ● Code examples (some of which are somewhat contrived) ● The refactoring catalogue contains the following sections: ● Composing Methods ● Moving features between objects ● Organizing data ● Simplfying conditional expressions ● Making method calls simpler ● Dealing with Generalization ● Big refactorings

Composing methods ● Procedural solutions (which most people are familiar with) tend to produce long sequences of commands. (ie. Procedures). ● These procedures are generally not cohesive for a given object. ● Long procedures usually involve more than one type of object, therefore, the responsibility contained within the procedure should be distributed amongst multiple object methods. ● The most common refactorings are: ● Extract Method ● Replace Temp with Query ● Inline Temp ● Split Temporary Variable

Moving features between objects ● This section generally deals with cohesion problems. ● When creating an object model, determining where to place various responsibilities can be a difficult task. If you have made a poor choice, moving things between objects can help improve cohesion. ● Most common refactorings: ● Move Method ● Move Field ● Extract Class/Inline Class ● Hide Delegate/Remove Middle Man

Organizing data ● Persons who have learned procedural methods of programming often deal with data in a manner which is a best fit for the OO world. ● Common refactorings include: ● Self encapsulate field ● Replace data value with object ● Replace array with object ● Change unidirectional association to bidirectional ● Change bidirectional association to unidirectional ● Replace type code with state.

Simplifying conditional expressions ● One of the problems with structured programming is that in order to maintain the proper structure, somewhat convoluted conditional expressions can be required ● Object oriented programs generally have less conditional behavior because much conditional behavior can be handled using polymorphism ● Common refactorings include: ● Decompose Conditional ● Consolodate Conditional Expression ● Replace nested conditional with guard clauses ● Remove control flag ● Replace conditional with polymorphism ● Introduce null object

Making method calls simpler ● One of the keys to OO is the focus on the interface of objects rather than their internals ● It is not terribly useful if object's interfaces are needlessly complex. ● One of the most common mistakes is that the name of the method does not really reflect what the method is doing. ● Common refactorings include: ● Rename method ● Add Parameter/Remove Parameter ● Introduce parameter object ● Replace parameter with method ● Separate query from modifier ● Replace constructor with Factory method

Dealing with Generalization ● Because most people do not think well in the abstract, their inheritance hierarchies are often poorly designed. ● Refactorings in this section deal mostly with moving fields and methods around the inheritance hierarchy ● Common refactorings are: ● Pull up field/ Push down field ● Pull up method/Push down method ● Extract subclass/Extract superclass ● Extract Interface ● Replace inheritance with delegation

Big refactorings ● Most refactorings are small steps. There are some that are not. ● The big refactorings are: ● Tease apart inheritance ● Convert procedural design to objects ● Separate domain from Presentation ● Extract Hierarchy