SlideShare une entreprise Scribd logo
1  sur  8
Télécharger pour lire hors ligne
Last lecture…
                                                                             On refactoring
                                                           • We explained what is refactoring, what is
                                                             software refactoring
                     Tutorial 4                            • How are they related to other restructuring
                More on Refactoring                          techniques?
                                                           • Examples of refactoring
              How to refactoring unstructured code?
                                                           • Refactoring structured source code into
               How to apply refactoring in Eclipse?
                                                             goal models
                                                           • …

Spring 2005          ECE450H1S   Software Engineering II   Spring 2005     ECE450H1S   Software Engineering II




                                                                           1. Refactoring an
                           Today…
                                                                         unstructured program
1. How to refactoring unstructured code into               • The subject is called “Squirrel Mail”
   goal models?                                            • It has 70 KLOC
2. How to use Eclipse to do refactoring?                   • Developed in PHP
3. Discussions                                               Function call
                                                             Foo.php: <?php include(“bar.php”) ?>
4. Relation to your course project                         • Why it is unstructured?
                                                             Foo.php: <a href=“bar.php”/>
                                                                       <a href=“moo.php”/>
                                                                       <?php echo “I won super 7!” ?>
                                                             Any idea?
Spring 2005          ECE450H1S   Software Engineering II   Spring 2005     ECE450H1S   Software Engineering II
Why a PHP program is
                                                                                                     The process
                   unstructured?
• Every Hyperlink generated from the PHP                            • Structured program is easier to understand
  is an “exit” in the current PHP program                                           /HJDF
                                                                                  VRXUFH FRGH
                                                                                                    ([WUDFW
                                                                                                   0HWKRGV
                                                                                                                      5HIDFWRUHG
                                                                                                                     VRXUFH FRGH
                                                                                                   5HIDFWRU
• It may call other PHP routines, other web
                                                                                                             HV                        1R             RQVWUXFW
  pages, etc. when user click at them                                                                               ,V VWUXFWXUHG
                                                                                                                                                     +DPPRFN JUDSK


• Non-deterministic, how could you tell
                                                                                                                                                     ([WUDFW
  which link will the user click?                                          $67
                                                                        DQQRWDWHG  3DUVH
                                                                                                    6WUXFWXUHG
                                                                                                     SURJUDP
                                                                                                                    (OLPLQDWH
                                                                                                                      *272
                                                                                                                                     +LJKOHYHO
                                                                                                                                     6WDWHFKDUW
                                                                                                                                                     6WDWHV
                                                                                                                                                   7UDQVLWLRQV
                                                                                                                                                                 6WDWHFKDUWV
                                                                        *RDO JUDSK
5HIDFWRULQJ
• Even “go back” button will change the                                 5HVWUXFWXUH

  behaviour of the program                                                                       7HVW WR                                $QDO]H 4XDOLW      *RDO 0RGHO
                                                                                                                      *RDO 0RGHO
                                                                        *RDO 0RGHO               LGHQWLI                                PHWULFV WR LGHQWLI        ZLWK
• So …                                                                                            1)5V
                                                                                                                      ZLWK 1)5V
                                                                                                                                             VRIWJRDOV            6RIWJRDOV


Spring 2005          ECE450H1S   Software Engineering II            Spring 2005                  ECE450H1S                 Software Engineering II




              1.1 Refactoring based on
                                                                                                             Example
                     comments
                                                                       /** Path for SquirrelMail required files. */
                                                                       define(‘SM_PATH’,’../’);
HQW            WKH IROORZLQJ GRHV 6                                  require_once($SM_PATH . ‘functions/strings.php’);
U            6, 2
UHIDFWRUHG       require_once($SM_PATH . ‘config/config.php’);
                                                                       require_once($SM_PATH . ‘functions/i18n.php’);
H[LW          6, 2
6, 2
require_once($SM_PATH . ‘functions/plugin.php’);
                                                                       require_once($SM_PATH . ‘functions/constants.php’);
               RWKHU …                                               require_once($SM_PATH . ‘functions/page_header.php’);
                                                                       require_once($SM_PATH . ‘functions/html.php’);
       9DULDEOHV GHILQHG EHIRUH WKH HQWU RI WKH EORFN                 require_once($SM_PATH . ‘functions/global.php’);
               , ,∪,
∩ ^ Y _ GHI Y S
∧ S ∠ S HQWU ` ≠ φ        require_once($SM_PATH . ‘functions/imap_general.php’);
       9DULDEOHV GHILQHG LQ WKH EORFN WKDW ZLOO EH XVHG DIWHU WKH
       H[LW
              2 2∪2

Contenu connexe

Similaire à tutorial4x4

Similaire à tutorial4x4 (6)

Node.Js Vs PHP: Which is Likely a Better Server Side Environment?
Node.Js Vs PHP: Which is Likely a Better Server Side Environment?Node.Js Vs PHP: Which is Likely a Better Server Side Environment?
Node.Js Vs PHP: Which is Likely a Better Server Side Environment?
 
Wt unit 4 server side technology-2
Wt unit 4 server side technology-2Wt unit 4 server side technology-2
Wt unit 4 server side technology-2
 
PHP - Introduction to PHP Fundamentals
PHP -  Introduction to PHP FundamentalsPHP -  Introduction to PHP Fundamentals
PHP - Introduction to PHP Fundamentals
 
Php Tutorial
Php TutorialPhp Tutorial
Php Tutorial
 
Oozie @ Riot Games
Oozie @ Riot GamesOozie @ Riot Games
Oozie @ Riot Games
 
Weaving aspects in PHP with the help of Go! AOP library
Weaving aspects in PHP with the help of Go! AOP libraryWeaving aspects in PHP with the help of Go! AOP library
Weaving aspects in PHP with the help of Go! AOP library
 

Plus de tutorialsruby

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>tutorialsruby
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />tutorialsruby
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008tutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheetstutorialsruby
 

Plus de tutorialsruby (20)

&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
TopStyle Help &amp; &lt;b>Tutorial&lt;/b>
 
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
The Art Institute of Atlanta IMD 210 Fundamentals of Scripting &lt;b>...&lt;/b>
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />&lt;img src="../i/r_14.png" />
&lt;img src="../i/r_14.png" />
 
Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0Standardization and Knowledge Transfer – INS0
Standardization and Knowledge Transfer – INS0
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml_basics
xhtml_basicsxhtml_basics
xhtml_basics
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
xhtml-documentation
xhtml-documentationxhtml-documentation
xhtml-documentation
 
CSS
CSSCSS
CSS
 
CSS
CSSCSS
CSS
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa0602690047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
0047ecaa6ea3e9ac0a13a2fe96f4de3bfd515c88f5d90c1fae79b956363d7f02c7fa060269
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
HowTo_CSS
HowTo_CSSHowTo_CSS
HowTo_CSS
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
BloggingWithStyle_2008
BloggingWithStyle_2008BloggingWithStyle_2008
BloggingWithStyle_2008
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 
cascadingstylesheets
cascadingstylesheetscascadingstylesheets
cascadingstylesheets
 

Dernier

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 

Dernier (20)

"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 

tutorial4x4

  • 1. Last lecture… On refactoring • We explained what is refactoring, what is software refactoring Tutorial 4 • How are they related to other restructuring More on Refactoring techniques? • Examples of refactoring How to refactoring unstructured code? • Refactoring structured source code into How to apply refactoring in Eclipse? goal models • … Spring 2005 ECE450H1S Software Engineering II Spring 2005 ECE450H1S Software Engineering II 1. Refactoring an Today… unstructured program 1. How to refactoring unstructured code into • The subject is called “Squirrel Mail” goal models? • It has 70 KLOC 2. How to use Eclipse to do refactoring? • Developed in PHP 3. Discussions Function call Foo.php: <?php include(“bar.php”) ?> 4. Relation to your course project • Why it is unstructured? Foo.php: <a href=“bar.php”/> <a href=“moo.php”/> <?php echo “I won super 7!” ?> Any idea? Spring 2005 ECE450H1S Software Engineering II Spring 2005 ECE450H1S Software Engineering II
  • 2. Why a PHP program is The process unstructured? • Every Hyperlink generated from the PHP • Structured program is easier to understand is an “exit” in the current PHP program /HJDF VRXUFH FRGH ([WUDFW 0HWKRGV 5HIDFWRUHG VRXUFH FRGH 5HIDFWRU • It may call other PHP routines, other web HV 1R RQVWUXFW pages, etc. when user click at them ,V VWUXFWXUHG +DPPRFN JUDSK • Non-deterministic, how could you tell ([WUDFW which link will the user click? $67 DQQRWDWHG 3DUVH 6WUXFWXUHG SURJUDP (OLPLQDWH *272 +LJKOHYHO 6WDWHFKDUW 6WDWHV 7UDQVLWLRQV 6WDWHFKDUWV *RDO JUDSK
  • 3. 5HIDFWRULQJ • Even “go back” button will change the 5HVWUXFWXUH behaviour of the program 7HVW WR $QDO]H 4XDOLW *RDO 0RGHO *RDO 0RGHO *RDO 0RGHO LGHQWLI PHWULFV WR LGHQWLI ZLWK • So … 1)5V ZLWK 1)5V VRIWJRDOV 6RIWJRDOV Spring 2005 ECE450H1S Software Engineering II Spring 2005 ECE450H1S Software Engineering II 1.1 Refactoring based on Example comments /** Path for SquirrelMail required files. */ define(‘SM_PATH’,’../’); HQW WKH IROORZLQJ GRHV 6 require_once($SM_PATH . ‘functions/strings.php’); U 6, 2
  • 4. UHIDFWRUHG require_once($SM_PATH . ‘config/config.php’); require_once($SM_PATH . ‘functions/i18n.php’); H[LW 6, 2
  • 6. require_once($SM_PATH . ‘functions/plugin.php’); require_once($SM_PATH . ‘functions/constants.php’); RWKHU … require_once($SM_PATH . ‘functions/page_header.php’); require_once($SM_PATH . ‘functions/html.php’); 9DULDEOHV GHILQHG EHIRUH WKH HQWU RI WKH EORFN require_once($SM_PATH . ‘functions/global.php’); , ,∪,
  • 7. ∩ ^ Y _ GHI Y S
  • 8. ∧ S ∠ S HQWU ` ≠ φ require_once($SM_PATH . ‘functions/imap_general.php’); 9DULDEOHV GHILQHG LQ WKH EORFN WKDW ZLOO EH XVHG DIWHU WKH H[LW 2 2∪2
  • 9. ∩^ Y _ XVH Y S
  • 10. ∧ S H[LW ∠ S ` ≠ φ $SM_PATH=set_path (); Spring 2005 ECE450H1S Software Engineering II Spring 2005 ECE450H1S Software Engineering II
  • 11. Further … 1.2 Convert into statechart ?php /* login.php */ • Statecharts concisely describe behaviour of a system. $SM_PATH=set_path (); $SM_lang=setup_language(); • No comments now, but we need to understand its $base_uri = findout_base_URI(); $logindisabled = detect_imap_server($base_uri); behaviour, therefore … if ($logindisabled) { explain_situation(); $SM_PATH is exit; undefined } do_hook(‘login_cookie’); $header =onload_function(“redirect.php”); /set_path display_header($header); $SM_PATH=set_path (); /set_path load_theme($theme[$theme_default]); do_hook('login_top'); show_logo(); show_form($loginname, $mailto, $key); $SM_PATH is $SM_PATH set do_hook('login_form'); do_hook('login_bottom'); ? Spring 2005 ECE450H1S Software Engineering II Spring 2005 ECE450H1S Software Engineering II 1.4 Put it together …the high-level statechart of the 1.3 Statechart refactoring unstructured program Extract Method - Extract States and Transitions based on Hammock graphs What’s new here? You are refactoring behaviour rather than structures! Spring 2005 ECE450H1S Software Engineering II Spring 2005 ECE450H1S Software Engineering II
  • 12. 1.4 Now convert statechart back 1.4 Eliminate GOTO’s into a program with GOTO’s • FORTRAN • FPT (Fortran parallelizing transformer, developed at ELIS, Ghent call EnterURL University, Belgium) 10 call Login • Result of goto elimination: if (wrongIMAP) goto 30 CALL EnterURL 20 call ShowForm REPEAT if (wrongKey) goto 20 REPEAT call EnterForm CALL Login IF (.not.wrongIMAP) THEN if (wrongForm) goto 30 REPEAT call StartWebMail CALL ShowForm if (loggedOut) goto 10 UNTIL (.not.wrongKey) if (expired) goto 10 CALL EnterForm IF(.not.wrongForm)THEN call Send CALL StartWebmail Stop ENDIF 30 call ReportError ENDIF call GoBack UNTIL (.not.loggedOut.or .not.expired.or.wrongIMAP .or.wrongForm) IF(wrongIMAP.or.wrongForm) goto 10 THEN end CALL ReportError • Rule of thumb: every state is a basic block; adding a label to states with CALL GoBack ENDIF multiple incoming transitions; adding GOTO statements for all outgoing UNTIL (.not.wrongIMAP.and.not.wrongForm) transitions except one; line-up the basic blocks CALL Send END Spring 2005 ECE450H1S Software Engineering II Spring 2005 ECE450H1S Software Engineering II 1.5 Turning structured program into 1.6 Turning it into “pure” goal an annotated goal model model (AND/OR graph) •call A … call B AND A B •if (x) then … call A if(x) OR if(!x) else A B call B end if … [topic] AND •call A A repeat until (s) B repeat … call C OR until s s C call B Spring 2005 ECE450H1S Software Engineering II Spring 2005 ECE450H1S Software Engineering II
  • 13. 1.7 Introducing softgoals 2. How to refactoring in Eclipse • Identify NFRs • If you are developing in Java, you are LUCKY! • Add softgoals to • The Eclipse IDE, JBuilder IDE are very categorize why comprehensive there are the • Refactoring was developed in Smalltalk, now NFRs moved to Java in Eclipse, it has been told in C# • If possible, one for Visual Studio, etc. can measure the • It should not be long to see open-source degree of programming languages to have them satisfaction for supported, such as PHP the softgoals • Examples, developed by Jing Su Spring 2005 ECE450H1S Software Engineering II Spring 2005 ECE450H1S Software Engineering II Example 1 – extract method void f() { void f() { ... ... // Compute score computeScore(); score = a * b + c; } score -= discount; } void computeScore() { score = a * b + c; score -= discount; } Spring 2005 ECE450H1S Software Engineering II Spring 2005 ECE450H1S Software Engineering II
  • 14. Enter a name according to the comment Spring 2005 ECE450H1S Software Engineering II Spring 2005 ECE450H1S Software Engineering II Example 2 – move method class Jar { class Jar { ... bool isFragile() { } switch(material) { class RoboPacker { case GLASS: return true; private bool isFragile(Jar foo) { case WOOD: return true; switch(foo.material) { case TIN: return false; case GLASS: return true; }}} case WOOD: return true; class RoboPacker { case TIN: return false; private bool isFragile(Jar foo) { } return foo.isFragile(); } } } } Spring 2005 ECE450H1S Software Engineering II Spring 2005 ECE450H1S Software Engineering II
  • 15. Spring 2005 ECE450H1S Software Engineering II Spring 2005 ECE450H1S Software Engineering II Example 3 – lift method class Jar { class Jar { bool isFragile() { bool isFragile() { switch(material) { return material.isFragile(); case GLASS: }} // complex glass calculation case WOOD: interface Material { ... } // complex wood calculation class GlassMaterial:Material { ... } case TIN: class WoodMaterial:Material { ... } // complex tin calculation class TinMaterial:Material { ... } }}} Spring 2005 ECE450H1S Software Engineering II Spring 2005 ECE450H1S Software Engineering II
  • 16. 3. Think about these … 4. Relation to your project 1. How to extend refactoring tool support to • Opportunities: – You may add junit test cases to the code base to other programming languages such as reveal bugs (publish it to the bug tracking system) PHP? and fix them (+5%) – You may apply design patterns, refactoring 2. Can you extend refactoring to techniques on this legacy code base, showing as an improved complexity metrics (+2.5%) documents, such as in various formats: – You may tune the performance of the system to diagrams, textual, xml, etc.? speed up the display, load/save for scalable graphs (+2.5%) 3. How can know a function is NFR? • Don’t forget your major project task (up to Can you measure the impact of a NFR 100%!) – To study the editor methods in the OpenOME and on a quality attribute? adapt them to the OmniGraphEditor web service. Spring 2005 ECE450H1S Software Engineering II Spring 2005 ECE450H1S Software Engineering II