SlideShare une entreprise Scribd logo
1  sur  14
Internal Use Only 4/22/2011 1 Ch 6: Composing Methods Refactoring: Improving The Design of Existing Code
Internal Use Only 4/22/2011 2 Ch6: Composing Methods ,[object Object]
6.2 Inline Method
6.3 Inline Temp
6.4 Replace Temp with Query
6.5 Introduce Explaining Variable
6.6 Split Temporary Variable
6.7 Remove Assignments to Parameters
6.8 Replace Method with Method Object
6.9 Substitute Algorithm,[object Object]
6.1 Extract Method Mechanics Create a new method, name it according to its purpose Copy code to new method Check local variables Check temporary variables Local variables modified by target code block? Pass in local variables needed by new method as parameters Compile new method Replace code block with new method Compile and test Internal Use Only 4/22/2011 4
6.2 Inline Method 在函式呼叫點插入函式本體,然後移除該函式。 Motivation Remove redundant redirection Mechanics Make sure the method is not polymorphic Find all of its callers Replace all calls to it with its code Compile and test Delete the method definition Internal Use Only 4/22/2011 5
6.3 Inline Temp 將所有對只被附值一次暫時變數的引用動作,替換為對它賦值的那個運算式本身。 Motivation Remove temporary variables that block refactoring Mechanics If the temporary variable is not final, declare it as final and compile Replace all references to it with its initialization Compile and test after each replacement Delete the variable declaration and initialization Compile and test Internal Use Only 4/22/2011 6
6.4 Replace Temp with Query 將對暫時變數附值的運算式提煉到一個獨立函式中。將這個暫時變數的所有「被引用點」替換為「對新函式的呼叫」。新函式可被其他函式使用。 Motivation Make the query available to the class Mechanics Find a temporary variable that has been assign once only Declare it as final and compile Move the initialization code to a new method Compile and test Do Inline Temp on the temporary variable Internal Use Only 4/22/2011 7

Contenu connexe

Tendances

ADVANCE SQL-"Sub queries"
ADVANCE SQL-"Sub queries"ADVANCE SQL-"Sub queries"
ADVANCE SQL-"Sub queries"Ankit Surti
 
An introduction to apex code test methods developer.force
An introduction to apex code test methods   developer.forceAn introduction to apex code test methods   developer.force
An introduction to apex code test methods developer.forcesendmail2cherukuri
 
QTP&UFT Automation Framework
QTP&UFT Automation FrameworkQTP&UFT Automation Framework
QTP&UFT Automation FrameworkYu Tao Zhang
 
e computer notes - Subqueries
e computer notes - Subqueriese computer notes - Subqueries
e computer notes - Subqueriesecomputernotes
 
Procedures/functions of rdbms
Procedures/functions of rdbmsProcedures/functions of rdbms
Procedures/functions of rdbmsjain.pralabh
 
Function & procedure
Function & procedureFunction & procedure
Function & procedureatishupadhyay
 
Effective Readable unit testing with junit5
Effective Readable unit testing with junit5Effective Readable unit testing with junit5
Effective Readable unit testing with junit5Sajith Vijesekara
 
Introduction to Everit Component Registry - B Zsoldos
Introduction to Everit Component Registry - B ZsoldosIntroduction to Everit Component Registry - B Zsoldos
Introduction to Everit Component Registry - B Zsoldosmfrancis
 
Qtp Basics
Qtp BasicsQtp Basics
Qtp Basicsmehramit
 
Apex Testing and Best Practices
Apex Testing and Best PracticesApex Testing and Best Practices
Apex Testing and Best PracticesJitendra Zaa
 
Spring certification-mock-exam
Spring certification-mock-examSpring certification-mock-exam
Spring certification-mock-examdmz networks
 

Tendances (19)

Orcal FUNCTIONS
Orcal FUNCTIONSOrcal FUNCTIONS
Orcal FUNCTIONS
 
ADVANCE SQL-"Sub queries"
ADVANCE SQL-"Sub queries"ADVANCE SQL-"Sub queries"
ADVANCE SQL-"Sub queries"
 
Spring framework part 2
Spring framework  part 2Spring framework  part 2
Spring framework part 2
 
An introduction to apex code test methods developer.force
An introduction to apex code test methods   developer.forceAn introduction to apex code test methods   developer.force
An introduction to apex code test methods developer.force
 
QTP&UFT Automation Framework
QTP&UFT Automation FrameworkQTP&UFT Automation Framework
QTP&UFT Automation Framework
 
e computer notes - Subqueries
e computer notes - Subqueriese computer notes - Subqueries
e computer notes - Subqueries
 
Procedures/functions of rdbms
Procedures/functions of rdbmsProcedures/functions of rdbms
Procedures/functions of rdbms
 
Function & procedure
Function & procedureFunction & procedure
Function & procedure
 
Effective Readable unit testing with junit5
Effective Readable unit testing with junit5Effective Readable unit testing with junit5
Effective Readable unit testing with junit5
 
Introduction to Everit Component Registry - B Zsoldos
Introduction to Everit Component Registry - B ZsoldosIntroduction to Everit Component Registry - B Zsoldos
Introduction to Everit Component Registry - B Zsoldos
 
Stored procedure
Stored procedureStored procedure
Stored procedure
 
Qtp Basics
Qtp BasicsQtp Basics
Qtp Basics
 
Plsql
PlsqlPlsql
Plsql
 
Apex Testing and Best Practices
Apex Testing and Best PracticesApex Testing and Best Practices
Apex Testing and Best Practices
 
Oracle: Procedures
Oracle: ProceduresOracle: Procedures
Oracle: Procedures
 
Ppt Qtp
Ppt QtpPpt Qtp
Ppt Qtp
 
Functions
FunctionsFunctions
Functions
 
Function Parameters
Function ParametersFunction Parameters
Function Parameters
 
Spring certification-mock-exam
Spring certification-mock-examSpring certification-mock-exam
Spring certification-mock-exam
 

En vedette

重構—改善既有程式的設計(chapter 12,13)
重構—改善既有程式的設計(chapter 12,13)重構—改善既有程式的設計(chapter 12,13)
重構—改善既有程式的設計(chapter 12,13)Chris Huang
 
重構—改善既有程式的設計(chapter 2,3)
重構—改善既有程式的設計(chapter 2,3)重構—改善既有程式的設計(chapter 2,3)
重構—改善既有程式的設計(chapter 2,3)Chris Huang
 
重構—改善既有程式的設計(chapter 8)part 1
重構—改善既有程式的設計(chapter 8)part 1重構—改善既有程式的設計(chapter 8)part 1
重構—改善既有程式的設計(chapter 8)part 1Chris Huang
 
重構—改善既有程式的設計(chapter 9)
重構—改善既有程式的設計(chapter 9)重構—改善既有程式的設計(chapter 9)
重構—改善既有程式的設計(chapter 9)Chris Huang
 
重構—改善既有程式的設計(chapter 7)
重構—改善既有程式的設計(chapter 7)重構—改善既有程式的設計(chapter 7)
重構—改善既有程式的設計(chapter 7)Chris Huang
 
重構—改善既有程式的設計(chapter 4,5)
重構—改善既有程式的設計(chapter 4,5)重構—改善既有程式的設計(chapter 4,5)
重構—改善既有程式的設計(chapter 4,5)Chris Huang
 
Approaching real-time-hadoop
Approaching real-time-hadoopApproaching real-time-hadoop
Approaching real-time-hadoopChris Huang
 
重構—改善既有程式的設計(chapter 8)part 2
重構—改善既有程式的設計(chapter 8)part 2重構—改善既有程式的設計(chapter 8)part 2
重構—改善既有程式的設計(chapter 8)part 2Chris Huang
 
Real time big data applications with hadoop ecosystem
Real time big data applications with hadoop ecosystemReal time big data applications with hadoop ecosystem
Real time big data applications with hadoop ecosystemChris Huang
 
重構—改善既有程式的設計(chapter 1)
重構—改善既有程式的設計(chapter 1)重構—改善既有程式的設計(chapter 1)
重構—改善既有程式的設計(chapter 1)Chris Huang
 
A Graph Service for Global Web Entities Traversal and Reputation Evaluation B...
A Graph Service for Global Web Entities Traversal and Reputation Evaluation B...A Graph Service for Global Web Entities Traversal and Reputation Evaluation B...
A Graph Service for Global Web Entities Traversal and Reputation Evaluation B...Chris Huang
 

En vedette (11)

重構—改善既有程式的設計(chapter 12,13)
重構—改善既有程式的設計(chapter 12,13)重構—改善既有程式的設計(chapter 12,13)
重構—改善既有程式的設計(chapter 12,13)
 
重構—改善既有程式的設計(chapter 2,3)
重構—改善既有程式的設計(chapter 2,3)重構—改善既有程式的設計(chapter 2,3)
重構—改善既有程式的設計(chapter 2,3)
 
重構—改善既有程式的設計(chapter 8)part 1
重構—改善既有程式的設計(chapter 8)part 1重構—改善既有程式的設計(chapter 8)part 1
重構—改善既有程式的設計(chapter 8)part 1
 
重構—改善既有程式的設計(chapter 9)
重構—改善既有程式的設計(chapter 9)重構—改善既有程式的設計(chapter 9)
重構—改善既有程式的設計(chapter 9)
 
重構—改善既有程式的設計(chapter 7)
重構—改善既有程式的設計(chapter 7)重構—改善既有程式的設計(chapter 7)
重構—改善既有程式的設計(chapter 7)
 
重構—改善既有程式的設計(chapter 4,5)
重構—改善既有程式的設計(chapter 4,5)重構—改善既有程式的設計(chapter 4,5)
重構—改善既有程式的設計(chapter 4,5)
 
Approaching real-time-hadoop
Approaching real-time-hadoopApproaching real-time-hadoop
Approaching real-time-hadoop
 
重構—改善既有程式的設計(chapter 8)part 2
重構—改善既有程式的設計(chapter 8)part 2重構—改善既有程式的設計(chapter 8)part 2
重構—改善既有程式的設計(chapter 8)part 2
 
Real time big data applications with hadoop ecosystem
Real time big data applications with hadoop ecosystemReal time big data applications with hadoop ecosystem
Real time big data applications with hadoop ecosystem
 
重構—改善既有程式的設計(chapter 1)
重構—改善既有程式的設計(chapter 1)重構—改善既有程式的設計(chapter 1)
重構—改善既有程式的設計(chapter 1)
 
A Graph Service for Global Web Entities Traversal and Reputation Evaluation B...
A Graph Service for Global Web Entities Traversal and Reputation Evaluation B...A Graph Service for Global Web Entities Traversal and Reputation Evaluation B...
A Graph Service for Global Web Entities Traversal and Reputation Evaluation B...
 

Similaire à 重構—改善既有程式的設計(chapter 6)

Legacy Coderetreat @Budapest 2013 02 16
Legacy Coderetreat @Budapest 2013 02 16Legacy Coderetreat @Budapest 2013 02 16
Legacy Coderetreat @Budapest 2013 02 16Adi Bolboaca
 
QTP Automation Testing Tutorial 6
QTP Automation Testing Tutorial 6QTP Automation Testing Tutorial 6
QTP Automation Testing Tutorial 6Akash Tyagi
 
PHP 8: What's New and Changed
PHP 8: What's New and ChangedPHP 8: What's New and Changed
PHP 8: What's New and ChangedAyesh Karunaratne
 
SAP Testing Training
SAP Testing TrainingSAP Testing Training
SAP Testing TrainingVGlobal Govi
 
Functional JavaScript Fundamentals
Functional JavaScript FundamentalsFunctional JavaScript Fundamentals
Functional JavaScript FundamentalsSrdjan Strbanovic
 
Testing the untestable
Testing the untestableTesting the untestable
Testing the untestableRoyKlein
 
Spring talk111204
Spring talk111204Spring talk111204
Spring talk111204s4al_com
 

Similaire à 重構—改善既有程式的設計(chapter 6) (12)

Legacy Coderetreat @Budapest 2013 02 16
Legacy Coderetreat @Budapest 2013 02 16Legacy Coderetreat @Budapest 2013 02 16
Legacy Coderetreat @Budapest 2013 02 16
 
Refactoring
RefactoringRefactoring
Refactoring
 
Spring Framework
Spring FrameworkSpring Framework
Spring Framework
 
QTP Automation Testing Tutorial 6
QTP Automation Testing Tutorial 6QTP Automation Testing Tutorial 6
QTP Automation Testing Tutorial 6
 
PHP 8: What's New and Changed
PHP 8: What's New and ChangedPHP 8: What's New and Changed
PHP 8: What's New and Changed
 
QTP Faqs
QTP FaqsQTP Faqs
QTP Faqs
 
SAP Testing Training
SAP Testing TrainingSAP Testing Training
SAP Testing Training
 
Functional JavaScript Fundamentals
Functional JavaScript FundamentalsFunctional JavaScript Fundamentals
Functional JavaScript Fundamentals
 
Reduce Reuse Refactor
Reduce Reuse RefactorReduce Reuse Refactor
Reduce Reuse Refactor
 
Testing the untestable
Testing the untestableTesting the untestable
Testing the untestable
 
Spring
SpringSpring
Spring
 
Spring talk111204
Spring talk111204Spring talk111204
Spring talk111204
 

Plus de Chris Huang

Data compression, data security, and machine learning
Data compression, data security, and machine learningData compression, data security, and machine learning
Data compression, data security, and machine learningChris Huang
 
Kks sre book_ch10
Kks sre book_ch10Kks sre book_ch10
Kks sre book_ch10Chris Huang
 
Kks sre book_ch1,2
Kks sre book_ch1,2Kks sre book_ch1,2
Kks sre book_ch1,2Chris Huang
 
20130310 solr tuorial
20130310 solr tuorial20130310 solr tuorial
20130310 solr tuorialChris Huang
 
Scaling big-data-mining-infra2
Scaling big-data-mining-infra2Scaling big-data-mining-infra2
Scaling big-data-mining-infra2Chris Huang
 
Applying Media Content Analysis to the Production of Musical Videos as Summar...
Applying Media Content Analysis to the Production of Musical Videos as Summar...Applying Media Content Analysis to the Production of Musical Videos as Summar...
Applying Media Content Analysis to the Production of Musical Videos as Summar...Chris Huang
 
Hbase status quo apache-con europe - nov 2012
Hbase status quo   apache-con europe - nov 2012Hbase status quo   apache-con europe - nov 2012
Hbase status quo apache-con europe - nov 2012Chris Huang
 
Hbase schema design and sizing apache-con europe - nov 2012
Hbase schema design and sizing   apache-con europe - nov 2012Hbase schema design and sizing   apache-con europe - nov 2012
Hbase schema design and sizing apache-con europe - nov 2012Chris Huang
 
Designs, Lessons and Advice from Building Large Distributed Systems
Designs, Lessons and Advice from Building Large Distributed SystemsDesigns, Lessons and Advice from Building Large Distributed Systems
Designs, Lessons and Advice from Building Large Distributed SystemsChris Huang
 
Hw5 my house in yong he
Hw5 my house in yong heHw5 my house in yong he
Hw5 my house in yong heChris Huang
 
Social English Class HW4
Social English Class HW4Social English Class HW4
Social English Class HW4Chris Huang
 
Social English Class HW3
Social English Class HW3Social English Class HW3
Social English Class HW3Chris Huang
 
火柴人的故事
火柴人的故事火柴人的故事
火柴人的故事Chris Huang
 
中德文化比較
中德文化比較中德文化比較
中德文化比較Chris Huang
 
Sm Case4 Fuji Xerox
Sm Case4 Fuji XeroxSm Case4 Fuji Xerox
Sm Case4 Fuji XeroxChris Huang
 
Disney報告 最終版
Disney報告 最終版Disney報告 最終版
Disney報告 最終版Chris Huang
 

Plus de Chris Huang (18)

Data compression, data security, and machine learning
Data compression, data security, and machine learningData compression, data security, and machine learning
Data compression, data security, and machine learning
 
Kks sre book_ch10
Kks sre book_ch10Kks sre book_ch10
Kks sre book_ch10
 
Kks sre book_ch1,2
Kks sre book_ch1,2Kks sre book_ch1,2
Kks sre book_ch1,2
 
20130310 solr tuorial
20130310 solr tuorial20130310 solr tuorial
20130310 solr tuorial
 
Scaling big-data-mining-infra2
Scaling big-data-mining-infra2Scaling big-data-mining-infra2
Scaling big-data-mining-infra2
 
Applying Media Content Analysis to the Production of Musical Videos as Summar...
Applying Media Content Analysis to the Production of Musical Videos as Summar...Applying Media Content Analysis to the Production of Musical Videos as Summar...
Applying Media Content Analysis to the Production of Musical Videos as Summar...
 
Wissbi osdc pdf
Wissbi osdc pdfWissbi osdc pdf
Wissbi osdc pdf
 
Hbase status quo apache-con europe - nov 2012
Hbase status quo   apache-con europe - nov 2012Hbase status quo   apache-con europe - nov 2012
Hbase status quo apache-con europe - nov 2012
 
Hbase schema design and sizing apache-con europe - nov 2012
Hbase schema design and sizing   apache-con europe - nov 2012Hbase schema design and sizing   apache-con europe - nov 2012
Hbase schema design and sizing apache-con europe - nov 2012
 
Designs, Lessons and Advice from Building Large Distributed Systems
Designs, Lessons and Advice from Building Large Distributed SystemsDesigns, Lessons and Advice from Building Large Distributed Systems
Designs, Lessons and Advice from Building Large Distributed Systems
 
Hw5 my house in yong he
Hw5 my house in yong heHw5 my house in yong he
Hw5 my house in yong he
 
Social English Class HW4
Social English Class HW4Social English Class HW4
Social English Class HW4
 
Social English Class HW3
Social English Class HW3Social English Class HW3
Social English Class HW3
 
Sm Case1 Ikea
Sm Case1 IkeaSm Case1 Ikea
Sm Case1 Ikea
 
火柴人的故事
火柴人的故事火柴人的故事
火柴人的故事
 
中德文化比較
中德文化比較中德文化比較
中德文化比較
 
Sm Case4 Fuji Xerox
Sm Case4 Fuji XeroxSm Case4 Fuji Xerox
Sm Case4 Fuji Xerox
 
Disney報告 最終版
Disney報告 最終版Disney報告 最終版
Disney報告 最終版
 

Dernier

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 

Dernier (20)

microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 

重構—改善既有程式的設計(chapter 6)

  • 1. Internal Use Only 4/22/2011 1 Ch 6: Composing Methods Refactoring: Improving The Design of Existing Code
  • 2.
  • 5. 6.4 Replace Temp with Query
  • 8. 6.7 Remove Assignments to Parameters
  • 9. 6.8 Replace Method with Method Object
  • 10.
  • 11. 6.1 Extract Method Mechanics Create a new method, name it according to its purpose Copy code to new method Check local variables Check temporary variables Local variables modified by target code block? Pass in local variables needed by new method as parameters Compile new method Replace code block with new method Compile and test Internal Use Only 4/22/2011 4
  • 12. 6.2 Inline Method 在函式呼叫點插入函式本體,然後移除該函式。 Motivation Remove redundant redirection Mechanics Make sure the method is not polymorphic Find all of its callers Replace all calls to it with its code Compile and test Delete the method definition Internal Use Only 4/22/2011 5
  • 13. 6.3 Inline Temp 將所有對只被附值一次暫時變數的引用動作,替換為對它賦值的那個運算式本身。 Motivation Remove temporary variables that block refactoring Mechanics If the temporary variable is not final, declare it as final and compile Replace all references to it with its initialization Compile and test after each replacement Delete the variable declaration and initialization Compile and test Internal Use Only 4/22/2011 6
  • 14. 6.4 Replace Temp with Query 將對暫時變數附值的運算式提煉到一個獨立函式中。將這個暫時變數的所有「被引用點」替換為「對新函式的呼叫」。新函式可被其他函式使用。 Motivation Make the query available to the class Mechanics Find a temporary variable that has been assign once only Declare it as final and compile Move the initialization code to a new method Compile and test Do Inline Temp on the temporary variable Internal Use Only 4/22/2011 7
  • 15. 6.5 Introduce Explaining Variable 將該複雜運算式〈或其中一部分〉的結果放進一個暫時變數,以此變數名稱來解釋運算式用途。 Motivation Use a temporary variable to help explain the purpose of an operation Mechanics Declare a final temporary variable to store the result of an operation Replace the operation with a reference to the temporary variable Compile and test Repeat on other operations Internal Use Only 4/22/2011 8
  • 16. 6.6 Split Temporary Variable 針對每次賦值,創造一個獨立的、對應的暫時變數。 Motivation Avoid using a temporary variable for multiple purposes Mechanics Rename the temporary variable at its declaration and initialization Declare new temporary variable as final Replace references to the temporary variable before its second assignment with the new one Re-declare the temporary variable at its second assignment Compile and test Repeat on other temporary variables Internal Use Only 4/22/2011 9
  • 17. 6.7 Remove Assignments to Parameters 以一個暫時變數取代一個參數的位置。 Motivation Avoid assigning new values to parameters (passed by value) Mechanics Create a temporary variable to store the new value for the parameter Replace all references to the parameter after the assignment with reference to the temporary variable Edit the assignment statement to assign to the temporary variable Compile and test Internal Use Only 4/22/2011 10
  • 18. 6.8 Replace Method with Method Object 將大型函式放進一個獨立物件中,如此一來區域變數就成了物件內的欄位。然後你可以在同一個物件中將這個大型函式分解為數個小型函式。 Motivation Overcome the difficulty of handling local variables during method breakdown Internal Use Only 4/22/2011 11
  • 19. 6.8 Replace Method with Method Object Mechanics Create a new class, name it according to its purpose Create a final field for the source object, and create a field for each parameter and each temporary variable Add a constructor to receive source object reference and all parameters Add a compute() method Copy code to compute(), use the reference to the source object when calling any of its methods. Compile Replace the original method with a comment: Create an object instance of the new class, and then call its compute() method. Internal Use Only 4/22/2011 12
  • 20. 6.9 Substitute Algorithm 將函式本體替換為另一個演算法。 Motivation Clarity Mechanics Compile replacement code Run unit tests If test results are different, use old algorithm as basis for debugging Internal Use Only 4/22/2011 13
  • 21. Internal Use Only 4/22/2011 14