<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Syi</id>
	<title>Expertiza_Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.expertiza.ncsu.edu/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Syi"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Syi"/>
	<updated>2026-06-06T22:39:23Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_15_SJ3&amp;diff=29049</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 15 SJ3</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_15_SJ3&amp;diff=29049"/>
		<updated>2009-11-19T00:54:32Z</updated>

		<summary type="html">&lt;p&gt;Syi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Programming by Assertion'''&lt;br /&gt;
&lt;br /&gt;
== Introduction to Assertions ==&lt;br /&gt;
&lt;br /&gt;
Assertions is statement used in code that indicates what a programmer assumes to be true at that point during execution.  They are used to help clarify program constraints and assumptions and ensure program correctness.  In general they can be thought of as way of testing.  Unlike test cases which apply external stimuli to objects and validate their state, assertions checks are used to check assumptions and constraints internally.&lt;br /&gt;
&lt;br /&gt;
Here is a basic assertion statement.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assert(expression);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The way the assertion statement behaves is based on the expression.  If the expression evaluates to true execution proceeds past the statement without notice.  If the expression evaluates false and exception is thrown causing the program to abort or execute an exception handler.  Typically if program is aborted the expression and line number are displayed to standard error as well.&lt;br /&gt;
&lt;br /&gt;
=== Design by Contract ===&lt;br /&gt;
Assertions are used in a facility called [http://en.wikipedia.org/wiki/Design_by_contract Design by Contract]. &lt;br /&gt;
Contracts are a breakthrough technique to reduce the programming effort for large projects. Contracts are the concept of [http://en.wikipedia.org/wiki/Precondition preconditions], [http://en.wikipedia.org/wiki/Postcondition postconditions], [http://en.wikipedia.org/wiki/Invariant_(computer_science) invariants], and general errors. These specifications of &amp;quot;contract&amp;quot; define the interface of different element of software includes method, class, module, etc.&lt;br /&gt;
&lt;br /&gt;
For detail information of contract, please refers to the helpful reading list in [2].&lt;br /&gt;
&lt;br /&gt;
==== Design by Contract Benefits ==== &lt;br /&gt;
* A better understanding of the object-oriented method and, more generally, of software construction.&lt;br /&gt;
* A systematic approach to building bug-free object-oriented systems.&lt;br /&gt;
* An effective framework for debugging, testing and, more generally, quality assurance.&lt;br /&gt;
* A method for documenting software components.&lt;br /&gt;
* Better understanding and control of the inheritance mechanism.&lt;br /&gt;
* A technique for dealing with abnormal cases, leading to a safe and effective language construct for exception handling.&lt;br /&gt;
&lt;br /&gt;
=== Precondition and Postcondition contract ===&lt;br /&gt;
The pre contracts specify the preconditions before a statement is executed. The most typical use of this would be in validating the parameters to a function. The post contracts validate the result of the statement. The most typical use of this would be in validating the return value of a function and of any side effects it has. The syntax is: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
long square_root(long x)&lt;br /&gt;
in&lt;br /&gt;
{&lt;br /&gt;
    assert(x &amp;gt;= 0);&lt;br /&gt;
}&lt;br /&gt;
out (result)&lt;br /&gt;
{&lt;br /&gt;
    assert((result * result) &amp;lt;= x &amp;amp;&amp;amp; (result+1) * (result+1) &amp;gt;= x);&lt;br /&gt;
}&lt;br /&gt;
body&lt;br /&gt;
{&lt;br /&gt;
    return cast(long)std.math.sqrt(cast(real)x);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Invariant contract ===&lt;br /&gt;
Here is simple example of invariant condition. Physically a size of a container should be 0 or positive.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
assert(size &amp;gt;= 0)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== General Assertion Error ===&lt;br /&gt;
Assertion will fail here if there is not any memory to allocate.&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
int* ptr = (int) malloc(sizeof(int));&lt;br /&gt;
assert(ptr != NULL);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== In, Out and Inheritance ===&lt;br /&gt;
If a function in a derived class overrides a function in its super class, then only one of the in contracts of the function and its base functions must be satisfied. Overriding functions then becomes a process of loosening the in  contracts. &lt;br /&gt;
&lt;br /&gt;
== Assertion Advantages ==&lt;br /&gt;
* Since they help clarifiy program constraints and assumptions they help with providing documentation.&lt;br /&gt;
* Provide runtime verification, which leads to continious and ongoing testing.&lt;br /&gt;
* Can perform Validations deep inside of a private method or in general a method not publicly visible.&lt;br /&gt;
* When used inside of classes they are encapuslated and hidden from the client. (helps client isolate problem to either client code or provide code)&lt;br /&gt;
&lt;br /&gt;
== Assertion Disadvantages ==&lt;br /&gt;
* If not turned off they can lead to serious performance implications (e.g. asserting a list is sorted)&lt;br /&gt;
* Not useful when validaton and output for a given input over a range of scenarios&lt;br /&gt;
* If assumptons are to restrictive assertions indicate bugs that are potentially false positives.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] wiki page of &amp;quot;Design by Contract&amp;quot;, http://en.wikipedia.org/wiki/Design_by_contract&lt;br /&gt;
&lt;br /&gt;
[2] reading list of contract, http://www.eecs.northwestern.edu/~robby/contract-reading-list/&lt;/div&gt;</summary>
		<author><name>Syi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=29043</id>
		<title>CSC/ECE 517 Fall 2009/wiki 3 1 SJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=29043"/>
		<updated>2009-11-19T00:51:39Z</updated>

		<summary type="html">&lt;p&gt;Syi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Syi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=28992</id>
		<title>CSC/ECE 517 Fall 2009/wiki 3 1 SJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=28992"/>
		<updated>2009-11-19T00:30:42Z</updated>

		<summary type="html">&lt;p&gt;Syi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Advantages and Disadvantages of Programming by Contract'''&lt;br /&gt;
&lt;br /&gt;
== Introduction of Contract Programming ==&lt;br /&gt;
&lt;br /&gt;
Contracts are a breakthrough technique to reduce the programming effort for large projects. Contracts are the concept of preconditions, postconditions, errors, and invariants. These specifications of &amp;quot;contract&amp;quot; define the interface of different element of software includes method, class, module and so on. In the following of introduction section, we provide some examples of different assertions.  &lt;br /&gt;
&lt;br /&gt;
===Assert contract===&lt;br /&gt;
The most basic contract is the assert. An assert inserts a checkable expression into the code, and that expression must evaluate to true: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 assert(expression);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
an assert  in function bodies works by throwing an AssertError, which can be caught and handled. Catching the contract violation is useful when the code must deal with errant uses by other code, when it must be failure proof, and as a useful tool for debugging.&lt;br /&gt;
&lt;br /&gt;
===Pre and Post contract ===&lt;br /&gt;
The pre contracts specify the preconditions before a statement is executed. The most typical use of this would be in validating the parameters to a function. The post contracts validate the result of the statement. The most typical use of this would be in validating the return value of a function and of any side effects it has. The syntax is: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  long square_root(long x)&lt;br /&gt;
    in&lt;br /&gt;
    {&lt;br /&gt;
	assert(x &amp;gt;= 0);&lt;br /&gt;
    }&lt;br /&gt;
    out (result)&lt;br /&gt;
    {&lt;br /&gt;
	assert((result * result) &amp;lt;= x &amp;amp;&amp;amp; (result+1) * (result+1) &amp;gt;= x);&lt;br /&gt;
    }&lt;br /&gt;
    body&lt;br /&gt;
    {&lt;br /&gt;
	return cast(long)std.math.sqrt(cast(real)x);&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===In, Out and Inheritance ===&lt;br /&gt;
If a function in a derived class overrides a function in its super class, then only one of the in contracts of the function and its base functions must be satisfied. Overriding functions then becomes a process of loosening the in  contracts. &lt;br /&gt;
&lt;br /&gt;
===Class Invariants ===&lt;br /&gt;
Class invariants are used to specify characteristics of a class that always must be true (except while executing a member function). They are described in Classes. &lt;br /&gt;
&lt;br /&gt;
for detail information of contract, please refers to the helpful reading list in [2].&lt;br /&gt;
&lt;br /&gt;
==The advantages of Contract Programming==&lt;br /&gt;
&lt;br /&gt;
* A better understanding of the object-oriented method and, more generally, of software construction.&lt;br /&gt;
* A systematic approach to building bug-free object-oriented systems.&lt;br /&gt;
* An effective framework for debugging, testing and, more generally, quality assurance.&lt;br /&gt;
* A method for documenting software components.&lt;br /&gt;
* Better understanding and control of the inheritance mechanism.&lt;br /&gt;
* A technique for dealing with abnormal cases, leading to a safe and effective language construct for exception handling.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== The disadvantages of Contract Programming ==&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] wiki page of &amp;quot;Design by Contract&amp;quot;, http://en.wikipedia.org/wiki/Design_by_contract&lt;br /&gt;
&lt;br /&gt;
[2] reading list of contract, http://www.eecs.northwestern.edu/~robby/contract-reading-list/&lt;/div&gt;</summary>
		<author><name>Syi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=28940</id>
		<title>CSC/ECE 517 Fall 2009/wiki 3 1 SJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=28940"/>
		<updated>2009-11-19T00:19:12Z</updated>

		<summary type="html">&lt;p&gt;Syi: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Advantages and Disadvantages of Programming by Contract'''&lt;br /&gt;
&lt;br /&gt;
== Introduction of Contract Programming ==&lt;br /&gt;
&lt;br /&gt;
Contracts are a breakthrough technique to reduce the programming effort for large projects. Contracts are the concept of preconditions, postconditions, errors, and invariants. These specifications of &amp;quot;contract&amp;quot; define the interface of different element of software includes method, class, module and so on. In the following of introduction section, we provide some examples of different assertions.  &lt;br /&gt;
&lt;br /&gt;
===Assert contract===&lt;br /&gt;
The most basic contract is the assert. An assert inserts a checkable expression into the code, and that expression must evaluate to true: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 assert(expression);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
an assert  in function bodies works by throwing an AssertError, which can be caught and handled. Catching the contract violation is useful when the code must deal with errant uses by other code, when it must be failure proof, and as a useful tool for debugging.&lt;br /&gt;
&lt;br /&gt;
===Pre and Post contract ===&lt;br /&gt;
The pre contracts specify the preconditions before a statement is executed. The most typical use of this would be in validating the parameters to a function. The post contracts validate the result of the statement. The most typical use of this would be in validating the return value of a function and of any side effects it has. The syntax is: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  long square_root(long x)&lt;br /&gt;
    in&lt;br /&gt;
    {&lt;br /&gt;
	assert(x &amp;gt;= 0);&lt;br /&gt;
    }&lt;br /&gt;
    out (result)&lt;br /&gt;
    {&lt;br /&gt;
	assert((result * result) &amp;lt;= x &amp;amp;&amp;amp; (result+1) * (result+1) &amp;gt;= x);&lt;br /&gt;
    }&lt;br /&gt;
    body&lt;br /&gt;
    {&lt;br /&gt;
	return cast(long)std.math.sqrt(cast(real)x);&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===In, Out and Inheritance ===&lt;br /&gt;
If a function in a derived class overrides a function in its super class, then only one of the in contracts of the function and its base functions must be satisfied. Overriding functions then becomes a process of loosening the in  contracts. &lt;br /&gt;
&lt;br /&gt;
===Class Invariants ===&lt;br /&gt;
Class invariants are used to specify characteristics of a class that always must be true (except while executing a member function). They are described in Classes. &lt;br /&gt;
&lt;br /&gt;
for detail information of contract, please refers to the helpful reading list in [2].&lt;br /&gt;
&lt;br /&gt;
==The advantages of Contract Programming==&lt;br /&gt;
&lt;br /&gt;
* A better understanding of the object-oriented method and, more generally, of software construction.&lt;br /&gt;
* A systematic approach to building bug-free object-oriented systems.&lt;br /&gt;
* An effective framework for debugging, testing and, more generally, quality assurance.&lt;br /&gt;
* A method for documenting software components.&lt;br /&gt;
* Better understanding and control of the inheritance mechanism.&lt;br /&gt;
* A technique for dealing with abnormal cases, leading to a safe and effective language construct for exception handling.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== The disadvantages of Contract Programming ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] wiki page of &amp;quot;Design by Contract&amp;quot;, http://en.wikipedia.org/wiki/Design_by_contract&lt;br /&gt;
&lt;br /&gt;
[2] reading list of contract, http://www.eecs.northwestern.edu/~robby/contract-reading-list/&lt;/div&gt;</summary>
		<author><name>Syi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=28938</id>
		<title>CSC/ECE 517 Fall 2009/wiki 3 1 SJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=28938"/>
		<updated>2009-11-19T00:18:53Z</updated>

		<summary type="html">&lt;p&gt;Syi: /* Introduction of Contract Programming */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Advantages and Disadvantages of Programming by Contract'''&lt;br /&gt;
&lt;br /&gt;
== Introduction of Contract Programming ==&lt;br /&gt;
&lt;br /&gt;
Contracts are a breakthrough technique to reduce the programming effort for large projects. Contracts are the concept of preconditions, postconditions, errors, and invariants. These specifications of &amp;quot;contract&amp;quot; define the interface of different element of software includes method, class, module and so on. In the following of introduction section, we provide some examples of different assertions.  &lt;br /&gt;
&lt;br /&gt;
===Assert contract===&lt;br /&gt;
The most basic contract is the assert. An assert inserts a checkable expression into the code, and that expression must evaluate to true: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 assert(expression);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
an assert  in function bodies works by throwing an AssertError, which can be caught and handled. Catching the contract violation is useful when the code must deal with errant uses by other code, when it must be failure proof, and as a useful tool for debugging.&lt;br /&gt;
&lt;br /&gt;
===Pre and Post contract ===&lt;br /&gt;
The pre contracts specify the preconditions before a statement is executed. The most typical use of this would be in validating the parameters to a function. The post contracts validate the result of the statement. The most typical use of this would be in validating the return value of a function and of any side effects it has. The syntax is: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  long square_root(long x)&lt;br /&gt;
    in&lt;br /&gt;
    {&lt;br /&gt;
	assert(x &amp;gt;= 0);&lt;br /&gt;
    }&lt;br /&gt;
    out (result)&lt;br /&gt;
    {&lt;br /&gt;
	assert((result * result) &amp;lt;= x &amp;amp;&amp;amp; (result+1) * (result+1) &amp;gt;= x);&lt;br /&gt;
    }&lt;br /&gt;
    body&lt;br /&gt;
    {&lt;br /&gt;
	return cast(long)std.math.sqrt(cast(real)x);&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===In, Out and Inheritance ===&lt;br /&gt;
If a function in a derived class overrides a function in its super class, then only one of the in contracts of the function and its base functions must be satisfied. Overriding functions then becomes a process of loosening the in  contracts. &lt;br /&gt;
&lt;br /&gt;
===Class Invariants ===&lt;br /&gt;
Class invariants are used to specify characteristics of a class that always must be true (except while executing a member function). They are described in Classes. &lt;br /&gt;
&lt;br /&gt;
for detail information of contract, please refers to the helpful reading list in [2].&lt;br /&gt;
&lt;br /&gt;
==The advantages of Contract Programming==&lt;br /&gt;
&lt;br /&gt;
* A better understanding of the object-oriented method and, more generally, of software construction.&lt;br /&gt;
* A systematic approach to building bug-free object-oriented systems.&lt;br /&gt;
* An effective framework for debugging, testing and, more generally, quality assurance.&lt;br /&gt;
* A method for documenting software components.&lt;br /&gt;
* Better understanding and control of the inheritance mechanism.&lt;br /&gt;
* A technique for dealing with abnormal cases, leading to a safe and effective language construct for exception handling.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== The disadvantages of Contract Programming ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] wiki page of &amp;quot;Design by Contract&amp;quot;, http://en.wikipedia.org/wiki/Design_by_contract&lt;br /&gt;
[2] reading list of contract, http://www.eecs.northwestern.edu/~robby/contract-reading-list/&lt;/div&gt;</summary>
		<author><name>Syi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=28782</id>
		<title>CSC/ECE 517 Fall 2009/wiki 3 1 SJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=28782"/>
		<updated>2009-11-18T22:19:52Z</updated>

		<summary type="html">&lt;p&gt;Syi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Advantages and Disadvantages of Programming by Contract'''&lt;br /&gt;
&lt;br /&gt;
== Introduction of Contract Programming ==&lt;br /&gt;
&lt;br /&gt;
Contracts are a breakthrough technique to reduce the programming effort for large projects. Contracts are the concept of preconditions, postconditions, errors, and invariants. These specifications of &amp;quot;contract&amp;quot; define the interface of different element of software includes method, class, module... &lt;br /&gt;
&lt;br /&gt;
===Assert contract===&lt;br /&gt;
The most basic contract is the assert. An assert inserts a checkable expression into the code, and that expression must evaluate to true: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 assert(expression);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
an assert  in function bodies works by throwing an AssertError, which can be caught and handled. Catching the contract violation is useful when the code must deal with errant uses by other code, when it must be failure proof, and as a useful tool for debugging.&lt;br /&gt;
&lt;br /&gt;
===Pre and Post contract ===&lt;br /&gt;
The pre contracts specify the preconditions before a statement is executed. The most typical use of this would be in validating the parameters to a function. The post contracts validate the result of the statement. The most typical use of this would be in validating the return value of a function and of any side effects it has. The syntax is: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  long square_root(long x)&lt;br /&gt;
    in&lt;br /&gt;
    {&lt;br /&gt;
	assert(x &amp;gt;= 0);&lt;br /&gt;
    }&lt;br /&gt;
    out (result)&lt;br /&gt;
    {&lt;br /&gt;
	assert((result * result) &amp;lt;= x &amp;amp;&amp;amp; (result+1) * (result+1) &amp;gt;= x);&lt;br /&gt;
    }&lt;br /&gt;
    body&lt;br /&gt;
    {&lt;br /&gt;
	return cast(long)std.math.sqrt(cast(real)x);&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===In, Out and Inheritance ===&lt;br /&gt;
If a function in a derived class overrides a function in its super class, then only one of the in contracts of the function and its base functions must be satisfied. Overriding functions then becomes a process of loosening the in  contracts. &lt;br /&gt;
&lt;br /&gt;
===Class Invariants ===&lt;br /&gt;
Class invariants are used to specify characteristics of a class that always must be true (except while executing a member function). They are described in Classes. &lt;br /&gt;
&lt;br /&gt;
for detail information of contract, please refers to the helpful reading list in [2].&lt;br /&gt;
&lt;br /&gt;
==The advantages of Contract Programming==&lt;br /&gt;
&lt;br /&gt;
* A better understanding of the object-oriented method and, more generally, of software construction.&lt;br /&gt;
* A systematic approach to building bug-free object-oriented systems.&lt;br /&gt;
* An effective framework for debugging, testing and, more generally, quality assurance.&lt;br /&gt;
* A method for documenting software components.&lt;br /&gt;
* Better understanding and control of the inheritance mechanism.&lt;br /&gt;
* A technique for dealing with abnormal cases, leading to a safe and effective language construct for exception handling.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== The disadvantages of Contract Programming ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] wiki page of &amp;quot;Design by Contract&amp;quot;, http://en.wikipedia.org/wiki/Design_by_contract&lt;br /&gt;
[2] reading list of contract, http://www.eecs.northwestern.edu/~robby/contract-reading-list/&lt;/div&gt;</summary>
		<author><name>Syi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=28779</id>
		<title>CSC/ECE 517 Fall 2009/wiki 3 1 SJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=28779"/>
		<updated>2009-11-18T22:19:24Z</updated>

		<summary type="html">&lt;p&gt;Syi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Advantages and Disadvantages of Programming by Contract'''&lt;br /&gt;
&lt;br /&gt;
== 1. Introduction of Contract Programming ==&lt;br /&gt;
&lt;br /&gt;
Contracts are a breakthrough technique to reduce the programming effort for large projects. Contracts are the concept of preconditions, postconditions, errors, and invariants. These specifications of &amp;quot;contract&amp;quot; define the interface of different element of software includes method, class, module... &lt;br /&gt;
&lt;br /&gt;
===1.1 Assert contract===&lt;br /&gt;
The most basic contract is the assert. An assert inserts a checkable expression into the code, and that expression must evaluate to true: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 assert(expression);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
an assert  in function bodies works by throwing an AssertError, which can be caught and handled. Catching the contract violation is useful when the code must deal with errant uses by other code, when it must be failure proof, and as a useful tool for debugging.&lt;br /&gt;
&lt;br /&gt;
===1.2 Pre and Post contract ===&lt;br /&gt;
The pre contracts specify the preconditions before a statement is executed. The most typical use of this would be in validating the parameters to a function. The post contracts validate the result of the statement. The most typical use of this would be in validating the return value of a function and of any side effects it has. The syntax is: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  long square_root(long x)&lt;br /&gt;
    in&lt;br /&gt;
    {&lt;br /&gt;
	assert(x &amp;gt;= 0);&lt;br /&gt;
    }&lt;br /&gt;
    out (result)&lt;br /&gt;
    {&lt;br /&gt;
	assert((result * result) &amp;lt;= x &amp;amp;&amp;amp; (result+1) * (result+1) &amp;gt;= x);&lt;br /&gt;
    }&lt;br /&gt;
    body&lt;br /&gt;
    {&lt;br /&gt;
	return cast(long)std.math.sqrt(cast(real)x);&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===1.3 In, Out and Inheritance ===&lt;br /&gt;
If a function in a derived class overrides a function in its super class, then only one of the in contracts of the function and its base functions must be satisfied. Overriding functions then becomes a process of loosening the in  contracts. &lt;br /&gt;
&lt;br /&gt;
=== 1.4 Class Invariants ===&lt;br /&gt;
Class invariants are used to specify characteristics of a class that always must be true (except while executing a member function). They are described in Classes. &lt;br /&gt;
&lt;br /&gt;
for detail information of contract, please refers to the helpful reading list in [2].&lt;br /&gt;
&lt;br /&gt;
==The advantages of Contract Programming==&lt;br /&gt;
&lt;br /&gt;
* A better understanding of the object-oriented method and, more generally, of software construction.&lt;br /&gt;
* A systematic approach to building bug-free object-oriented systems.&lt;br /&gt;
* An effective framework for debugging, testing and, more generally, quality assurance.&lt;br /&gt;
* A method for documenting software components.&lt;br /&gt;
* Better understanding and control of the inheritance mechanism.&lt;br /&gt;
* A technique for dealing with abnormal cases, leading to a safe and effective language construct for exception handling.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== The disadvantages of Contract Programming ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] wiki page of &amp;quot;Design by Contract&amp;quot;, http://en.wikipedia.org/wiki/Design_by_contract&lt;br /&gt;
[2] reading list of contract, http://www.eecs.northwestern.edu/~robby/contract-reading-list/&lt;/div&gt;</summary>
		<author><name>Syi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=28778</id>
		<title>CSC/ECE 517 Fall 2009/wiki 3 1 SJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=28778"/>
		<updated>2009-11-18T22:19:01Z</updated>

		<summary type="html">&lt;p&gt;Syi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Advantages and Disadvantages of Programming by Contract'''&lt;br /&gt;
&lt;br /&gt;
== 1. Introduction of Contract Programming ==&lt;br /&gt;
&lt;br /&gt;
Contracts are a breakthrough technique to reduce the programming effort for large projects. Contracts are the concept of preconditions, postconditions, errors, and invariants. These specifications of &amp;quot;contract&amp;quot; define the interface of different element of software includes method, class, module... &lt;br /&gt;
&lt;br /&gt;
===1.1 Assert contract===&lt;br /&gt;
The most basic contract is the assert. An assert inserts a checkable expression into the code, and that expression must evaluate to true: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 assert(expression);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
an assert  in function bodies works by throwing an AssertError, which can be caught and handled. Catching the contract violation is useful when the code must deal with errant uses by other code, when it must be failure proof, and as a useful tool for debugging.&lt;br /&gt;
&lt;br /&gt;
===1.2 Pre and Post contract ===&lt;br /&gt;
The pre contracts specify the preconditions before a statement is executed. The most typical use of this would be in validating the parameters to a function. The post contracts validate the result of the statement. The most typical use of this would be in validating the return value of a function and of any side effects it has. The syntax is: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  long square_root(long x)&lt;br /&gt;
    in&lt;br /&gt;
    {&lt;br /&gt;
	assert(x &amp;gt;= 0);&lt;br /&gt;
    }&lt;br /&gt;
    out (result)&lt;br /&gt;
    {&lt;br /&gt;
	assert((result * result) &amp;lt;= x &amp;amp;&amp;amp; (result+1) * (result+1) &amp;gt;= x);&lt;br /&gt;
    }&lt;br /&gt;
    body&lt;br /&gt;
    {&lt;br /&gt;
	return cast(long)std.math.sqrt(cast(real)x);&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===1.3 In, Out and Inheritance ===&lt;br /&gt;
If a function in a derived class overrides a function in its super class, then only one of the in contracts of the function and its base functions must be satisfied. Overriding functions then becomes a process of loosening the in  contracts. &lt;br /&gt;
&lt;br /&gt;
=== 1.4 Class Invariants ===&lt;br /&gt;
Class invariants are used to specify characteristics of a class that always must be true (except while executing a member function). They are described in Classes. &lt;br /&gt;
&lt;br /&gt;
for detail information of contract, please refers to the helpful reading list in [2].&lt;br /&gt;
&lt;br /&gt;
==The advantages of Contract Programming==&lt;br /&gt;
&lt;br /&gt;
* A better understanding of the object-oriented method and, more generally, of software construction.&lt;br /&gt;
* A systematic approach to building bug-free object-oriented systems.&lt;br /&gt;
* An effective framework for debugging, testing and, more generally, quality assurance.&lt;br /&gt;
* A method for documenting software components.&lt;br /&gt;
* Better understanding and control of the inheritance mechanism.&lt;br /&gt;
* A technique for dealing with abnormal cases, leading to a safe and effective language construct for exception handling.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== The disadvantages of Contract Programming ===&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] wiki page of &amp;quot;Design by Contract&amp;quot;, http://en.wikipedia.org/wiki/Design_by_contract&lt;br /&gt;
&lt;br /&gt;
[2] reading list of contract, http://www.eecs.northwestern.edu/~robby/contract-reading-list/&lt;br /&gt;
[3] Refactoring conditional statement, http://sourcemaking.com/refactoring/replace-conditional-with-polymorphism&lt;br /&gt;
&lt;br /&gt;
[4] Object Orientation Design, http://en.wikipedia.org/wiki/Object-oriented_design&lt;/div&gt;</summary>
		<author><name>Syi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=28774</id>
		<title>CSC/ECE 517 Fall 2009/wiki 3 1 SJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=28774"/>
		<updated>2009-11-18T22:17:47Z</updated>

		<summary type="html">&lt;p&gt;Syi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Advantages and Disadvantages of Programming by Contract'''&lt;br /&gt;
&lt;br /&gt;
== Introduction of Contract Programming ==&lt;br /&gt;
&lt;br /&gt;
Contracts are a breakthrough technique to reduce the programming effort for large projects. Contracts are the concept of preconditions, postconditions, errors, and invariants. These specifications of &amp;quot;contract&amp;quot; define the interface of different element of software includes method, class, module... &lt;br /&gt;
&lt;br /&gt;
===Assert contract===&lt;br /&gt;
The most basic contract is the assert. An assert inserts a checkable expression into the code, and that expression must evaluate to true: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
 assert(expression);&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
an assert  in function bodies works by throwing an AssertError, which can be caught and handled. Catching the contract violation is useful when the code must deal with errant uses by other code, when it must be failure proof, and as a useful tool for debugging.&lt;br /&gt;
&lt;br /&gt;
===Pre and Post contract ===&lt;br /&gt;
The pre contracts specify the preconditions before a statement is executed. The most typical use of this would be in validating the parameters to a function. The post contracts validate the result of the statement. The most typical use of this would be in validating the return value of a function and of any side effects it has. The syntax is: &lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
  long square_root(long x)&lt;br /&gt;
    in&lt;br /&gt;
    {&lt;br /&gt;
	assert(x &amp;gt;= 0);&lt;br /&gt;
    }&lt;br /&gt;
    out (result)&lt;br /&gt;
    {&lt;br /&gt;
	assert((result * result) &amp;lt;= x &amp;amp;&amp;amp; (result+1) * (result+1) &amp;gt;= x);&lt;br /&gt;
    }&lt;br /&gt;
    body&lt;br /&gt;
    {&lt;br /&gt;
	return cast(long)std.math.sqrt(cast(real)x);&lt;br /&gt;
    }&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
===In, Out and Inheritance ===&lt;br /&gt;
If a function in a derived class overrides a function in its super class, then only one of the in contracts of the function and its base functions must be satisfied. Overriding functions then becomes a process of loosening the in  contracts. &lt;br /&gt;
&lt;br /&gt;
=== Class Invariants ===&lt;br /&gt;
Class invariants are used to specify characteristics of a class that always must be true (except while executing a member function). They are described in Classes. &lt;br /&gt;
&lt;br /&gt;
for detail information of contract, please refers to the helpful reading list in [2].&lt;br /&gt;
&lt;br /&gt;
==The advantages of Contract Programming==&lt;br /&gt;
&lt;br /&gt;
* A better understanding of the object-oriented method and, more generally, of software construction.&lt;br /&gt;
* A systematic approach to building bug-free object-oriented systems.&lt;br /&gt;
* An effective framework for debugging, testing and, more generally, quality assurance.&lt;br /&gt;
* A method for documenting software components.&lt;br /&gt;
* Better understanding and control of the inheritance mechanism.&lt;br /&gt;
* A technique for dealing with abnormal cases, leading to a safe and effective language construct for exception handling.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Example of If statement ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Operator&lt;br /&gt;
{&lt;br /&gt;
    string operation;&lt;br /&gt;
&lt;br /&gt;
    public int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
         switch(operation)&lt;br /&gt;
         {&lt;br /&gt;
             case &amp;quot;Add&amp;quot;:&lt;br /&gt;
                 return x + y;&lt;br /&gt;
             case &amp;quot;Subtract&amp;quot;:&lt;br /&gt;
                 return x - y;&lt;br /&gt;
             case &amp;quot;Multiply&amp;quot;:&lt;br /&gt;
                 return x * y;&lt;br /&gt;
             case &amp;quot;Divide&amp;quot;:&lt;br /&gt;
                 return x / y;&lt;br /&gt;
             default:&lt;br /&gt;
                 throw new InvalidOperationException(&amp;quot;Unsupported operation&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In such example of conditional statement on operator, we see that: if we want to reuse function &amp;quot;add&amp;quot; operator in the other code segment, we have to reuse whole Class operator with the value &amp;quot;Add&amp;quot;. And if we want to add a new operation &amp;quot;Power&amp;quot;, we need to code in the implementation of Class Operator.&lt;br /&gt;
&lt;br /&gt;
== Idea of Polymorphism ==&lt;br /&gt;
Facing the problem of the conditional statement, people[2] come up with refactoring method called 'Polymorphism'. The idea of Polymorphism is to replace the highly functional relationship with the subclass override procedure under abstract class. So subclass is created to encapsulate each function in the conditional statement and the conditional relation is replaced by override a common abstract class. The advantage of such idea is to separate the functionality.    &lt;br /&gt;
&lt;br /&gt;
=== Definition of Polymorphism ===&lt;br /&gt;
According to [1], Subtype polymorphism, almost universally called just polymorphism in the context of object-oriented programming, is the ability of one type, A, to appear as and be used like another type, B. &lt;br /&gt;
&lt;br /&gt;
The primary usage of polymorphism in industry (object-oriented programming theory) is the ability of objects belonging to different types to respond to method, field, or property calls of the same name, each one according to an appropriate type-specific behavior. The programmer (and the program) does not have to know the exact type of the object in advance, and so the exact behavior is determined at run time.&lt;br /&gt;
&lt;br /&gt;
== Example of Refactoring Conditional Statement with Polymorphism ==&lt;br /&gt;
*Before refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Operator&lt;br /&gt;
{&lt;br /&gt;
    string operation;&lt;br /&gt;
&lt;br /&gt;
    public int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
         switch(operation)&lt;br /&gt;
         {&lt;br /&gt;
             case &amp;quot;Add&amp;quot;:&lt;br /&gt;
                 return x + y;&lt;br /&gt;
             case &amp;quot;Subtract&amp;quot;:&lt;br /&gt;
                 return x - y;&lt;br /&gt;
             case &amp;quot;Multiply&amp;quot;:&lt;br /&gt;
                 return x * y;&lt;br /&gt;
             case &amp;quot;Divide&amp;quot;:&lt;br /&gt;
                 return x / y;&lt;br /&gt;
             default:&lt;br /&gt;
                 throw new InvalidOperationException(&amp;quot;Unsupported operation&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*After refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public abstract class Operator&lt;br /&gt;
{&lt;br /&gt;
    public abstract int Execute(int x, int y)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class Add : Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x + y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Subtract : Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x - y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Multiply: Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x * y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Divide: Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x / y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] wiki page of &amp;quot;Design by Contract&amp;quot;, http://en.wikipedia.org/wiki/Design_by_contract&lt;br /&gt;
&lt;br /&gt;
[2] reading list of contract, http://www.eecs.northwestern.edu/~robby/contract-reading-list/&lt;br /&gt;
[3] Refactoring conditional statement, http://sourcemaking.com/refactoring/replace-conditional-with-polymorphism&lt;br /&gt;
&lt;br /&gt;
[4] Object Orientation Design, http://en.wikipedia.org/wiki/Object-oriented_design&lt;/div&gt;</summary>
		<author><name>Syi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=28771</id>
		<title>CSC/ECE 517 Fall 2009/wiki 3 1 SJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=28771"/>
		<updated>2009-11-18T22:14:05Z</updated>

		<summary type="html">&lt;p&gt;Syi: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Advantages and Disadvantages of Programming by Contract'''&lt;br /&gt;
&lt;br /&gt;
== Introduction of Contract Programming ==&lt;br /&gt;
&lt;br /&gt;
Contracts are a breakthrough technique to reduce the programming effort for large projects. Contracts are the concept of preconditions, postconditions, errors, and invariants. These specifications of &amp;quot;contract&amp;quot; define the interface of different element of software includes method, class, module... &lt;br /&gt;
&lt;br /&gt;
===Assert contract===&lt;br /&gt;
The most basic contract is the assert. An assert inserts a checkable expression into the code, and that expression must evaluate to true: &lt;br /&gt;
 assert(expression);&lt;br /&gt;
an assert  in function bodies works by throwing an AssertError, which can be caught and handled. Catching the contract violation is useful when the code must deal with errant uses by other code, when it must be failure proof, and as a useful tool for debugging.&lt;br /&gt;
&lt;br /&gt;
===Pre and Post contract ===&lt;br /&gt;
The pre contracts specify the preconditions before a statement is executed. The most typical use of this would be in validating the parameters to a function. The post contracts validate the result of the statement. The most typical use of this would be in validating the return value of a function and of any side effects it has. The syntax is: &lt;br /&gt;
 long square_root(long x)&lt;br /&gt;
    in&lt;br /&gt;
    {&lt;br /&gt;
	assert(x &amp;gt;= 0);&lt;br /&gt;
    }&lt;br /&gt;
    out (result)&lt;br /&gt;
    {&lt;br /&gt;
	assert((result * result) &amp;lt;= x &amp;amp;&amp;amp; (result+1) * (result+1) &amp;gt;= x);&lt;br /&gt;
    }&lt;br /&gt;
    body&lt;br /&gt;
    {&lt;br /&gt;
	return cast(long)std.math.sqrt(cast(real)x);&lt;br /&gt;
    }&lt;br /&gt;
===In, Out and Inheritance ===&lt;br /&gt;
If a function in a derived class overrides a function in its super class, then only one of the in contracts of the function and its base functions must be satisfied. Overriding functions then becomes a process of loosening the in  contracts. &lt;br /&gt;
&lt;br /&gt;
=== Class Invariants ===&lt;br /&gt;
Class invariants are used to specify characteristics of a class that always must be true (except while executing a member function). They are described in Classes. &lt;br /&gt;
&lt;br /&gt;
for detail information of contract, please refers to the helpful reading list in [2].&lt;br /&gt;
&lt;br /&gt;
==The advantages of Contract Programming==&lt;br /&gt;
&lt;br /&gt;
* A better understanding of the object-oriented method and, more generally, of software construction.&lt;br /&gt;
* A systematic approach to building bug-free object-oriented systems.&lt;br /&gt;
* An effective framework for debugging, testing and, more generally, quality assurance.&lt;br /&gt;
* A method for documenting software components.&lt;br /&gt;
* Better understanding and control of the inheritance mechanism.&lt;br /&gt;
* A technique for dealing with abnormal cases, leading to a safe and effective language construct for exception handling.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Example of If statement ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Operator&lt;br /&gt;
{&lt;br /&gt;
    string operation;&lt;br /&gt;
&lt;br /&gt;
    public int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
         switch(operation)&lt;br /&gt;
         {&lt;br /&gt;
             case &amp;quot;Add&amp;quot;:&lt;br /&gt;
                 return x + y;&lt;br /&gt;
             case &amp;quot;Subtract&amp;quot;:&lt;br /&gt;
                 return x - y;&lt;br /&gt;
             case &amp;quot;Multiply&amp;quot;:&lt;br /&gt;
                 return x * y;&lt;br /&gt;
             case &amp;quot;Divide&amp;quot;:&lt;br /&gt;
                 return x / y;&lt;br /&gt;
             default:&lt;br /&gt;
                 throw new InvalidOperationException(&amp;quot;Unsupported operation&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In such example of conditional statement on operator, we see that: if we want to reuse function &amp;quot;add&amp;quot; operator in the other code segment, we have to reuse whole Class operator with the value &amp;quot;Add&amp;quot;. And if we want to add a new operation &amp;quot;Power&amp;quot;, we need to code in the implementation of Class Operator.&lt;br /&gt;
&lt;br /&gt;
== Idea of Polymorphism ==&lt;br /&gt;
Facing the problem of the conditional statement, people[2] come up with refactoring method called 'Polymorphism'. The idea of Polymorphism is to replace the highly functional relationship with the subclass override procedure under abstract class. So subclass is created to encapsulate each function in the conditional statement and the conditional relation is replaced by override a common abstract class. The advantage of such idea is to separate the functionality.    &lt;br /&gt;
&lt;br /&gt;
=== Definition of Polymorphism ===&lt;br /&gt;
According to [1], Subtype polymorphism, almost universally called just polymorphism in the context of object-oriented programming, is the ability of one type, A, to appear as and be used like another type, B. &lt;br /&gt;
&lt;br /&gt;
The primary usage of polymorphism in industry (object-oriented programming theory) is the ability of objects belonging to different types to respond to method, field, or property calls of the same name, each one according to an appropriate type-specific behavior. The programmer (and the program) does not have to know the exact type of the object in advance, and so the exact behavior is determined at run time.&lt;br /&gt;
&lt;br /&gt;
== Example of Refactoring Conditional Statement with Polymorphism ==&lt;br /&gt;
*Before refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Operator&lt;br /&gt;
{&lt;br /&gt;
    string operation;&lt;br /&gt;
&lt;br /&gt;
    public int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
         switch(operation)&lt;br /&gt;
         {&lt;br /&gt;
             case &amp;quot;Add&amp;quot;:&lt;br /&gt;
                 return x + y;&lt;br /&gt;
             case &amp;quot;Subtract&amp;quot;:&lt;br /&gt;
                 return x - y;&lt;br /&gt;
             case &amp;quot;Multiply&amp;quot;:&lt;br /&gt;
                 return x * y;&lt;br /&gt;
             case &amp;quot;Divide&amp;quot;:&lt;br /&gt;
                 return x / y;&lt;br /&gt;
             default:&lt;br /&gt;
                 throw new InvalidOperationException(&amp;quot;Unsupported operation&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*After refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public abstract class Operator&lt;br /&gt;
{&lt;br /&gt;
    public abstract int Execute(int x, int y)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class Add : Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x + y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Subtract : Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x - y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Multiply: Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x * y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Divide: Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x / y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] wiki page of &amp;quot;Design by Contract&amp;quot;, http://en.wikipedia.org/wiki/Design_by_contract&lt;br /&gt;
&lt;br /&gt;
[2] reading list of contract, http://www.eecs.northwestern.edu/~robby/contract-reading-list/&lt;br /&gt;
[3] Refactoring conditional statement, http://sourcemaking.com/refactoring/replace-conditional-with-polymorphism&lt;br /&gt;
&lt;br /&gt;
[4] Object Orientation Design, http://en.wikipedia.org/wiki/Object-oriented_design&lt;/div&gt;</summary>
		<author><name>Syi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=28770</id>
		<title>CSC/ECE 517 Fall 2009/wiki 3 1 SJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=28770"/>
		<updated>2009-11-18T22:13:39Z</updated>

		<summary type="html">&lt;p&gt;Syi: /* Introduction of Contract Programming */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Advantages and Disadvantages of Programming by Contract'''&lt;br /&gt;
&lt;br /&gt;
== Introduction of Contract Programming ==&lt;br /&gt;
&lt;br /&gt;
Contracts are a breakthrough technique to reduce the programming effort for large projects. Contracts are the concept of preconditions, postconditions, errors, and invariants. These specifications of &amp;quot;contract&amp;quot; define the interface of different element of software includes method, class, module... &lt;br /&gt;
&lt;br /&gt;
===Assert contract===&lt;br /&gt;
The most basic contract is the assert. An assert inserts a checkable expression into the code, and that expression must evaluate to true: &lt;br /&gt;
 assert(expression);&lt;br /&gt;
an assert  in function bodies works by throwing an AssertError, which can be caught and handled. Catching the contract violation is useful when the code must deal with errant uses by other code, when it must be failure proof, and as a useful tool for debugging.&lt;br /&gt;
&lt;br /&gt;
===Pre and Post contract ===&lt;br /&gt;
The pre contracts specify the preconditions before a statement is executed. The most typical use of this would be in validating the parameters to a function. The post contracts validate the result of the statement. The most typical use of this would be in validating the return value of a function and of any side effects it has. The syntax is: &lt;br /&gt;
 long square_root(long x)&lt;br /&gt;
    in&lt;br /&gt;
    {&lt;br /&gt;
	assert(x &amp;gt;= 0);&lt;br /&gt;
    }&lt;br /&gt;
    out (result)&lt;br /&gt;
    {&lt;br /&gt;
	assert((result * result) &amp;lt;= x &amp;amp;&amp;amp; (result+1) * (result+1) &amp;gt;= x);&lt;br /&gt;
    }&lt;br /&gt;
    body&lt;br /&gt;
    {&lt;br /&gt;
	return cast(long)std.math.sqrt(cast(real)x);&lt;br /&gt;
    }&lt;br /&gt;
===In, Out and Inheritance ===&lt;br /&gt;
If a function in a derived class overrides a function in its super class, then only one of the in contracts of the function and its base functions must be satisfied. Overriding functions then becomes a process of loosening the in  contracts. &lt;br /&gt;
&lt;br /&gt;
=== Class Invariants ===&lt;br /&gt;
Class invariants are used to specify characteristics of a class that always must be true (except while executing a member function). They are described in Classes. &lt;br /&gt;
&lt;br /&gt;
for detail information of contract, please refers to the helpful reading list in [2].&lt;br /&gt;
&lt;br /&gt;
==The advantages of Contract Programming==&lt;br /&gt;
&lt;br /&gt;
* A better understanding of the object-oriented method and, more generally, of software construction.&lt;br /&gt;
* A systematic approach to building bug-free object-oriented systems.&lt;br /&gt;
* An effective framework for debugging, testing and, more generally, quality assurance.&lt;br /&gt;
* A method for documenting software components.&lt;br /&gt;
* Better understanding and control of the inheritance mechanism.&lt;br /&gt;
* A technique for dealing with abnormal cases, leading to a safe and effective language construct for exception handling.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Example of If statement ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Operator&lt;br /&gt;
{&lt;br /&gt;
    string operation;&lt;br /&gt;
&lt;br /&gt;
    public int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
         switch(operation)&lt;br /&gt;
         {&lt;br /&gt;
             case &amp;quot;Add&amp;quot;:&lt;br /&gt;
                 return x + y;&lt;br /&gt;
             case &amp;quot;Subtract&amp;quot;:&lt;br /&gt;
                 return x - y;&lt;br /&gt;
             case &amp;quot;Multiply&amp;quot;:&lt;br /&gt;
                 return x * y;&lt;br /&gt;
             case &amp;quot;Divide&amp;quot;:&lt;br /&gt;
                 return x / y;&lt;br /&gt;
             default:&lt;br /&gt;
                 throw new InvalidOperationException(&amp;quot;Unsupported operation&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In such example of conditional statement on operator, we see that: if we want to reuse function &amp;quot;add&amp;quot; operator in the other code segment, we have to reuse whole Class operator with the value &amp;quot;Add&amp;quot;. And if we want to add a new operation &amp;quot;Power&amp;quot;, we need to code in the implementation of Class Operator.&lt;br /&gt;
&lt;br /&gt;
== Idea of Polymorphism ==&lt;br /&gt;
Facing the problem of the conditional statement, people[2] come up with refactoring method called 'Polymorphism'. The idea of Polymorphism is to replace the highly functional relationship with the subclass override procedure under abstract class. So subclass is created to encapsulate each function in the conditional statement and the conditional relation is replaced by override a common abstract class. The advantage of such idea is to separate the functionality.    &lt;br /&gt;
&lt;br /&gt;
=== Definition of Polymorphism ===&lt;br /&gt;
According to [1], Subtype polymorphism, almost universally called just polymorphism in the context of object-oriented programming, is the ability of one type, A, to appear as and be used like another type, B. &lt;br /&gt;
&lt;br /&gt;
The primary usage of polymorphism in industry (object-oriented programming theory) is the ability of objects belonging to different types to respond to method, field, or property calls of the same name, each one according to an appropriate type-specific behavior. The programmer (and the program) does not have to know the exact type of the object in advance, and so the exact behavior is determined at run time.&lt;br /&gt;
&lt;br /&gt;
== Example of Refactoring Conditional Statement with Polymorphism ==&lt;br /&gt;
*Before refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Operator&lt;br /&gt;
{&lt;br /&gt;
    string operation;&lt;br /&gt;
&lt;br /&gt;
    public int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
         switch(operation)&lt;br /&gt;
         {&lt;br /&gt;
             case &amp;quot;Add&amp;quot;:&lt;br /&gt;
                 return x + y;&lt;br /&gt;
             case &amp;quot;Subtract&amp;quot;:&lt;br /&gt;
                 return x - y;&lt;br /&gt;
             case &amp;quot;Multiply&amp;quot;:&lt;br /&gt;
                 return x * y;&lt;br /&gt;
             case &amp;quot;Divide&amp;quot;:&lt;br /&gt;
                 return x / y;&lt;br /&gt;
             default:&lt;br /&gt;
                 throw new InvalidOperationException(&amp;quot;Unsupported operation&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*After refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public abstract class Operator&lt;br /&gt;
{&lt;br /&gt;
    public abstract int Execute(int x, int y)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class Add : Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x + y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Subtract : Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x - y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Multiply: Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x * y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Divide: Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x / y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] wiki page of &amp;quot;Design by Contract&amp;quot;, http://en.wikipedia.org/wiki/Design_by_contract&lt;br /&gt;
&lt;br /&gt;
[2] Rene Santaolaya, Olivia G. Fragoso, Joaquín Pérez, Lorenzo Zambrano, Restructuring Conditional Code Structures Using Object Oriented Design Patterns, Lecture Notes in Computer Science. &lt;br /&gt;
&lt;br /&gt;
[3] Refactoring conditional statement, http://sourcemaking.com/refactoring/replace-conditional-with-polymorphism&lt;br /&gt;
&lt;br /&gt;
[4] Object Orientation Design, http://en.wikipedia.org/wiki/Object-oriented_design&lt;/div&gt;</summary>
		<author><name>Syi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=28753</id>
		<title>CSC/ECE 517 Fall 2009/wiki 3 1 SJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=28753"/>
		<updated>2009-11-18T22:02:56Z</updated>

		<summary type="html">&lt;p&gt;Syi: /* Introduction of Contract Programming */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Advantages and Disadvantages of Programming by Contract'''&lt;br /&gt;
&lt;br /&gt;
== Introduction of Contract Programming ==&lt;br /&gt;
&lt;br /&gt;
Contracts are a breakthrough technique to reduce the programming effort for large projects. Contracts are the concept of preconditions, postconditions, errors, and invariants. These specifications of &amp;quot;contract&amp;quot; define the interface of different element of software includes method, class, module... &lt;br /&gt;
The most basic contract is the assert. An assert inserts a checkable expression into the code, and that expression must evaluate to true: &lt;br /&gt;
 assert(expression);&lt;br /&gt;
an assert  in function bodies works by throwing an AssertError, which can be caught and handled. Catching the contract violation is useful when the code must deal with errant uses by other code, when it must be failure proof, and as a useful tool for debugging.&lt;br /&gt;
&lt;br /&gt;
==The advantages of Contract Programming==&lt;br /&gt;
&lt;br /&gt;
* A better understanding of the object-oriented method and, more generally, of software construction.&lt;br /&gt;
* A systematic approach to building bug-free object-oriented systems.&lt;br /&gt;
* An effective framework for debugging, testing and, more generally, quality assurance.&lt;br /&gt;
* A method for documenting software components.&lt;br /&gt;
* Better understanding and control of the inheritance mechanism.&lt;br /&gt;
* A technique for dealing with abnormal cases, leading to a safe and effective language construct for exception handling.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Example of If statement ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Operator&lt;br /&gt;
{&lt;br /&gt;
    string operation;&lt;br /&gt;
&lt;br /&gt;
    public int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
         switch(operation)&lt;br /&gt;
         {&lt;br /&gt;
             case &amp;quot;Add&amp;quot;:&lt;br /&gt;
                 return x + y;&lt;br /&gt;
             case &amp;quot;Subtract&amp;quot;:&lt;br /&gt;
                 return x - y;&lt;br /&gt;
             case &amp;quot;Multiply&amp;quot;:&lt;br /&gt;
                 return x * y;&lt;br /&gt;
             case &amp;quot;Divide&amp;quot;:&lt;br /&gt;
                 return x / y;&lt;br /&gt;
             default:&lt;br /&gt;
                 throw new InvalidOperationException(&amp;quot;Unsupported operation&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In such example of conditional statement on operator, we see that: if we want to reuse function &amp;quot;add&amp;quot; operator in the other code segment, we have to reuse whole Class operator with the value &amp;quot;Add&amp;quot;. And if we want to add a new operation &amp;quot;Power&amp;quot;, we need to code in the implementation of Class Operator.&lt;br /&gt;
&lt;br /&gt;
== Idea of Polymorphism ==&lt;br /&gt;
Facing the problem of the conditional statement, people[2] come up with refactoring method called 'Polymorphism'. The idea of Polymorphism is to replace the highly functional relationship with the subclass override procedure under abstract class. So subclass is created to encapsulate each function in the conditional statement and the conditional relation is replaced by override a common abstract class. The advantage of such idea is to separate the functionality.    &lt;br /&gt;
&lt;br /&gt;
=== Definition of Polymorphism ===&lt;br /&gt;
According to [1], Subtype polymorphism, almost universally called just polymorphism in the context of object-oriented programming, is the ability of one type, A, to appear as and be used like another type, B. &lt;br /&gt;
&lt;br /&gt;
The primary usage of polymorphism in industry (object-oriented programming theory) is the ability of objects belonging to different types to respond to method, field, or property calls of the same name, each one according to an appropriate type-specific behavior. The programmer (and the program) does not have to know the exact type of the object in advance, and so the exact behavior is determined at run time.&lt;br /&gt;
&lt;br /&gt;
== Example of Refactoring Conditional Statement with Polymorphism ==&lt;br /&gt;
*Before refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Operator&lt;br /&gt;
{&lt;br /&gt;
    string operation;&lt;br /&gt;
&lt;br /&gt;
    public int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
         switch(operation)&lt;br /&gt;
         {&lt;br /&gt;
             case &amp;quot;Add&amp;quot;:&lt;br /&gt;
                 return x + y;&lt;br /&gt;
             case &amp;quot;Subtract&amp;quot;:&lt;br /&gt;
                 return x - y;&lt;br /&gt;
             case &amp;quot;Multiply&amp;quot;:&lt;br /&gt;
                 return x * y;&lt;br /&gt;
             case &amp;quot;Divide&amp;quot;:&lt;br /&gt;
                 return x / y;&lt;br /&gt;
             default:&lt;br /&gt;
                 throw new InvalidOperationException(&amp;quot;Unsupported operation&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*After refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public abstract class Operator&lt;br /&gt;
{&lt;br /&gt;
    public abstract int Execute(int x, int y)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class Add : Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x + y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Subtract : Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x - y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Multiply: Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x * y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Divide: Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x / y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] wiki page of &amp;quot;Design by Contract&amp;quot;, http://en.wikipedia.org/wiki/Design_by_contract&lt;br /&gt;
&lt;br /&gt;
[2] Rene Santaolaya, Olivia G. Fragoso, Joaquín Pérez, Lorenzo Zambrano, Restructuring Conditional Code Structures Using Object Oriented Design Patterns, Lecture Notes in Computer Science. &lt;br /&gt;
&lt;br /&gt;
[3] Refactoring conditional statement, http://sourcemaking.com/refactoring/replace-conditional-with-polymorphism&lt;br /&gt;
&lt;br /&gt;
[4] Object Orientation Design, http://en.wikipedia.org/wiki/Object-oriented_design&lt;/div&gt;</summary>
		<author><name>Syi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=28740</id>
		<title>CSC/ECE 517 Fall 2009/wiki 3 1 SJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=28740"/>
		<updated>2009-11-18T21:54:10Z</updated>

		<summary type="html">&lt;p&gt;Syi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Advantages and Disadvantages of Programming by Contract'''&lt;br /&gt;
&lt;br /&gt;
== Introduction of Contract Programming ==&lt;br /&gt;
&lt;br /&gt;
Contracts are a breakthrough technique to reduce the programming effort for large projects. Contracts are the concept of preconditions, postconditions, errors, and invariants.  &lt;br /&gt;
 &lt;br /&gt;
==The advantages of Contract Programming==&lt;br /&gt;
&lt;br /&gt;
* A better understanding of the object-oriented method and, more generally, of software construction.&lt;br /&gt;
* A systematic approach to building bug-free object-oriented systems.&lt;br /&gt;
* An effective framework for debugging, testing and, more generally, quality assurance.&lt;br /&gt;
* A method for documenting software components.&lt;br /&gt;
* Better understanding and control of the inheritance mechanism.&lt;br /&gt;
* A technique for dealing with abnormal cases, leading to a safe and effective language construct for exception handling.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Example of If statement ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Operator&lt;br /&gt;
{&lt;br /&gt;
    string operation;&lt;br /&gt;
&lt;br /&gt;
    public int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
         switch(operation)&lt;br /&gt;
         {&lt;br /&gt;
             case &amp;quot;Add&amp;quot;:&lt;br /&gt;
                 return x + y;&lt;br /&gt;
             case &amp;quot;Subtract&amp;quot;:&lt;br /&gt;
                 return x - y;&lt;br /&gt;
             case &amp;quot;Multiply&amp;quot;:&lt;br /&gt;
                 return x * y;&lt;br /&gt;
             case &amp;quot;Divide&amp;quot;:&lt;br /&gt;
                 return x / y;&lt;br /&gt;
             default:&lt;br /&gt;
                 throw new InvalidOperationException(&amp;quot;Unsupported operation&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In such example of conditional statement on operator, we see that: if we want to reuse function &amp;quot;add&amp;quot; operator in the other code segment, we have to reuse whole Class operator with the value &amp;quot;Add&amp;quot;. And if we want to add a new operation &amp;quot;Power&amp;quot;, we need to code in the implementation of Class Operator.&lt;br /&gt;
&lt;br /&gt;
== Idea of Polymorphism ==&lt;br /&gt;
Facing the problem of the conditional statement, people[2] come up with refactoring method called 'Polymorphism'. The idea of Polymorphism is to replace the highly functional relationship with the subclass override procedure under abstract class. So subclass is created to encapsulate each function in the conditional statement and the conditional relation is replaced by override a common abstract class. The advantage of such idea is to separate the functionality.    &lt;br /&gt;
&lt;br /&gt;
=== Definition of Polymorphism ===&lt;br /&gt;
According to [1], Subtype polymorphism, almost universally called just polymorphism in the context of object-oriented programming, is the ability of one type, A, to appear as and be used like another type, B. &lt;br /&gt;
&lt;br /&gt;
The primary usage of polymorphism in industry (object-oriented programming theory) is the ability of objects belonging to different types to respond to method, field, or property calls of the same name, each one according to an appropriate type-specific behavior. The programmer (and the program) does not have to know the exact type of the object in advance, and so the exact behavior is determined at run time.&lt;br /&gt;
&lt;br /&gt;
== Example of Refactoring Conditional Statement with Polymorphism ==&lt;br /&gt;
*Before refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Operator&lt;br /&gt;
{&lt;br /&gt;
    string operation;&lt;br /&gt;
&lt;br /&gt;
    public int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
         switch(operation)&lt;br /&gt;
         {&lt;br /&gt;
             case &amp;quot;Add&amp;quot;:&lt;br /&gt;
                 return x + y;&lt;br /&gt;
             case &amp;quot;Subtract&amp;quot;:&lt;br /&gt;
                 return x - y;&lt;br /&gt;
             case &amp;quot;Multiply&amp;quot;:&lt;br /&gt;
                 return x * y;&lt;br /&gt;
             case &amp;quot;Divide&amp;quot;:&lt;br /&gt;
                 return x / y;&lt;br /&gt;
             default:&lt;br /&gt;
                 throw new InvalidOperationException(&amp;quot;Unsupported operation&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*After refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public abstract class Operator&lt;br /&gt;
{&lt;br /&gt;
    public abstract int Execute(int x, int y)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class Add : Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x + y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Subtract : Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x - y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Multiply: Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x * y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Divide: Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x / y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] wiki page of &amp;quot;Design by Contract&amp;quot;, http://en.wikipedia.org/wiki/Design_by_contract&lt;br /&gt;
&lt;br /&gt;
[2] Rene Santaolaya, Olivia G. Fragoso, Joaquín Pérez, Lorenzo Zambrano, Restructuring Conditional Code Structures Using Object Oriented Design Patterns, Lecture Notes in Computer Science. &lt;br /&gt;
&lt;br /&gt;
[3] Refactoring conditional statement, http://sourcemaking.com/refactoring/replace-conditional-with-polymorphism&lt;br /&gt;
&lt;br /&gt;
[4] Object Orientation Design, http://en.wikipedia.org/wiki/Object-oriented_design&lt;/div&gt;</summary>
		<author><name>Syi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=28738</id>
		<title>CSC/ECE 517 Fall 2009/wiki 3 1 SJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=28738"/>
		<updated>2009-11-18T21:53:40Z</updated>

		<summary type="html">&lt;p&gt;Syi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Advantages and Disadvantages of Programming by Contract'''&lt;br /&gt;
&lt;br /&gt;
== Introduction of Contract Programming ==&lt;br /&gt;
&lt;br /&gt;
Contracts are a breakthrough technique to reduce the programming effort for large projects. Contracts are the concept of preconditions, postconditions, errors, and invariants.  &lt;br /&gt;
 &lt;br /&gt;
==The advantages of Contract Programming==&lt;br /&gt;
&lt;br /&gt;
    * A better understanding of the object-oriented method and, more generally, of software construction.&lt;br /&gt;
    * A systematic approach to building bug-free object-oriented systems.&lt;br /&gt;
    * An effective framework for debugging, testing and, more generally, quality assurance.&lt;br /&gt;
    * A method for documenting software components.&lt;br /&gt;
    * Better understanding and control of the inheritance mechanism.&lt;br /&gt;
    * A technique for dealing with abnormal cases, leading to a safe and effective language construct for exception handling.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Example of If statement ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Operator&lt;br /&gt;
{&lt;br /&gt;
    string operation;&lt;br /&gt;
&lt;br /&gt;
    public int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
         switch(operation)&lt;br /&gt;
         {&lt;br /&gt;
             case &amp;quot;Add&amp;quot;:&lt;br /&gt;
                 return x + y;&lt;br /&gt;
             case &amp;quot;Subtract&amp;quot;:&lt;br /&gt;
                 return x - y;&lt;br /&gt;
             case &amp;quot;Multiply&amp;quot;:&lt;br /&gt;
                 return x * y;&lt;br /&gt;
             case &amp;quot;Divide&amp;quot;:&lt;br /&gt;
                 return x / y;&lt;br /&gt;
             default:&lt;br /&gt;
                 throw new InvalidOperationException(&amp;quot;Unsupported operation&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In such example of conditional statement on operator, we see that: if we want to reuse function &amp;quot;add&amp;quot; operator in the other code segment, we have to reuse whole Class operator with the value &amp;quot;Add&amp;quot;. And if we want to add a new operation &amp;quot;Power&amp;quot;, we need to code in the implementation of Class Operator.&lt;br /&gt;
&lt;br /&gt;
== Idea of Polymorphism ==&lt;br /&gt;
Facing the problem of the conditional statement, people[2] come up with refactoring method called 'Polymorphism'. The idea of Polymorphism is to replace the highly functional relationship with the subclass override procedure under abstract class. So subclass is created to encapsulate each function in the conditional statement and the conditional relation is replaced by override a common abstract class. The advantage of such idea is to separate the functionality.    &lt;br /&gt;
&lt;br /&gt;
=== Definition of Polymorphism ===&lt;br /&gt;
According to [1], Subtype polymorphism, almost universally called just polymorphism in the context of object-oriented programming, is the ability of one type, A, to appear as and be used like another type, B. &lt;br /&gt;
&lt;br /&gt;
The primary usage of polymorphism in industry (object-oriented programming theory) is the ability of objects belonging to different types to respond to method, field, or property calls of the same name, each one according to an appropriate type-specific behavior. The programmer (and the program) does not have to know the exact type of the object in advance, and so the exact behavior is determined at run time.&lt;br /&gt;
&lt;br /&gt;
== Example of Refactoring Conditional Statement with Polymorphism ==&lt;br /&gt;
*Before refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Operator&lt;br /&gt;
{&lt;br /&gt;
    string operation;&lt;br /&gt;
&lt;br /&gt;
    public int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
         switch(operation)&lt;br /&gt;
         {&lt;br /&gt;
             case &amp;quot;Add&amp;quot;:&lt;br /&gt;
                 return x + y;&lt;br /&gt;
             case &amp;quot;Subtract&amp;quot;:&lt;br /&gt;
                 return x - y;&lt;br /&gt;
             case &amp;quot;Multiply&amp;quot;:&lt;br /&gt;
                 return x * y;&lt;br /&gt;
             case &amp;quot;Divide&amp;quot;:&lt;br /&gt;
                 return x / y;&lt;br /&gt;
             default:&lt;br /&gt;
                 throw new InvalidOperationException(&amp;quot;Unsupported operation&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*After refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public abstract class Operator&lt;br /&gt;
{&lt;br /&gt;
    public abstract int Execute(int x, int y)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class Add : Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x + y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Subtract : Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x - y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Multiply: Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x * y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Divide: Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x / y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] wiki page of &amp;quot;Design by Contract&amp;quot;, http://en.wikipedia.org/wiki/Design_by_contract&lt;br /&gt;
&lt;br /&gt;
[2] Rene Santaolaya, Olivia G. Fragoso, Joaquín Pérez, Lorenzo Zambrano, Restructuring Conditional Code Structures Using Object Oriented Design Patterns, Lecture Notes in Computer Science. &lt;br /&gt;
&lt;br /&gt;
[3] Refactoring conditional statement, http://sourcemaking.com/refactoring/replace-conditional-with-polymorphism&lt;br /&gt;
&lt;br /&gt;
[4] Object Orientation Design, http://en.wikipedia.org/wiki/Object-oriented_design&lt;/div&gt;</summary>
		<author><name>Syi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=28737</id>
		<title>CSC/ECE 517 Fall 2009/wiki 3 1 SJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=28737"/>
		<updated>2009-11-18T21:50:31Z</updated>

		<summary type="html">&lt;p&gt;Syi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Advantages and Disadvantages of Programming by Contract'''&lt;br /&gt;
&lt;br /&gt;
== Introduction of Contract Programming ==&lt;br /&gt;
&lt;br /&gt;
One of the most important consideration of Object-Orientation Software Design is 'Reuse' and 'Change' [2][4]. In terms of reuse, we mean to build the new software with the building block from the old software. The importance of 'change' is from the fact that the software is always changing to keep alive. So that how to effectively make change to the source code is critical for the software design.   &lt;br /&gt;
 &lt;br /&gt;
=== The Problem of If Statement ===&lt;br /&gt;
&lt;br /&gt;
Under the design consideration we have discussed, the problem of if statement is quite obvious: 1. the conditional relationship in function level prevent us to reuse each of the function separately. We can only reuse the whole application as a unit. 2. when we want to change the functionality of a certain function or add a new function we have to trace to every implementation code. Such change is expensive and violate the OO principle 'code to interface instead of implementation'.    &lt;br /&gt;
&lt;br /&gt;
=== Example of If statement ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Operator&lt;br /&gt;
{&lt;br /&gt;
    string operation;&lt;br /&gt;
&lt;br /&gt;
    public int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
         switch(operation)&lt;br /&gt;
         {&lt;br /&gt;
             case &amp;quot;Add&amp;quot;:&lt;br /&gt;
                 return x + y;&lt;br /&gt;
             case &amp;quot;Subtract&amp;quot;:&lt;br /&gt;
                 return x - y;&lt;br /&gt;
             case &amp;quot;Multiply&amp;quot;:&lt;br /&gt;
                 return x * y;&lt;br /&gt;
             case &amp;quot;Divide&amp;quot;:&lt;br /&gt;
                 return x / y;&lt;br /&gt;
             default:&lt;br /&gt;
                 throw new InvalidOperationException(&amp;quot;Unsupported operation&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In such example of conditional statement on operator, we see that: if we want to reuse function &amp;quot;add&amp;quot; operator in the other code segment, we have to reuse whole Class operator with the value &amp;quot;Add&amp;quot;. And if we want to add a new operation &amp;quot;Power&amp;quot;, we need to code in the implementation of Class Operator.&lt;br /&gt;
&lt;br /&gt;
== Idea of Polymorphism ==&lt;br /&gt;
Facing the problem of the conditional statement, people[2] come up with refactoring method called 'Polymorphism'. The idea of Polymorphism is to replace the highly functional relationship with the subclass override procedure under abstract class. So subclass is created to encapsulate each function in the conditional statement and the conditional relation is replaced by override a common abstract class. The advantage of such idea is to separate the functionality.    &lt;br /&gt;
&lt;br /&gt;
=== Definition of Polymorphism ===&lt;br /&gt;
According to [1], Subtype polymorphism, almost universally called just polymorphism in the context of object-oriented programming, is the ability of one type, A, to appear as and be used like another type, B. &lt;br /&gt;
&lt;br /&gt;
The primary usage of polymorphism in industry (object-oriented programming theory) is the ability of objects belonging to different types to respond to method, field, or property calls of the same name, each one according to an appropriate type-specific behavior. The programmer (and the program) does not have to know the exact type of the object in advance, and so the exact behavior is determined at run time.&lt;br /&gt;
&lt;br /&gt;
== Example of Refactoring Conditional Statement with Polymorphism ==&lt;br /&gt;
*Before refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Operator&lt;br /&gt;
{&lt;br /&gt;
    string operation;&lt;br /&gt;
&lt;br /&gt;
    public int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
         switch(operation)&lt;br /&gt;
         {&lt;br /&gt;
             case &amp;quot;Add&amp;quot;:&lt;br /&gt;
                 return x + y;&lt;br /&gt;
             case &amp;quot;Subtract&amp;quot;:&lt;br /&gt;
                 return x - y;&lt;br /&gt;
             case &amp;quot;Multiply&amp;quot;:&lt;br /&gt;
                 return x * y;&lt;br /&gt;
             case &amp;quot;Divide&amp;quot;:&lt;br /&gt;
                 return x / y;&lt;br /&gt;
             default:&lt;br /&gt;
                 throw new InvalidOperationException(&amp;quot;Unsupported operation&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*After refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public abstract class Operator&lt;br /&gt;
{&lt;br /&gt;
    public abstract int Execute(int x, int y)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class Add : Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x + y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Subtract : Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x - y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Multiply: Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x * y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Divide: Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x / y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] wiki page of &amp;quot;Design by Contract&amp;quot;, http://en.wikipedia.org/wiki/Design_by_contract&lt;br /&gt;
&lt;br /&gt;
[2] Rene Santaolaya, Olivia G. Fragoso, Joaquín Pérez, Lorenzo Zambrano, Restructuring Conditional Code Structures Using Object Oriented Design Patterns, Lecture Notes in Computer Science. &lt;br /&gt;
&lt;br /&gt;
[3] Refactoring conditional statement, http://sourcemaking.com/refactoring/replace-conditional-with-polymorphism&lt;br /&gt;
&lt;br /&gt;
[4] Object Orientation Design, http://en.wikipedia.org/wiki/Object-oriented_design&lt;/div&gt;</summary>
		<author><name>Syi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=28722</id>
		<title>CSC/ECE 517 Fall 2009/wiki 3 1 SJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_3_1_SJ&amp;diff=28722"/>
		<updated>2009-11-18T21:39:13Z</updated>

		<summary type="html">&lt;p&gt;Syi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Refactoring If Statement with Polymorphism.'''&lt;br /&gt;
&lt;br /&gt;
== Design Consideration: Reuse and Change ==&lt;br /&gt;
&lt;br /&gt;
One of the most important consideration of Object-Orientation Software Design is 'Reuse' and 'Change' [2][4]. In terms of reuse, we mean to build the new software with the building block from the old software. The importance of 'change' is from the fact that the software is always changing to keep alive. So that how to effectively make change to the source code is critical for the software design.   &lt;br /&gt;
 &lt;br /&gt;
=== The Problem of If Statement ===&lt;br /&gt;
&lt;br /&gt;
Under the design consideration we have discussed, the problem of if statement is quite obvious: 1. the conditional relationship in function level prevent us to reuse each of the function separately. We can only reuse the whole application as a unit. 2. when we want to change the functionality of a certain function or add a new function we have to trace to every implementation code. Such change is expensive and violate the OO principle 'code to interface instead of implementation'.    &lt;br /&gt;
&lt;br /&gt;
=== Example of If statement ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Operator&lt;br /&gt;
{&lt;br /&gt;
    string operation;&lt;br /&gt;
&lt;br /&gt;
    public int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
         switch(operation)&lt;br /&gt;
         {&lt;br /&gt;
             case &amp;quot;Add&amp;quot;:&lt;br /&gt;
                 return x + y;&lt;br /&gt;
             case &amp;quot;Subtract&amp;quot;:&lt;br /&gt;
                 return x - y;&lt;br /&gt;
             case &amp;quot;Multiply&amp;quot;:&lt;br /&gt;
                 return x * y;&lt;br /&gt;
             case &amp;quot;Divide&amp;quot;:&lt;br /&gt;
                 return x / y;&lt;br /&gt;
             default:&lt;br /&gt;
                 throw new InvalidOperationException(&amp;quot;Unsupported operation&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In such example of conditional statement on operator, we see that: if we want to reuse function &amp;quot;add&amp;quot; operator in the other code segment, we have to reuse whole Class operator with the value &amp;quot;Add&amp;quot;. And if we want to add a new operation &amp;quot;Power&amp;quot;, we need to code in the implementation of Class Operator.&lt;br /&gt;
&lt;br /&gt;
== Idea of Polymorphism ==&lt;br /&gt;
Facing the problem of the conditional statement, people[2] come up with refactoring method called 'Polymorphism'. The idea of Polymorphism is to replace the highly functional relationship with the subclass override procedure under abstract class. So subclass is created to encapsulate each function in the conditional statement and the conditional relation is replaced by override a common abstract class. The advantage of such idea is to separate the functionality.    &lt;br /&gt;
&lt;br /&gt;
=== Definition of Polymorphism ===&lt;br /&gt;
According to [1], Subtype polymorphism, almost universally called just polymorphism in the context of object-oriented programming, is the ability of one type, A, to appear as and be used like another type, B. &lt;br /&gt;
&lt;br /&gt;
The primary usage of polymorphism in industry (object-oriented programming theory) is the ability of objects belonging to different types to respond to method, field, or property calls of the same name, each one according to an appropriate type-specific behavior. The programmer (and the program) does not have to know the exact type of the object in advance, and so the exact behavior is determined at run time.&lt;br /&gt;
&lt;br /&gt;
== Example of Refactoring Conditional Statement with Polymorphism ==&lt;br /&gt;
*Before refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Operator&lt;br /&gt;
{&lt;br /&gt;
    string operation;&lt;br /&gt;
&lt;br /&gt;
    public int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
         switch(operation)&lt;br /&gt;
         {&lt;br /&gt;
             case &amp;quot;Add&amp;quot;:&lt;br /&gt;
                 return x + y;&lt;br /&gt;
             case &amp;quot;Subtract&amp;quot;:&lt;br /&gt;
                 return x - y;&lt;br /&gt;
             case &amp;quot;Multiply&amp;quot;:&lt;br /&gt;
                 return x * y;&lt;br /&gt;
             case &amp;quot;Divide&amp;quot;:&lt;br /&gt;
                 return x / y;&lt;br /&gt;
             default:&lt;br /&gt;
                 throw new InvalidOperationException(&amp;quot;Unsupported operation&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*After refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public abstract class Operator&lt;br /&gt;
{&lt;br /&gt;
    public abstract int Execute(int x, int y)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class Add : Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x + y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Subtract : Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x - y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Multiply: Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x * y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Divide: Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x / y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] Polymorphism in object-oriented programming, http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming&lt;br /&gt;
&lt;br /&gt;
[2] Rene Santaolaya, Olivia G. Fragoso, Joaquín Pérez, Lorenzo Zambrano, Restructuring Conditional Code Structures Using Object Oriented Design Patterns, Lecture Notes in Computer Science. &lt;br /&gt;
&lt;br /&gt;
[3] Refactoring conditional statement, http://sourcemaking.com/refactoring/replace-conditional-with-polymorphism&lt;br /&gt;
&lt;br /&gt;
[4] Object Orientation Design, http://en.wikipedia.org/wiki/Object-oriented_design&lt;/div&gt;</summary>
		<author><name>Syi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_2_2_SJ&amp;diff=28717</id>
		<title>CSC/ECE 517 Fall 2009/wiki 2 2 SJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_2_2_SJ&amp;diff=28717"/>
		<updated>2009-11-18T21:37:20Z</updated>

		<summary type="html">&lt;p&gt;Syi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Refactoring If Statement with Polymorphism.'''&lt;br /&gt;
&lt;br /&gt;
== Design Consideration: Reuse and Change ==&lt;br /&gt;
&lt;br /&gt;
One of the most important consideration of Object-Orientation Software Design is 'Reuse' and 'Change' [2][4]. In terms of reuse, we mean to build the new software with the building block from the old software. The importance of 'change' is from the fact that the software is always changing to keep alive. So that how to effectively make change to the source code is critical for the software design.   &lt;br /&gt;
 &lt;br /&gt;
=== The Problem of If Statement ===&lt;br /&gt;
&lt;br /&gt;
Under the design consideration we have discussed, the problem of if statement is quite obvious: 1. the conditional relationship in function level prevent us to reuse each of the function separately. We can only reuse the whole application as a unit. 2. when we want to change the functionality of a certain function or add a new function we have to trace to every implementation code. Such change is expensive and violate the OO principle 'code to interface instead of implementation'.    &lt;br /&gt;
&lt;br /&gt;
=== Example of If statement ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Operator&lt;br /&gt;
{&lt;br /&gt;
    string operation;&lt;br /&gt;
&lt;br /&gt;
    public int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
         switch(operation)&lt;br /&gt;
         {&lt;br /&gt;
             case &amp;quot;Add&amp;quot;:&lt;br /&gt;
                 return x + y;&lt;br /&gt;
             case &amp;quot;Subtract&amp;quot;:&lt;br /&gt;
                 return x - y;&lt;br /&gt;
             case &amp;quot;Multiply&amp;quot;:&lt;br /&gt;
                 return x * y;&lt;br /&gt;
             case &amp;quot;Divide&amp;quot;:&lt;br /&gt;
                 return x / y;&lt;br /&gt;
             default:&lt;br /&gt;
                 throw new InvalidOperationException(&amp;quot;Unsupported operation&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In such example of conditional statement on operator, we see that: if we want to reuse function &amp;quot;add&amp;quot; operator in the other code segment, we have to reuse whole Class operator with the value &amp;quot;Add&amp;quot;. And if we want to add a new operation &amp;quot;Power&amp;quot;, we need to code in the implementation of Class Operator.&lt;br /&gt;
&lt;br /&gt;
== Idea of Polymorphism ==&lt;br /&gt;
Facing the problem of the conditional statement, people[2] come up with refactoring method called 'Polymorphism'. The idea of Polymorphism is to replace the highly functional relationship with the subclass override procedure under abstract class. So subclass is created to encapsulate each function in the conditional statement and the conditional relation is replaced by override a common abstract class. The advantage of such idea is to separate the functionality.    &lt;br /&gt;
&lt;br /&gt;
=== Definition of Polymorphism ===&lt;br /&gt;
According to [1], Subtype polymorphism, almost universally called just polymorphism in the context of object-oriented programming, is the ability of one type, A, to appear as and be used like another type, B. &lt;br /&gt;
&lt;br /&gt;
The primary usage of polymorphism in industry (object-oriented programming theory) is the ability of objects belonging to different types to respond to method, field, or property calls of the same name, each one according to an appropriate type-specific behavior. The programmer (and the program) does not have to know the exact type of the object in advance, and so the exact behavior is determined at run time.&lt;br /&gt;
&lt;br /&gt;
== Example of Refactoring Conditional Statement with Polymorphism ==&lt;br /&gt;
*Before refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Operator&lt;br /&gt;
{&lt;br /&gt;
    string operation;&lt;br /&gt;
&lt;br /&gt;
    public int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
         switch(operation)&lt;br /&gt;
         {&lt;br /&gt;
             case &amp;quot;Add&amp;quot;:&lt;br /&gt;
                 return x + y;&lt;br /&gt;
             case &amp;quot;Subtract&amp;quot;:&lt;br /&gt;
                 return x - y;&lt;br /&gt;
             case &amp;quot;Multiply&amp;quot;:&lt;br /&gt;
                 return x * y;&lt;br /&gt;
             case &amp;quot;Divide&amp;quot;:&lt;br /&gt;
                 return x / y;&lt;br /&gt;
             default:&lt;br /&gt;
                 throw new InvalidOperationException(&amp;quot;Unsupported operation&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*After refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public abstract class Operator&lt;br /&gt;
{&lt;br /&gt;
    public abstract int Execute(int x, int y)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class Add : Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x + y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Subtract : Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x - y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Multiply: Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x * y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Divide: Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x / y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] Polymorphism in object-oriented programming, http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming&lt;br /&gt;
&lt;br /&gt;
[2] Rene Santaolaya, Olivia G. Fragoso, Joaquín Pérez, Lorenzo Zambrano, Restructuring Conditional Code Structures Using Object Oriented Design Patterns, Lecture Notes in Computer Science. &lt;br /&gt;
&lt;br /&gt;
[3] Refactoring conditional statement, http://sourcemaking.com/refactoring/replace-conditional-with-polymorphism&lt;br /&gt;
&lt;br /&gt;
[4] Object Orientation Design, http://en.wikipedia.org/wiki/Object-oriented_design&lt;/div&gt;</summary>
		<author><name>Syi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_2_2_SJ&amp;diff=25593</id>
		<title>CSC/ECE 517 Fall 2009/wiki 2 2 SJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_2_2_SJ&amp;diff=25593"/>
		<updated>2009-10-10T04:25:18Z</updated>

		<summary type="html">&lt;p&gt;Syi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Refactoring If Statement with Polymorphism.'''&lt;br /&gt;
&lt;br /&gt;
== Design Consideration: Reuse and Change ==&lt;br /&gt;
&lt;br /&gt;
One of the most important consideration of Object-Orientation Software Design is 'Reuse' and 'Change' [2][4]. In terms of reuse, we mean to build the new software with the building block from the old software. The importance of 'change' is from the fact that the software is always changing to keep alive. So that how to effectively make change to the source code is critical for the software design.   &lt;br /&gt;
 &lt;br /&gt;
=== The Problem of If Statement ===&lt;br /&gt;
&lt;br /&gt;
Under the design consideration we have discussed, the problem of if statement is quite obvious: 1. the conditional relationship in function level prevent us to reuse each of the function separately. We can only reuse the whole application as a unit. 2. when we want to change the functionality of a certain function or add a new function we have to trace to every implementation code. Such change is expensive and violate the OO principle 'code to interface instead of implementation'.    &lt;br /&gt;
&lt;br /&gt;
=== Example of If statement ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Operator&lt;br /&gt;
{&lt;br /&gt;
    string operation;&lt;br /&gt;
&lt;br /&gt;
    public int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
         switch(operation)&lt;br /&gt;
         {&lt;br /&gt;
             case &amp;quot;Add&amp;quot;:&lt;br /&gt;
                 return x + y;&lt;br /&gt;
             case &amp;quot;Subtract&amp;quot;:&lt;br /&gt;
                 return x - y;&lt;br /&gt;
             case &amp;quot;Multiply&amp;quot;:&lt;br /&gt;
                 return x * y;&lt;br /&gt;
             case &amp;quot;Divide&amp;quot;:&lt;br /&gt;
                 return x / y;&lt;br /&gt;
             default:&lt;br /&gt;
                 throw new InvalidOperationException(&amp;quot;Unsupported operation&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In such example of conditional statement on operator, we see that: if we want to reuse function &amp;quot;add&amp;quot; operator in the other code segment, we have to reuse whole Class operator with the value &amp;quot;Add&amp;quot;. And if we want to add a new operation &amp;quot;Power&amp;quot;, we need to code in the implementation of Class Operator.&lt;br /&gt;
&lt;br /&gt;
== Idea of Polymorphism ==&lt;br /&gt;
Facing the problem of the conditional statement, people[2] come up with refactoring method called 'Polymorphism'. The idea of Polymorphism is to replace the highly functional relationship with the subclass override procedure under abstract class. So subclass is created to encapsulate each function in the conditional statement and the conditional relation is replaced by override a common abstract class. The advantage of such idea is to separate the functionality.    &lt;br /&gt;
&lt;br /&gt;
=== Definition of Polymorphism ===&lt;br /&gt;
According to [1], Subtype polymorphism, almost universally called just polymorphism in the context of object-oriented programming, is the ability of one type, A, to appear as and be used like another type, B. &lt;br /&gt;
&lt;br /&gt;
The primary usage of polymorphism in industry (object-oriented programming theory) is the ability of objects belonging to different types to respond to method, field, or property calls of the same name, each one according to an appropriate type-specific behavior. The programmer (and the program) does not have to know the exact type of the object in advance, and so the exact behavior is determined at run time.&lt;br /&gt;
&lt;br /&gt;
== Example of Refactoring Conditional Statement with Polymorphism ==&lt;br /&gt;
*Before refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Operator&lt;br /&gt;
{&lt;br /&gt;
    string operation;&lt;br /&gt;
&lt;br /&gt;
    public int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
         switch(operation)&lt;br /&gt;
         {&lt;br /&gt;
             case &amp;quot;Add&amp;quot;:&lt;br /&gt;
                 return x + y;&lt;br /&gt;
             case &amp;quot;Subtract&amp;quot;:&lt;br /&gt;
                 return x - y;&lt;br /&gt;
             case &amp;quot;Multiply&amp;quot;:&lt;br /&gt;
                 return x * y;&lt;br /&gt;
             case &amp;quot;Divide&amp;quot;:&lt;br /&gt;
                 return x / y;&lt;br /&gt;
             default:&lt;br /&gt;
                 throw new InvalidOperationException(&amp;quot;Unsupported operation&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*After refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public abstract class Operator&lt;br /&gt;
{&lt;br /&gt;
    public abstract int Execute(int x, int y)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class Add : Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x + y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Subtract : Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x - y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Multiply: Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x * y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Divide: Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x / y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] Polymorphism in object-oriented programming, http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming&lt;br /&gt;
&lt;br /&gt;
[2] Rene Santaolaya, Olivia G. Fragoso, Joaquín Pérez, Lorenzo Zambrano, Restructuring Conditional Code Structures Using Object Oriented Design Patterns, Lecture Notes in Computer Science. &lt;br /&gt;
&lt;br /&gt;
[3] Refactoring conditional statement, http://sourcemaking.com/refactoring/replace-conditional-with-polymorphism&lt;br /&gt;
&lt;br /&gt;
[4] Object Orientation Design, http://en.wikipedia.org/wiki/Object-oriented_design&lt;/div&gt;</summary>
		<author><name>Syi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_2_If_SJ&amp;diff=24428</id>
		<title>CSC/ECE 517 Fall 2009/wiki 2 If SJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_2_If_SJ&amp;diff=24428"/>
		<updated>2009-10-09T20:45:29Z</updated>

		<summary type="html">&lt;p&gt;Syi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Refactoring If Statement with Polymorphism.'''&lt;br /&gt;
&lt;br /&gt;
== Design Consideration: Reuse and Change ==&lt;br /&gt;
&lt;br /&gt;
One of the most important consideration of Object-Orientation Software Design is 'Reuse' and 'Change' [2][4]. In terms of reuse, we mean to build the new software with the building block from the old software. The importance of 'change' is from the fact that the software is always changing to keep alive. So that how to effectively make change to the source code is critical for the software design.   &lt;br /&gt;
 &lt;br /&gt;
=== The Problem of If Statement ===&lt;br /&gt;
&lt;br /&gt;
Under the design consideration we have discussed, the problem of if statement is quite obvious: 1. the conditional relationship in function level prevent us to reuse each of the function separately. We can only reuse the whole application as a unit. 2. when we want to change the functionality of a certain function or add a new function we have to trace to every implementation code. Such change is expensive and violate the OO principle 'code to interface instead of implementation'.    &lt;br /&gt;
&lt;br /&gt;
=== Example of If statement ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Operator&lt;br /&gt;
{&lt;br /&gt;
    string operation;&lt;br /&gt;
&lt;br /&gt;
    public int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
         switch(operation)&lt;br /&gt;
         {&lt;br /&gt;
             case &amp;quot;Add&amp;quot;:&lt;br /&gt;
                 return x + y;&lt;br /&gt;
             case &amp;quot;Subtract&amp;quot;:&lt;br /&gt;
                 return x - y;&lt;br /&gt;
             case &amp;quot;Multiply&amp;quot;:&lt;br /&gt;
                 return x * y;&lt;br /&gt;
             case &amp;quot;Divide&amp;quot;:&lt;br /&gt;
                 return x / y;&lt;br /&gt;
             default:&lt;br /&gt;
                 throw new InvalidOperationException(&amp;quot;Unsupported operation&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In such example of conditional statement on operator, we see that: if we want to reuse function &amp;quot;add&amp;quot; operator in the other code segment, we have to reuse whole Class operator with the value &amp;quot;Add&amp;quot;. And if we want to add a new operation &amp;quot;Power&amp;quot;, we need to code in the implementation of Class Operator.&lt;br /&gt;
&lt;br /&gt;
== Idea of Polymorphism ==&lt;br /&gt;
Facing the problem of the conditional statement, people[2] come up with refactoring method called 'Polymorphism'. The idea of Polymorphism is to replace the highly functional relationship with the subclass override procedure under abstract class. So subclass is created to encapsulate each function in the conditional statement and the conditional relation is replaced by override a common abstract class. The advantage of such idea is to separate the functionality.    &lt;br /&gt;
&lt;br /&gt;
=== Definition of Polymorphism ===&lt;br /&gt;
According to [1], Subtype polymorphism, almost universally called just polymorphism in the context of object-oriented programming, is the ability of one type, A, to appear as and be used like another type, B. &lt;br /&gt;
&lt;br /&gt;
The primary usage of polymorphism in industry (object-oriented programming theory) is the ability of objects belonging to different types to respond to method, field, or property calls of the same name, each one according to an appropriate type-specific behavior. The programmer (and the program) does not have to know the exact type of the object in advance, and so the exact behavior is determined at run time.&lt;br /&gt;
&lt;br /&gt;
== Example of Refactoring Conditional Statement with Polymorphism ==&lt;br /&gt;
*Before refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Operator&lt;br /&gt;
{&lt;br /&gt;
    string operation;&lt;br /&gt;
&lt;br /&gt;
    public int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
         switch(operation)&lt;br /&gt;
         {&lt;br /&gt;
             case &amp;quot;Add&amp;quot;:&lt;br /&gt;
                 return x + y;&lt;br /&gt;
             case &amp;quot;Subtract&amp;quot;:&lt;br /&gt;
                 return x - y;&lt;br /&gt;
             case &amp;quot;Multiply&amp;quot;:&lt;br /&gt;
                 return x * y;&lt;br /&gt;
             case &amp;quot;Divide&amp;quot;:&lt;br /&gt;
                 return x / y;&lt;br /&gt;
             default:&lt;br /&gt;
                 throw new InvalidOperationException(&amp;quot;Unsupported operation&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*After refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public abstract class Operator&lt;br /&gt;
{&lt;br /&gt;
    public abstract int Execute(int x, int y)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class Add : Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x + y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Subtract : Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x - y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Multiply: Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x * y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Divide: Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x / y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] Polymorphism in object-oriented programming, http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming&lt;br /&gt;
&lt;br /&gt;
[2] Rene Santaolaya, Olivia G. Fragoso, Joaquín Pérez, Lorenzo Zambrano, Restructuring Conditional Code Structures Using Object Oriented Design Patterns, Lecture Notes in Computer Science. &lt;br /&gt;
&lt;br /&gt;
[3] Refactoring conditional statement, http://sourcemaking.com/refactoring/replace-conditional-with-polymorphism&lt;br /&gt;
&lt;br /&gt;
[4] Object Orientation Design, http://en.wikipedia.org/wiki/Object-oriented_design&lt;/div&gt;</summary>
		<author><name>Syi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_2_If_SJ&amp;diff=24427</id>
		<title>CSC/ECE 517 Fall 2009/wiki 2 If SJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_2_If_SJ&amp;diff=24427"/>
		<updated>2009-10-09T20:45:02Z</updated>

		<summary type="html">&lt;p&gt;Syi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Refactoring If Statement with Polymorphism.'''&lt;br /&gt;
&lt;br /&gt;
== Design Consideration: Reuse and Change ==&lt;br /&gt;
&lt;br /&gt;
One of the most important consideration of Object-Orientation Software Design is 'Reuse' and 'Change' [4]. In terms of reuse, we mean to build the new software with the building block from the old software. The importance of 'change' is from the fact that the software is always changing to keep alive. So that how to effectively make change to the source code is critical for the software design.   &lt;br /&gt;
 &lt;br /&gt;
=== The Problem of If Statement ===&lt;br /&gt;
&lt;br /&gt;
Under the design consideration we have discussed, the problem of if statement is quite obvious: 1. the conditional relationship in function level prevent us to reuse each of the function separately. We can only reuse the whole application as a unit. 2. when we want to change the functionality of a certain function or add a new function we have to trace to every implementation code. Such change is expensive and violate the OO principle 'code to interface instead of implementation'.    &lt;br /&gt;
&lt;br /&gt;
=== Example of If statement ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Operator&lt;br /&gt;
{&lt;br /&gt;
    string operation;&lt;br /&gt;
&lt;br /&gt;
    public int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
         switch(operation)&lt;br /&gt;
         {&lt;br /&gt;
             case &amp;quot;Add&amp;quot;:&lt;br /&gt;
                 return x + y;&lt;br /&gt;
             case &amp;quot;Subtract&amp;quot;:&lt;br /&gt;
                 return x - y;&lt;br /&gt;
             case &amp;quot;Multiply&amp;quot;:&lt;br /&gt;
                 return x * y;&lt;br /&gt;
             case &amp;quot;Divide&amp;quot;:&lt;br /&gt;
                 return x / y;&lt;br /&gt;
             default:&lt;br /&gt;
                 throw new InvalidOperationException(&amp;quot;Unsupported operation&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In such example of conditional statement on operator, we see that: if we want to reuse function &amp;quot;add&amp;quot; operator in the other code segment, we have to reuse whole Class operator with the value &amp;quot;Add&amp;quot;. And if we want to add a new operation &amp;quot;Power&amp;quot;, we need to code in the implementation of Class Operator.&lt;br /&gt;
&lt;br /&gt;
== Idea of Polymorphism ==&lt;br /&gt;
Facing the problem of the conditional statement, people[2] come up with refactoring method called 'Polymorphism'. The idea of Polymorphism is to replace the highly functional relationship with the subclass override procedure under abstract class. So subclass is created to encapsulate each function in the conditional statement and the conditional relation is replaced by override a common abstract class. The advantage of such idea is to separate the functionality.    &lt;br /&gt;
&lt;br /&gt;
=== Definition of Polymorphism ===&lt;br /&gt;
According to [1], Subtype polymorphism, almost universally called just polymorphism in the context of object-oriented programming, is the ability of one type, A, to appear as and be used like another type, B. &lt;br /&gt;
&lt;br /&gt;
The primary usage of polymorphism in industry (object-oriented programming theory) is the ability of objects belonging to different types to respond to method, field, or property calls of the same name, each one according to an appropriate type-specific behavior. The programmer (and the program) does not have to know the exact type of the object in advance, and so the exact behavior is determined at run time.&lt;br /&gt;
&lt;br /&gt;
== Example of Refactoring Conditional Statement with Polymorphism ==&lt;br /&gt;
*Before refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Operator&lt;br /&gt;
{&lt;br /&gt;
    string operation;&lt;br /&gt;
&lt;br /&gt;
    public int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
         switch(operation)&lt;br /&gt;
         {&lt;br /&gt;
             case &amp;quot;Add&amp;quot;:&lt;br /&gt;
                 return x + y;&lt;br /&gt;
             case &amp;quot;Subtract&amp;quot;:&lt;br /&gt;
                 return x - y;&lt;br /&gt;
             case &amp;quot;Multiply&amp;quot;:&lt;br /&gt;
                 return x * y;&lt;br /&gt;
             case &amp;quot;Divide&amp;quot;:&lt;br /&gt;
                 return x / y;&lt;br /&gt;
             default:&lt;br /&gt;
                 throw new InvalidOperationException(&amp;quot;Unsupported operation&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*After refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public abstract class Operator&lt;br /&gt;
{&lt;br /&gt;
    public abstract int Execute(int x, int y)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class Add : Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x + y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Subtract : Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x - y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Multiply: Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x * y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Divide: Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x / y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] Polymorphism in object-oriented programming, http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming&lt;br /&gt;
&lt;br /&gt;
[2] Rene Santaolaya, Olivia G. Fragoso, Joaquín Pérez, Lorenzo Zambrano, Restructuring Conditional Code Structures Using Object Oriented Design Patterns, Lecture Notes in Computer Science. &lt;br /&gt;
&lt;br /&gt;
[3] Refactoring conditional statement, http://sourcemaking.com/refactoring/replace-conditional-with-polymorphism&lt;br /&gt;
&lt;br /&gt;
[4] Object Orientation Design, http://en.wikipedia.org/wiki/Object-oriented_design&lt;/div&gt;</summary>
		<author><name>Syi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_2_If_SJ&amp;diff=24419</id>
		<title>CSC/ECE 517 Fall 2009/wiki 2 If SJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_2_If_SJ&amp;diff=24419"/>
		<updated>2009-10-09T20:42:32Z</updated>

		<summary type="html">&lt;p&gt;Syi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Refactoring If Statement with Polymorphism.'''&lt;br /&gt;
&lt;br /&gt;
== Design Consideration: Reuse and Change ==&lt;br /&gt;
&lt;br /&gt;
One of the most important consideration of Object-Orientation Software Design is 'Reuse' and 'Change'. In terms of reuse, we mean to build the new software with the building block from the old software. The importance of 'change' is from the fact that the software is always changing to keep alive. So that how to effectively make change to the source code is critical for the software design.   &lt;br /&gt;
 &lt;br /&gt;
=== The Problem of If Statement ===&lt;br /&gt;
&lt;br /&gt;
Under the design consideration we have discussed, the problem of if statement is quite obvious: 1. the conditional relationship in function level prevent us to reuse each of the function separately. We can only reuse the whole application as a unit. 2. when we want to change the functionality of a certain function or add a new function we have to trace to every implementation code. Such change is expensive and violate the OO principle 'code to interface instead of implementation'.    &lt;br /&gt;
&lt;br /&gt;
=== Example of If statement ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Operator&lt;br /&gt;
{&lt;br /&gt;
    string operation;&lt;br /&gt;
&lt;br /&gt;
    public int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
         switch(operation)&lt;br /&gt;
         {&lt;br /&gt;
             case &amp;quot;Add&amp;quot;:&lt;br /&gt;
                 return x + y;&lt;br /&gt;
             case &amp;quot;Subtract&amp;quot;:&lt;br /&gt;
                 return x - y;&lt;br /&gt;
             case &amp;quot;Multiply&amp;quot;:&lt;br /&gt;
                 return x * y;&lt;br /&gt;
             case &amp;quot;Divide&amp;quot;:&lt;br /&gt;
                 return x / y;&lt;br /&gt;
             default:&lt;br /&gt;
                 throw new InvalidOperationException(&amp;quot;Unsupported operation&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In such example of conditional statement on operator, we see that: if we want to reuse function &amp;quot;add&amp;quot; operator in the other code segment, we have to reuse whole Class operator with the value &amp;quot;Add&amp;quot;. And if we want to add a new operation &amp;quot;Power&amp;quot;, we need to code in the implementation of Class Operator.&lt;br /&gt;
&lt;br /&gt;
== Idea of Polymorphism ==&lt;br /&gt;
Facing the problem of the conditional statement, people[2] come up with refactoring method called 'Polymorphism'. The idea of Polymorphism is to replace the highly functional relationship with the subclass override procedure under abstract class. So subclass is created to encapsulate each function in the conditional statement and the conditional relation is replaced by override a common abstract class. The advantage of such idea is to separate the functionality.    &lt;br /&gt;
&lt;br /&gt;
=== Definition of Polymorphism ===&lt;br /&gt;
According to [1], Subtype polymorphism, almost universally called just polymorphism in the context of object-oriented programming, is the ability of one type, A, to appear as and be used like another type, B. &lt;br /&gt;
&lt;br /&gt;
The primary usage of polymorphism in industry (object-oriented programming theory) is the ability of objects belonging to different types to respond to method, field, or property calls of the same name, each one according to an appropriate type-specific behavior. The programmer (and the program) does not have to know the exact type of the object in advance, and so the exact behavior is determined at run time.&lt;br /&gt;
&lt;br /&gt;
== Example of Refactoring Conditional Statement with Polymorphism ==&lt;br /&gt;
*Before refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Operator&lt;br /&gt;
{&lt;br /&gt;
    string operation;&lt;br /&gt;
&lt;br /&gt;
    public int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
         switch(operation)&lt;br /&gt;
         {&lt;br /&gt;
             case &amp;quot;Add&amp;quot;:&lt;br /&gt;
                 return x + y;&lt;br /&gt;
             case &amp;quot;Subtract&amp;quot;:&lt;br /&gt;
                 return x - y;&lt;br /&gt;
             case &amp;quot;Multiply&amp;quot;:&lt;br /&gt;
                 return x * y;&lt;br /&gt;
             case &amp;quot;Divide&amp;quot;:&lt;br /&gt;
                 return x / y;&lt;br /&gt;
             default:&lt;br /&gt;
                 throw new InvalidOperationException(&amp;quot;Unsupported operation&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*After refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public abstract class Operator&lt;br /&gt;
{&lt;br /&gt;
    public abstract int Execute(int x, int y)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class Add : Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x + y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Subtract : Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x - y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Multiply: Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x * y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Divide: Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x / y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] Polymorphism in object-oriented programming, http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming&lt;br /&gt;
&lt;br /&gt;
[2] Rene Santaolaya, Olivia G. Fragoso, Joaquín Pérez, Lorenzo Zambrano, Restructuring Conditional Code Structures Using Object Oriented Design Patterns, Lecture Notes in Computer Science. &lt;br /&gt;
&lt;br /&gt;
[3] The First Workshop on Refactoring, https://netfiles.uiuc.edu/dig/RefactoringWorkshop&lt;br /&gt;
&lt;br /&gt;
[4] Refactoring Tutorial for Ruby on Rails, http://www.good-tutorials.com/tutorials/ruby-on-rails/refactoring&lt;br /&gt;
&lt;br /&gt;
[5] Martin Fowler Refactoring: Improving the Design of Existing Code&lt;/div&gt;</summary>
		<author><name>Syi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_2_If_SJ&amp;diff=24415</id>
		<title>CSC/ECE 517 Fall 2009/wiki 2 If SJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_2_If_SJ&amp;diff=24415"/>
		<updated>2009-10-09T20:40:11Z</updated>

		<summary type="html">&lt;p&gt;Syi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Refactoring If Statement with Polymorphism.'''&lt;br /&gt;
&lt;br /&gt;
== Design Consideration: Reuse and Change ==&lt;br /&gt;
&lt;br /&gt;
One of the most important consideration of Object-Orientation Software Design is 'Reuse' and 'Change'. In terms of reuse, we mean to build the new software with the building block from the old software. The importance of 'change' is from the fact that the software is always changing to keep alive. So that how to effectively make change to the source code is critical for the software design.   &lt;br /&gt;
 &lt;br /&gt;
=== The Problem of If Statement ===&lt;br /&gt;
&lt;br /&gt;
Under the design consideration we have discussed, the problem of if statement is quite obvious: 1. the conditional relationship in function level prevent us to reuse each of the function separately. We can only reuse the whole application as a unit. 2. when we want to change the functionality of a certain function or add a new function we have to trace to every implementation code. Such change is expensive and violate the OO principle 'code to interface instead of implementation'.    &lt;br /&gt;
&lt;br /&gt;
=== Example of If statement ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Operator&lt;br /&gt;
{&lt;br /&gt;
    string operation;&lt;br /&gt;
&lt;br /&gt;
    public int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
         switch(operation)&lt;br /&gt;
         {&lt;br /&gt;
             case &amp;quot;Add&amp;quot;:&lt;br /&gt;
                 return x + y;&lt;br /&gt;
             case &amp;quot;Subtract&amp;quot;:&lt;br /&gt;
                 return x - y;&lt;br /&gt;
             case &amp;quot;Multiply&amp;quot;:&lt;br /&gt;
                 return x * y;&lt;br /&gt;
             case &amp;quot;Divide&amp;quot;:&lt;br /&gt;
                 return x / y;&lt;br /&gt;
             default:&lt;br /&gt;
                 throw new InvalidOperationException(&amp;quot;Unsupported operation&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In such example of conditional statement on operator, we see that: if we want to reuse function &amp;quot;add&amp;quot; operator in the other code segment, we have to reuse whole Class operator with the value &amp;quot;Add&amp;quot;. And if we want to add a new operation &amp;quot;Power&amp;quot;, we need to code in the implementation of Class Operator.&lt;br /&gt;
&lt;br /&gt;
== Idea of Polymorphism ==&lt;br /&gt;
Facing the problem of the conditional statement, people come up with refactoring method called 'Polymorphism'. The idea of Polymorphism is to replace the highly functional relationship with the subclass override procedure under abstract class. So subclass is created to encapsulate each function in the conditional statement and the conditional relation is replaced by override a common abstract class. The advantage of such idea is to separate the functionality.    &lt;br /&gt;
&lt;br /&gt;
=== Definition of Polymorphism ===&lt;br /&gt;
According to [1], Subtype polymorphism, almost universally called just polymorphism in the context of object-oriented programming, is the ability of one type, A, to appear as and be used like another type, B. &lt;br /&gt;
&lt;br /&gt;
The primary usage of polymorphism in industry (object-oriented programming theory) is the ability of objects belonging to different types to respond to method, field, or property calls of the same name, each one according to an appropriate type-specific behavior. The programmer (and the program) does not have to know the exact type of the object in advance, and so the exact behavior is determined at run time.&lt;br /&gt;
&lt;br /&gt;
== Example of Refactoring Conditional Statement with Polymorphism ==&lt;br /&gt;
*Before refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class Operator&lt;br /&gt;
{&lt;br /&gt;
    string operation;&lt;br /&gt;
&lt;br /&gt;
    public int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
         switch(operation)&lt;br /&gt;
         {&lt;br /&gt;
             case &amp;quot;Add&amp;quot;:&lt;br /&gt;
                 return x + y;&lt;br /&gt;
             case &amp;quot;Subtract&amp;quot;:&lt;br /&gt;
                 return x - y;&lt;br /&gt;
             case &amp;quot;Multiply&amp;quot;:&lt;br /&gt;
                 return x * y;&lt;br /&gt;
             case &amp;quot;Divide&amp;quot;:&lt;br /&gt;
                 return x / y;&lt;br /&gt;
             default:&lt;br /&gt;
                 throw new InvalidOperationException(&amp;quot;Unsupported operation&amp;quot;);&lt;br /&gt;
         }&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*After refactoring&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public abstract class Operator&lt;br /&gt;
{&lt;br /&gt;
    public abstract int Execute(int x, int y)&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public class Add : Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x + y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Subtract : Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x - y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Multiply: Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x * y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
public class Divide: Operator&lt;br /&gt;
{&lt;br /&gt;
    public override int Execute(int x, int y)&lt;br /&gt;
    {&lt;br /&gt;
        return x / y;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] Polymorphism in object-oriented programming, http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming&lt;br /&gt;
&lt;br /&gt;
[2] Code Refactoring Wiki, http://en.wikipedia.org/wiki/Code_refactoring.&lt;br /&gt;
&lt;br /&gt;
[3] The First Workshop on Refactoring, https://netfiles.uiuc.edu/dig/RefactoringWorkshop&lt;br /&gt;
&lt;br /&gt;
[4] Refactoring Tutorial for Ruby on Rails, http://www.good-tutorials.com/tutorials/ruby-on-rails/refactoring&lt;br /&gt;
&lt;br /&gt;
[5] Martin Fowler Refactoring: Improving the Design of Existing Code&lt;/div&gt;</summary>
		<author><name>Syi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_2_If_SJ&amp;diff=24391</id>
		<title>CSC/ECE 517 Fall 2009/wiki 2 If SJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_2_If_SJ&amp;diff=24391"/>
		<updated>2009-10-09T20:20:43Z</updated>

		<summary type="html">&lt;p&gt;Syi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Refactoring If Statement with Polymorphism.'''&lt;br /&gt;
&lt;br /&gt;
== Design Consideration: Reuse and Change ==&lt;br /&gt;
&lt;br /&gt;
One of the most important consideration of Object-Orientation Software Design is 'Reuse' and 'Change'. In terms of reuse, we mean to build the new software with the building block from the old software. The importance of 'change' is from the fact that the software is always changing to keep alive. So that how to effectively make change to the source code is critical for the software design.   &lt;br /&gt;
 &lt;br /&gt;
=== The Problem of If Statement ===&lt;br /&gt;
&lt;br /&gt;
Under the design consideration we have discussed, the problem of if statement is quite obvious: 1. the conditional relationship in function level prevent us to reuse each of the function separately. We can only reuse the whole application as a unit. 2. when we want to change the functionality of a certain function or add a new function we have to trace to every implementation code. Such change is expensive and violate the OO principle 'code to interface instead of implementation'.    &lt;br /&gt;
&lt;br /&gt;
=== Example of If statement ===&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class rename_method&lt;br /&gt;
{&lt;br /&gt;
    static void badRenameMethod()&lt;br /&gt;
    {&lt;br /&gt;
        System.out.println(&amp;quot;Hello, world!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Idea of Polymorphism ==&lt;br /&gt;
&lt;br /&gt;
=== Definition of Polymorphism ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Example of Refactoring Conditional Statement with Polymorphism ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] Thomas Corbat, Lukas Felber, Mirko Stocker Refactoring Support for the Eclipse Ruby Development Tools, Diploma Thesis, HSR University of Applied Sciences Rapperswil Institute for Software.&lt;br /&gt;
&lt;br /&gt;
[2] Code Refactoring Wiki, http://en.wikipedia.org/wiki/Code_refactoring.&lt;br /&gt;
&lt;br /&gt;
[3] The First Workshop on Refactoring, https://netfiles.uiuc.edu/dig/RefactoringWorkshop&lt;br /&gt;
&lt;br /&gt;
[4] Refactoring Tutorial for Ruby on Rails, http://www.good-tutorials.com/tutorials/ruby-on-rails/refactoring&lt;br /&gt;
&lt;br /&gt;
[5] Martin Fowler Refactoring: Improving the Design of Existing Code&lt;/div&gt;</summary>
		<author><name>Syi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_2_If_SJ&amp;diff=24338</id>
		<title>CSC/ECE 517 Fall 2009/wiki 2 If SJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_2_If_SJ&amp;diff=24338"/>
		<updated>2009-10-09T19:57:31Z</updated>

		<summary type="html">&lt;p&gt;Syi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Refactoring If Statement with Polymorphism.'''&lt;br /&gt;
&lt;br /&gt;
== Problem with If Statement ==&lt;br /&gt;
&lt;br /&gt;
According to the famous book &amp;quot;Refactoring: Improving the Design of Existing Code &amp;quot; by Martin Fowler: [5], refactoring is the process of applying behavior-preserving transformations to a program with the objective of improving the program’s design. Intuitively people refer to code refactoring as &amp;quot;cleaning it up.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Idea of Polymorphism ===&lt;br /&gt;
&lt;br /&gt;
Refactoring is very useful for software engineer to maintain the quality of their code in different environment. In fact, no software can be guaranteed to be perfect when it is first developed. Usually when the source code is applied to different customer needs, we want to improve the inner-structure without modify the external behavior. The ability to refactor your code takes the pressure off the design phase of software development. Refactoring gives you the ability to change the design of the code at a later stage. This means that you don’t have to get the design absolutely right before you write any code. You can get a rough design worked out, code it up and then if (when) you spot a better design you can refactor your code towards the better design.&lt;br /&gt;
&lt;br /&gt;
=== Example of Refactoring Conditional Statement with Polymorphism===&lt;br /&gt;
&lt;br /&gt;
In the following we list some popular refactoring to specify how refactoring transform the code. For more detail information, the reader please refer to the section 2.1.2 of the thesis of Thomas Corbat [1]. [1] provide Ruby example for each refactoring this list.   &lt;br /&gt;
  &lt;br /&gt;
{|&lt;br /&gt;
| 1. Merge Class Parts &lt;br /&gt;
|-&lt;br /&gt;
|	2. Convert Local Variable to Field &lt;br /&gt;
|-&lt;br /&gt;
|	3. Encapsulate Field &lt;br /&gt;
|-&lt;br /&gt;
|	4. Extract Method &lt;br /&gt;
|-&lt;br /&gt;
|	5. Inline Class &lt;br /&gt;
|-&lt;br /&gt;
|	6. Inline Method &lt;br /&gt;
|-&lt;br /&gt;
|	7. Move Field &lt;br /&gt;
|-&lt;br /&gt;
|	8. Move Method &lt;br /&gt;
|-&lt;br /&gt;
|	9. Rename Class &lt;br /&gt;
|-&lt;br /&gt;
|	10. Rename Field &lt;br /&gt;
|-&lt;br /&gt;
|	11. Rename Local Variable &lt;br /&gt;
|-&lt;br /&gt;
|	12. Rename Method &lt;br /&gt;
|-&lt;br /&gt;
|	13. Replace Temporary Variable with Query &lt;br /&gt;
|-&lt;br /&gt;
|	14. Split Temporary Variable &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Ruby Example of Refactoring ===&lt;br /&gt;
&lt;br /&gt;
*Before Rename:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def badRenameMethod&lt;br /&gt;
    puts(&amp;quot;Hello World&amp;quot;);&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*After Rename:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def hello&lt;br /&gt;
    puts(&amp;quot;Hello World&amp;quot;);&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Before Encapsulation:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class SomeClass&lt;br /&gt;
    def initialize&lt;br /&gt;
        @field = 0;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*After Encapsulation:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class SomeClass                &lt;br /&gt;
    def initialize&lt;br /&gt;
        @field = 0;&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    def field&lt;br /&gt;
        @field&lt;br /&gt;
    end&lt;br /&gt;
    private :field&lt;br /&gt;
    &lt;br /&gt;
    def field= field&lt;br /&gt;
        @field = field&lt;br /&gt;
    end&lt;br /&gt;
    private :field=&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Java Example of Refactoring ===&lt;br /&gt;
&lt;br /&gt;
*Before Rename:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class rename_method&lt;br /&gt;
{&lt;br /&gt;
    static void badRenameMethod()&lt;br /&gt;
    {&lt;br /&gt;
        System.out.println(&amp;quot;Hello, world!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*After Rename:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class rename_method&lt;br /&gt;
{&lt;br /&gt;
    static void hello()&lt;br /&gt;
    {&lt;br /&gt;
        System.out.println(&amp;quot;Hello, world!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Before Encapsulation:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class encap_field&lt;br /&gt;
{&lt;br /&gt;
    public String field;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*After Encapsulation:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class encap_field&lt;br /&gt;
{&lt;br /&gt;
    private int field;&lt;br /&gt;
&lt;br /&gt;
    public void setField(int field)&lt;br /&gt;
    {&lt;br /&gt;
        this.field = field;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public int getField()&lt;br /&gt;
    {&lt;br /&gt;
        return field;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Refactoring support for Current Ruby IDE ==&lt;br /&gt;
&lt;br /&gt;
This the following table we summary the current ruby IDE and their refactoring support situation. &lt;br /&gt;
{| &lt;br /&gt;
 | Current Ruby IDE || Refactoring Support (Y/N)&lt;br /&gt;
|-&lt;br /&gt;
 | [http://www.activestate.com/komodo/ ActiveState Komodo] || N&lt;br /&gt;
 |- &lt;br /&gt;
 | [http://www.netbeans.org/ NetBeans] || N&lt;br /&gt;
 |-&lt;br /&gt;
 | [http://www.ruby-ide.com/ruby/ruby_ide_and_ruby_editor.php Arachno Ruby] || N&lt;br /&gt;
|-&lt;br /&gt;
 | [http://freeride.rubyforge.org/wiki/wiki.pl FreeRIDE] || N&lt;br /&gt;
|-&lt;br /&gt;
 | [http://www.mondrian-ide.com/ Mondrian Ruby IDE] || N&lt;br /&gt;
|-&lt;br /&gt;
 | [http://www.sapphiresteel.com/ Ruby in Steel] || N&lt;br /&gt;
|-&lt;br /&gt;
 | [http://www.jetbrains.com/ruby/index.html RubyMine] || Y&lt;br /&gt;
|-&lt;br /&gt;
 | [http://www.eclipse.org/ Eclipse] ([http://aptana.com/ Aptana]) || Y  &lt;br /&gt;
 |}&lt;br /&gt;
&lt;br /&gt;
=== Example of Using Ruby Refactoring Tools in Eclipse ===&lt;br /&gt;
Here the renaming of the method &amp;quot;badRenameMethod&amp;quot; to &amp;quot;Hello&amp;quot; is illustrated for Ruby.  The source code is shown in section 1.3.&lt;br /&gt;
{|&lt;br /&gt;
| [[Image:r00.jpg|thumb|upright|The badly named method &amp;quot;badRenameMethod is shown with a call to this method.]]&lt;br /&gt;
| [[Image:r01.jpg|thumb|upright|The method is highlighted and then right clicked on.  Refactor then Rename is selected.]]&lt;br /&gt;
| [[Image:r02.jpg|thumb|upright|The method is renamed to &amp;quot;hello&amp;quot;]]&lt;br /&gt;
| [[Image:r03.jpg|thumb|upright|A preview of each call to the method.]]&lt;br /&gt;
| [[Image:r04.jpg|thumb|upright|The resulting code after refactoring is shown with newly renamed method.]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Here the encapsulation of the field &amp;quot;field&amp;quot; is illustrated for Ruby.  The source code is show in section 1.3.&lt;br /&gt;
{|&lt;br /&gt;
| [[Image:r05.jpg|thumb|upright|The field to be encapsulated is shown inside its class.]]&lt;br /&gt;
| [[Image:r06.jpg|thumb|upright|The field is highlighted and then right clicked on.  Refactor then Encapsulate Field is selected.]]&lt;br /&gt;
| [[Image:r07.jpg|thumb|upright|A reader and writer method is selected to be generated and labeled private.]]&lt;br /&gt;
| [[Image:r08.jpg|thumb|upright|A preview of the encapsulation.]]&lt;br /&gt;
| [[Image:r09.jpg|thumb|upright|The resulting code after refactoring is shown with encapsulated field.]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Example of Using Java Refactoring Tools in Eclipse ===&lt;br /&gt;
Here the renaming of the method &amp;quot;badRenameMethod&amp;quot; to &amp;quot;Hello&amp;quot; is illustrated for Java. The source code is show in section 1.4. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
| [[Image:j00.jpg|thumb|upright|The badly named method &amp;quot;badRenameMethod is shown.]]&lt;br /&gt;
| [[Image:j01.jpg|thumb|upright|The badly named method is called.]]&lt;br /&gt;
| [[Image:j02.jpg|thumb|upright|The method is highlighted and then right clicked on.  Refactor then Rename is selected.]]&lt;br /&gt;
| [[Image:j03.jpg|thumb|upright|The method is renamed to &amp;quot;hello&amp;quot; as shown and preview is selected.]]&lt;br /&gt;
| [[Image:j04.jpg|thumb|upright|A preview of each call to the method.]]&lt;br /&gt;
| [[Image:j05.jpg|thumb|upright|The resulting code after refactoring is shown with newly renamed method.  The call is shown here.]]&lt;br /&gt;
|}&lt;br /&gt;
Here the encapsulation of the field &amp;quot;field&amp;quot; is illustrated for Java. The source code is show in section 1.4.&lt;br /&gt;
 &lt;br /&gt;
{|&lt;br /&gt;
| [[Image:j06.jpg|thumb|upright|The field to be encapsulated is shown inside its class.]]&lt;br /&gt;
| [[Image:j07.jpg|thumb|upright|The field is highlighted and then right clicked on.  Refactor then Encapsulate Field is selected.]]&lt;br /&gt;
| [[Image:j08.jpg|thumb|upright|A getter(reader) and setter(writer) mehtod is selected and named.]]&lt;br /&gt;
| [[Image:j09.jpg|thumb|upright|The resulting code after refactoring is shown with encapsulated field.]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Comparison of Ruby and Java Refactoring Tools ==&lt;br /&gt;
&lt;br /&gt;
=== Comprehensiveness ===&lt;br /&gt;
&lt;br /&gt;
These are the following refactoring options available in eclipse for Ruby and Java.&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|'''Refactoring Options for Java in Eclipse'''  ||||  '''Refactoring Options for Ruby in Eclipse'''&lt;br /&gt;
|-&lt;br /&gt;
|Rename   || || Rename&lt;br /&gt;
|-&lt;br /&gt;
|Move || || Move&lt;br /&gt;
|-&lt;br /&gt;
|Change Method Signature || || Merge Class Parts in File&lt;br /&gt;
|-&lt;br /&gt;
|Extract Local Variable || || Pull Up&lt;br /&gt;
|-&lt;br /&gt;
|Extract Constant || || Pull Down&lt;br /&gt;
|-&lt;br /&gt;
|Inline || || Merge With External Class Parts&lt;br /&gt;
|-&lt;br /&gt;
|Convert Anonymous Class to Nested || || Split Local Variable&lt;br /&gt;
|-&lt;br /&gt;
|Convert Member to Top Level || || Merge With External Class Parts&lt;br /&gt;
|-&lt;br /&gt;
|Convert Local Variable to Field || || Inline&lt;br /&gt;
|-&lt;br /&gt;
|Extract Super Class || || Extract Constant&lt;br /&gt;
|-&lt;br /&gt;
|Extract Interface || || Encapsulate Field&lt;br /&gt;
|-&lt;br /&gt;
|Extract Class || || Convert Local Variable to Field&lt;br /&gt;
|-&lt;br /&gt;
|Use Supertype where possible&lt;br /&gt;
|-&lt;br /&gt;
|Pull Up &lt;br /&gt;
|-&lt;br /&gt;
|Pull Down &lt;br /&gt;
|-&lt;br /&gt;
|Introduce Parameter Object&lt;br /&gt;
|-&lt;br /&gt;
|Introduce Indirection&lt;br /&gt;
|-&lt;br /&gt;
|Introduce Factory&lt;br /&gt;
|-&lt;br /&gt;
|Introduce Parameter&lt;br /&gt;
|-&lt;br /&gt;
|Encapsulate Field&lt;br /&gt;
|-&lt;br /&gt;
|Generalize Declared Type&lt;br /&gt;
|-&lt;br /&gt;
|Infer Generic Type Arguments&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Ease of Use and Integrated Develop Environment(IDE) Integration ===&lt;br /&gt;
&lt;br /&gt;
The refactoring options for Ruby and Java cover all the basic refactorings.  The differences in the number of options mainly come from the difference in the two languages. Ruby is a [http://en.wikipedia.org/wiki/Type_system#Dynamic_typing dynamically typed language], has unbounded [http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming polymorphism], and all classes are open to extension or can be inherited.  On the other hand, Java is a [http://en.wikipedia.org/wiki/Type_system#Static_typing statically typed language], polymorphism is mainly implemented via [http://en.wikipedia.org/wiki/Interface_%28computer_science%29 interfaces] and [http://en.wikipedia.org/wiki/Implementation_inheritance inheritance], and classes cannot be extended at run-time.  The given examples (in section [http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki_1a_9b_SJ#Ruby_Example_of_Refactoring [1.3]], [http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki_1a_9b_SJ#Java_Example_of_Refactoring [1.4]]) illustrate the ease of use of the refactoring tools for both Ruby and Java and how well these tools are integrated into the Eclipse IDE.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] Thomas Corbat, Lukas Felber, Mirko Stocker Refactoring Support for the Eclipse Ruby Development Tools, Diploma Thesis, HSR University of Applied Sciences Rapperswil Institute for Software.&lt;br /&gt;
&lt;br /&gt;
[2] Code Refactoring Wiki, http://en.wikipedia.org/wiki/Code_refactoring.&lt;br /&gt;
&lt;br /&gt;
[3] The First Workshop on Refactoring, https://netfiles.uiuc.edu/dig/RefactoringWorkshop&lt;br /&gt;
&lt;br /&gt;
[4] Refactoring Tutorial for Ruby on Rails, http://www.good-tutorials.com/tutorials/ruby-on-rails/refactoring&lt;br /&gt;
&lt;br /&gt;
[5] Martin Fowler Refactoring: Improving the Design of Existing Code&lt;/div&gt;</summary>
		<author><name>Syi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_2_If_SJ&amp;diff=24328</id>
		<title>CSC/ECE 517 Fall 2009/wiki 2 If SJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_2_If_SJ&amp;diff=24328"/>
		<updated>2009-10-09T19:54:38Z</updated>

		<summary type="html">&lt;p&gt;Syi: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Refactoring tools for Ruby and Ruby on Rails.'''&lt;br /&gt;
&lt;br /&gt;
== What is Code Refactoring ==&lt;br /&gt;
&lt;br /&gt;
According to the famous book &amp;quot;Refactoring: Improving the Design of Existing Code &amp;quot; by Martin Fowler: [5], refactoring is the process of applying behavior-preserving transformations to a program with the objective of improving the program’s design. Intuitively people refer to code refactoring as &amp;quot;cleaning it up.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Motivation of Refactoring ===&lt;br /&gt;
&lt;br /&gt;
Refactoring is very useful for software engineer to maintain the quality of their code in different environment. In fact, no software can be guaranteed to be perfect when it is first developed. Usually when the source code is applied to different customer needs, we want to improve the inner-structure without modify the external behavior. The ability to refactor your code takes the pressure off the design phase of software development. Refactoring gives you the ability to change the design of the code at a later stage. This means that you don’t have to get the design absolutely right before you write any code. You can get a rough design worked out, code it up and then if (when) you spot a better design you can refactor your code towards the better design.&lt;br /&gt;
&lt;br /&gt;
=== List of Common Refactorings ===&lt;br /&gt;
&lt;br /&gt;
In the following we list some popular refactoring to specify how refactoring transform the code. For more detail information, the reader please refer to the section 2.1.2 of the thesis of Thomas Corbat [1]. [1] provide Ruby example for each refactoring this list.   &lt;br /&gt;
  &lt;br /&gt;
{|&lt;br /&gt;
| 1. Merge Class Parts &lt;br /&gt;
|-&lt;br /&gt;
|	2. Convert Local Variable to Field &lt;br /&gt;
|-&lt;br /&gt;
|	3. Encapsulate Field &lt;br /&gt;
|-&lt;br /&gt;
|	4. Extract Method &lt;br /&gt;
|-&lt;br /&gt;
|	5. Inline Class &lt;br /&gt;
|-&lt;br /&gt;
|	6. Inline Method &lt;br /&gt;
|-&lt;br /&gt;
|	7. Move Field &lt;br /&gt;
|-&lt;br /&gt;
|	8. Move Method &lt;br /&gt;
|-&lt;br /&gt;
|	9. Rename Class &lt;br /&gt;
|-&lt;br /&gt;
|	10. Rename Field &lt;br /&gt;
|-&lt;br /&gt;
|	11. Rename Local Variable &lt;br /&gt;
|-&lt;br /&gt;
|	12. Rename Method &lt;br /&gt;
|-&lt;br /&gt;
|	13. Replace Temporary Variable with Query &lt;br /&gt;
|-&lt;br /&gt;
|	14. Split Temporary Variable &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Ruby Example of Refactoring ===&lt;br /&gt;
&lt;br /&gt;
*Before Rename:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def badRenameMethod&lt;br /&gt;
    puts(&amp;quot;Hello World&amp;quot;);&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*After Rename:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
def hello&lt;br /&gt;
    puts(&amp;quot;Hello World&amp;quot;);&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Before Encapsulation:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class SomeClass&lt;br /&gt;
    def initialize&lt;br /&gt;
        @field = 0;&lt;br /&gt;
    end&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*After Encapsulation:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
class SomeClass                &lt;br /&gt;
    def initialize&lt;br /&gt;
        @field = 0;&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    def field&lt;br /&gt;
        @field&lt;br /&gt;
    end&lt;br /&gt;
    private :field&lt;br /&gt;
    &lt;br /&gt;
    def field= field&lt;br /&gt;
        @field = field&lt;br /&gt;
    end&lt;br /&gt;
    private :field=&lt;br /&gt;
end&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Java Example of Refactoring ===&lt;br /&gt;
&lt;br /&gt;
*Before Rename:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class rename_method&lt;br /&gt;
{&lt;br /&gt;
    static void badRenameMethod()&lt;br /&gt;
    {&lt;br /&gt;
        System.out.println(&amp;quot;Hello, world!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*After Rename:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class rename_method&lt;br /&gt;
{&lt;br /&gt;
    static void hello()&lt;br /&gt;
    {&lt;br /&gt;
        System.out.println(&amp;quot;Hello, world!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*Before Encapsulation:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class encap_field&lt;br /&gt;
{&lt;br /&gt;
    public String field;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
*After Encapsulation:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
public class encap_field&lt;br /&gt;
{&lt;br /&gt;
    private int field;&lt;br /&gt;
&lt;br /&gt;
    public void setField(int field)&lt;br /&gt;
    {&lt;br /&gt;
        this.field = field;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public int getField()&lt;br /&gt;
    {&lt;br /&gt;
        return field;&lt;br /&gt;
    }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Refactoring support for Current Ruby IDE ==&lt;br /&gt;
&lt;br /&gt;
This the following table we summary the current ruby IDE and their refactoring support situation. &lt;br /&gt;
{| &lt;br /&gt;
 | Current Ruby IDE || Refactoring Support (Y/N)&lt;br /&gt;
|-&lt;br /&gt;
 | [http://www.activestate.com/komodo/ ActiveState Komodo] || N&lt;br /&gt;
 |- &lt;br /&gt;
 | [http://www.netbeans.org/ NetBeans] || N&lt;br /&gt;
 |-&lt;br /&gt;
 | [http://www.ruby-ide.com/ruby/ruby_ide_and_ruby_editor.php Arachno Ruby] || N&lt;br /&gt;
|-&lt;br /&gt;
 | [http://freeride.rubyforge.org/wiki/wiki.pl FreeRIDE] || N&lt;br /&gt;
|-&lt;br /&gt;
 | [http://www.mondrian-ide.com/ Mondrian Ruby IDE] || N&lt;br /&gt;
|-&lt;br /&gt;
 | [http://www.sapphiresteel.com/ Ruby in Steel] || N&lt;br /&gt;
|-&lt;br /&gt;
 | [http://www.jetbrains.com/ruby/index.html RubyMine] || Y&lt;br /&gt;
|-&lt;br /&gt;
 | [http://www.eclipse.org/ Eclipse] ([http://aptana.com/ Aptana]) || Y  &lt;br /&gt;
 |}&lt;br /&gt;
&lt;br /&gt;
=== Example of Using Ruby Refactoring Tools in Eclipse ===&lt;br /&gt;
Here the renaming of the method &amp;quot;badRenameMethod&amp;quot; to &amp;quot;Hello&amp;quot; is illustrated for Ruby.  The source code is shown in section 1.3.&lt;br /&gt;
{|&lt;br /&gt;
| [[Image:r00.jpg|thumb|upright|The badly named method &amp;quot;badRenameMethod is shown with a call to this method.]]&lt;br /&gt;
| [[Image:r01.jpg|thumb|upright|The method is highlighted and then right clicked on.  Refactor then Rename is selected.]]&lt;br /&gt;
| [[Image:r02.jpg|thumb|upright|The method is renamed to &amp;quot;hello&amp;quot;]]&lt;br /&gt;
| [[Image:r03.jpg|thumb|upright|A preview of each call to the method.]]&lt;br /&gt;
| [[Image:r04.jpg|thumb|upright|The resulting code after refactoring is shown with newly renamed method.]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Here the encapsulation of the field &amp;quot;field&amp;quot; is illustrated for Ruby.  The source code is show in section 1.3.&lt;br /&gt;
{|&lt;br /&gt;
| [[Image:r05.jpg|thumb|upright|The field to be encapsulated is shown inside its class.]]&lt;br /&gt;
| [[Image:r06.jpg|thumb|upright|The field is highlighted and then right clicked on.  Refactor then Encapsulate Field is selected.]]&lt;br /&gt;
| [[Image:r07.jpg|thumb|upright|A reader and writer method is selected to be generated and labeled private.]]&lt;br /&gt;
| [[Image:r08.jpg|thumb|upright|A preview of the encapsulation.]]&lt;br /&gt;
| [[Image:r09.jpg|thumb|upright|The resulting code after refactoring is shown with encapsulated field.]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Example of Using Java Refactoring Tools in Eclipse ===&lt;br /&gt;
Here the renaming of the method &amp;quot;badRenameMethod&amp;quot; to &amp;quot;Hello&amp;quot; is illustrated for Java. The source code is show in section 1.4. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
| [[Image:j00.jpg|thumb|upright|The badly named method &amp;quot;badRenameMethod is shown.]]&lt;br /&gt;
| [[Image:j01.jpg|thumb|upright|The badly named method is called.]]&lt;br /&gt;
| [[Image:j02.jpg|thumb|upright|The method is highlighted and then right clicked on.  Refactor then Rename is selected.]]&lt;br /&gt;
| [[Image:j03.jpg|thumb|upright|The method is renamed to &amp;quot;hello&amp;quot; as shown and preview is selected.]]&lt;br /&gt;
| [[Image:j04.jpg|thumb|upright|A preview of each call to the method.]]&lt;br /&gt;
| [[Image:j05.jpg|thumb|upright|The resulting code after refactoring is shown with newly renamed method.  The call is shown here.]]&lt;br /&gt;
|}&lt;br /&gt;
Here the encapsulation of the field &amp;quot;field&amp;quot; is illustrated for Java. The source code is show in section 1.4.&lt;br /&gt;
 &lt;br /&gt;
{|&lt;br /&gt;
| [[Image:j06.jpg|thumb|upright|The field to be encapsulated is shown inside its class.]]&lt;br /&gt;
| [[Image:j07.jpg|thumb|upright|The field is highlighted and then right clicked on.  Refactor then Encapsulate Field is selected.]]&lt;br /&gt;
| [[Image:j08.jpg|thumb|upright|A getter(reader) and setter(writer) mehtod is selected and named.]]&lt;br /&gt;
| [[Image:j09.jpg|thumb|upright|The resulting code after refactoring is shown with encapsulated field.]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Comparison of Ruby and Java Refactoring Tools ==&lt;br /&gt;
&lt;br /&gt;
=== Comprehensiveness ===&lt;br /&gt;
&lt;br /&gt;
These are the following refactoring options available in eclipse for Ruby and Java.&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|'''Refactoring Options for Java in Eclipse'''  ||||  '''Refactoring Options for Ruby in Eclipse'''&lt;br /&gt;
|-&lt;br /&gt;
|Rename   || || Rename&lt;br /&gt;
|-&lt;br /&gt;
|Move || || Move&lt;br /&gt;
|-&lt;br /&gt;
|Change Method Signature || || Merge Class Parts in File&lt;br /&gt;
|-&lt;br /&gt;
|Extract Local Variable || || Pull Up&lt;br /&gt;
|-&lt;br /&gt;
|Extract Constant || || Pull Down&lt;br /&gt;
|-&lt;br /&gt;
|Inline || || Merge With External Class Parts&lt;br /&gt;
|-&lt;br /&gt;
|Convert Anonymous Class to Nested || || Split Local Variable&lt;br /&gt;
|-&lt;br /&gt;
|Convert Member to Top Level || || Merge With External Class Parts&lt;br /&gt;
|-&lt;br /&gt;
|Convert Local Variable to Field || || Inline&lt;br /&gt;
|-&lt;br /&gt;
|Extract Super Class || || Extract Constant&lt;br /&gt;
|-&lt;br /&gt;
|Extract Interface || || Encapsulate Field&lt;br /&gt;
|-&lt;br /&gt;
|Extract Class || || Convert Local Variable to Field&lt;br /&gt;
|-&lt;br /&gt;
|Use Supertype where possible&lt;br /&gt;
|-&lt;br /&gt;
|Pull Up &lt;br /&gt;
|-&lt;br /&gt;
|Pull Down &lt;br /&gt;
|-&lt;br /&gt;
|Introduce Parameter Object&lt;br /&gt;
|-&lt;br /&gt;
|Introduce Indirection&lt;br /&gt;
|-&lt;br /&gt;
|Introduce Factory&lt;br /&gt;
|-&lt;br /&gt;
|Introduce Parameter&lt;br /&gt;
|-&lt;br /&gt;
|Encapsulate Field&lt;br /&gt;
|-&lt;br /&gt;
|Generalize Declared Type&lt;br /&gt;
|-&lt;br /&gt;
|Infer Generic Type Arguments&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Ease of Use and Integrated Develop Environment(IDE) Integration ===&lt;br /&gt;
&lt;br /&gt;
The refactoring options for Ruby and Java cover all the basic refactorings.  The differences in the number of options mainly come from the difference in the two languages. Ruby is a [http://en.wikipedia.org/wiki/Type_system#Dynamic_typing dynamically typed language], has unbounded [http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming polymorphism], and all classes are open to extension or can be inherited.  On the other hand, Java is a [http://en.wikipedia.org/wiki/Type_system#Static_typing statically typed language], polymorphism is mainly implemented via [http://en.wikipedia.org/wiki/Interface_%28computer_science%29 interfaces] and [http://en.wikipedia.org/wiki/Implementation_inheritance inheritance], and classes cannot be extended at run-time.  The given examples (in section [http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki_1a_9b_SJ#Ruby_Example_of_Refactoring [1.3]], [http://pg-server.csc.ncsu.edu/mediawiki/index.php/CSC/ECE_517_Fall_2009/wiki_1a_9b_SJ#Java_Example_of_Refactoring [1.4]]) illustrate the ease of use of the refactoring tools for both Ruby and Java and how well these tools are integrated into the Eclipse IDE.&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
[1] Thomas Corbat, Lukas Felber, Mirko Stocker Refactoring Support for the Eclipse Ruby Development Tools, Diploma Thesis, HSR University of Applied Sciences Rapperswil Institute for Software.&lt;br /&gt;
&lt;br /&gt;
[2] Code Refactoring Wiki, http://en.wikipedia.org/wiki/Code_refactoring.&lt;br /&gt;
&lt;br /&gt;
[3] The First Workshop on Refactoring, https://netfiles.uiuc.edu/dig/RefactoringWorkshop&lt;br /&gt;
&lt;br /&gt;
[4] Refactoring Tutorial for Ruby on Rails, http://www.good-tutorials.com/tutorials/ruby-on-rails/refactoring&lt;br /&gt;
&lt;br /&gt;
[5] Martin Fowler Refactoring: Improving the Design of Existing Code&lt;/div&gt;</summary>
		<author><name>Syi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_1a_9b_SJ&amp;diff=19124</id>
		<title>CSC/ECE 517 Fall 2009/wiki 1a 9b SJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_1a_9b_SJ&amp;diff=19124"/>
		<updated>2009-09-12T21:50:23Z</updated>

		<summary type="html">&lt;p&gt;Syi: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Code Refactoring ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
According to the famous book &amp;quot;Refactoring: Improving the Design of Existing Code &amp;quot; by Martin Fowler: Refactoring is the process of applying behavior-preserving transformations &lt;br /&gt;
to a program with the objective of improving the program’s design. Intuitively people refer to code refactoring as &amp;quot;cleaning it up.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Motivation of Refactoring ===&lt;br /&gt;
&lt;br /&gt;
Refactoring is very useful for software engineer to maintain the quality of their code in different environment. In fact, no software can be guaranteed to be perfect when it is first developed. &lt;br /&gt;
Usually when the source code is applied to different customer needs, we want to improve the inner-structure without modify the external behavior. The ability to refactor your code takes &lt;br /&gt;
the pressure off the design phase of software development. Refactoring gives you the ability to change the design of the code at a later stage. This means that you don’t have to get the&lt;br /&gt;
design absolutely right before you write any code. You can get a rough design worked out, code it up and then if (when) you spot a better design you can refactor your code towards the &lt;br /&gt;
better design.&lt;br /&gt;
&lt;br /&gt;
=== List of Common Refactorings ===&lt;br /&gt;
&lt;br /&gt;
In the following we list some popular refactoring to specify how refactoring transform the code. For more detail information, the reader please refer to the section 2.1.2 of the &lt;br /&gt;
thesis of Thomas Corbat[1]. [1] provide Ruby example for each refactoring this list.   &lt;br /&gt;
  &lt;br /&gt;
{|&lt;br /&gt;
| 1. Merge Class Parts &lt;br /&gt;
|-&lt;br /&gt;
|	2. Convert Local Variable to Field &lt;br /&gt;
|-&lt;br /&gt;
|	3. Encapsulate Field &lt;br /&gt;
|-&lt;br /&gt;
|	4. Extract Method &lt;br /&gt;
|-&lt;br /&gt;
|	5. Inline Class &lt;br /&gt;
|-&lt;br /&gt;
|	6. Inline Method &lt;br /&gt;
|-&lt;br /&gt;
|	7. Move Field &lt;br /&gt;
|-&lt;br /&gt;
|	8. Move Method &lt;br /&gt;
|-&lt;br /&gt;
|	9. Rename Class &lt;br /&gt;
|-&lt;br /&gt;
|	10. Rename Field &lt;br /&gt;
|-&lt;br /&gt;
|	11. Rename Local Variable &lt;br /&gt;
|-&lt;br /&gt;
|	12. Rename Method &lt;br /&gt;
|-&lt;br /&gt;
|	13. Replace Temporary Variable with Query &lt;br /&gt;
|-&lt;br /&gt;
|	14. Split Temporary Variable &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Ruby Example of Refactoring ===&lt;br /&gt;
&lt;br /&gt;
before rename:&lt;br /&gt;
&lt;br /&gt;
 def badRenameMethod&lt;br /&gt;
    puts(&amp;quot;Hello World&amp;quot;);&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
after rename:&lt;br /&gt;
&lt;br /&gt;
 def hello&lt;br /&gt;
    puts(&amp;quot;Hello World&amp;quot;);&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
before encapsulation:&lt;br /&gt;
 &lt;br /&gt;
 class SomeClass&lt;br /&gt;
    def initialize&lt;br /&gt;
        @field = 0;&lt;br /&gt;
    end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
after encapsulation:&lt;br /&gt;
&lt;br /&gt;
 class SomeClass                &lt;br /&gt;
    def initialize&lt;br /&gt;
        @field = 0;&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    def field&lt;br /&gt;
        @field&lt;br /&gt;
    end&lt;br /&gt;
    private :field&lt;br /&gt;
    &lt;br /&gt;
    def field= field&lt;br /&gt;
        @field = field&lt;br /&gt;
    end&lt;br /&gt;
    private :field=&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
=== Java Example of Refactoring ===&lt;br /&gt;
&lt;br /&gt;
before rename:&lt;br /&gt;
&lt;br /&gt;
 public class rename_method&lt;br /&gt;
 {&lt;br /&gt;
    static void badRenameMethod()&lt;br /&gt;
    {&lt;br /&gt;
        System.out.println(&amp;quot;Hello, world!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
after rename:&lt;br /&gt;
&lt;br /&gt;
 public class rename_method&lt;br /&gt;
 {&lt;br /&gt;
    static void hello()&lt;br /&gt;
    {&lt;br /&gt;
        System.out.println(&amp;quot;Hello, world!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
before encapsulation:&lt;br /&gt;
&lt;br /&gt;
 public class encap_field&lt;br /&gt;
 {&lt;br /&gt;
    public String field;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
after encapsulation:&lt;br /&gt;
&lt;br /&gt;
 public class encap_field&lt;br /&gt;
 {&lt;br /&gt;
    private int field;&lt;br /&gt;
&lt;br /&gt;
    public void setField(int field)&lt;br /&gt;
    {&lt;br /&gt;
        this.field = field;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public int getField()&lt;br /&gt;
    {&lt;br /&gt;
        return field;&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Refactoring support for Current Ruby IDE ==&lt;br /&gt;
&lt;br /&gt;
This the following table we summary the current ruby IDE and their refactoring support situation. &lt;br /&gt;
{| &lt;br /&gt;
 | Current Ruby IDE || Refactoring Support (Y/N)&lt;br /&gt;
|-&lt;br /&gt;
 | ActiveState Komodo  || N&lt;br /&gt;
 |- &lt;br /&gt;
 | NetBeans || N&lt;br /&gt;
 |-&lt;br /&gt;
 | Arachno Ruby ||  N&lt;br /&gt;
|-&lt;br /&gt;
 | FreeRIDE || N&lt;br /&gt;
|-&lt;br /&gt;
 | Mondrian Ruby IDE || N&lt;br /&gt;
|-&lt;br /&gt;
 | Ruby in Steel || N&lt;br /&gt;
|-&lt;br /&gt;
 | RubyMine || Y&lt;br /&gt;
|-&lt;br /&gt;
 | Eclipse (Aptana) || Y  &lt;br /&gt;
 |}&lt;br /&gt;
&lt;br /&gt;
=== Example of Using Ruby Refactoring Tools in Eclipse ===&lt;br /&gt;
Here the renaming of the method &amp;quot;badRenameMethod&amp;quot; to &amp;quot;Hello&amp;quot; is illustrated for Ruby.  The source code is shown in section 1.3.&lt;br /&gt;
{|&lt;br /&gt;
| [[Image:r00.jpg|thumb|upright|alt= rename step 1]]&lt;br /&gt;
| [[Image:r01.jpg|thumb|upright|alt= rename step 2]]&lt;br /&gt;
| [[Image:r02.jpg|thumb|upright|alt= rename step 3]]&lt;br /&gt;
| [[Image:r03.jpg|thumb|upright|alt= rename step 4]]&lt;br /&gt;
| [[Image:r04.jpg|thumb|upright|alt= rename step 5]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Here the encapsulation of the field &amp;quot;field&amp;quot; is illustrated for Ruby.  The source code is show in section 1.3.&lt;br /&gt;
{|&lt;br /&gt;
| [[Image:r05.jpg|thumb|upright|alt= encapsulation step 1]]&lt;br /&gt;
| [[Image:r06.jpg|thumb|upright|alt= encapsulation step 2]]&lt;br /&gt;
| [[Image:r07.jpg|thumb|upright|alt= encapsulation step 3]]&lt;br /&gt;
| [[Image:r08.jpg|thumb|upright|alt= encapsulation step 4]]&lt;br /&gt;
| [[Image:r09.jpg|thumb|upright|alt= encapsulation step 5]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Example of Using Java Refactoring Tools in Eclipse ===&lt;br /&gt;
Here the renaming of the method &amp;quot;badRenameMethod&amp;quot; to &amp;quot;Hello&amp;quot; is illustrated for Java. The source code is show in section 1.4. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
| [[Image:j00.jpg|thumb|upright|alt= rename step 1]]&lt;br /&gt;
| [[Image:j01.jpg|thumb|upright|alt= rename step 2]]&lt;br /&gt;
| [[Image:j02.jpg|thumb|upright|alt= rename step 3]]&lt;br /&gt;
| [[Image:j03.jpg|thumb|upright|alt= rename step 4]]&lt;br /&gt;
| [[Image:j04.jpg|thumb|upright|alt= rename step 5]]&lt;br /&gt;
| [[Image:j05.jpg|thumb|upright|alt= rename step 6]]&lt;br /&gt;
|}&lt;br /&gt;
Here the encapsulation of the field &amp;quot;field&amp;quot; is illustrated for Java. The source code is show in section 1.4.&lt;br /&gt;
 &lt;br /&gt;
{|&lt;br /&gt;
| [[Image:j06.jpg|thumb|upright|alt= encapsulation step 1]]&lt;br /&gt;
| [[Image:j07.jpg|thumb|upright|alt= encapsulation step 2]]&lt;br /&gt;
| [[Image:j08.jpg|thumb|upright|alt= encapsulation step 3]]&lt;br /&gt;
| [[Image:j09.jpg|thumb|upright|alt= encapsulation step 4]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Comparison of Ruby and Java Refactoring Tools ==&lt;br /&gt;
Comprehensiveness comparison:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|1. Refactoring Options for Java in Eclipse  ||||  2. Refactoring Options in Eclipse for Ruby&lt;br /&gt;
|-&lt;br /&gt;
|Rename   || || Rename&lt;br /&gt;
|-&lt;br /&gt;
|Move || || Move&lt;br /&gt;
|-&lt;br /&gt;
|Change Method Signature || || Merge Class Parts in File&lt;br /&gt;
|-&lt;br /&gt;
|Extract Local Variable || || Pull Up&lt;br /&gt;
|-&lt;br /&gt;
|Extract Constant || || Pull Down&lt;br /&gt;
|-&lt;br /&gt;
|Inline || || Merge With External Class Parts&lt;br /&gt;
|-&lt;br /&gt;
|Convert Anonymous Class to Nested || || Split Local Variable&lt;br /&gt;
|-&lt;br /&gt;
|Convert Member to Top Level || || Merge With External Class Parts&lt;br /&gt;
|-&lt;br /&gt;
|Convert Local Variable to Field || || Inline&lt;br /&gt;
|-&lt;br /&gt;
|Extract Super Class || || Extract Constant&lt;br /&gt;
|-&lt;br /&gt;
|Extract Interface || || Encapsulate Field&lt;br /&gt;
|-&lt;br /&gt;
|Extract Class || || Convert Local Variable to Field&lt;br /&gt;
|-&lt;br /&gt;
|Use Supertype where possible&lt;br /&gt;
|-&lt;br /&gt;
|Pull Up &lt;br /&gt;
|-&lt;br /&gt;
|Pull Down &lt;br /&gt;
|-&lt;br /&gt;
|Introduce Parameter Object&lt;br /&gt;
|-&lt;br /&gt;
|Introduce Indirection&lt;br /&gt;
|-&lt;br /&gt;
|Introduce Factory&lt;br /&gt;
|-&lt;br /&gt;
|Introduce Parameter&lt;br /&gt;
|-&lt;br /&gt;
|Encapsulate Field&lt;br /&gt;
|-&lt;br /&gt;
|Generalize Declared Type&lt;br /&gt;
|-&lt;br /&gt;
|Infer Generic Type Arguments&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The refactoring options for Ruby and Java cover all the basic refactorings.  The differences in the number of options mainly come from the difference in the two languages. &lt;br /&gt;
 Ruby is a dynamically typed language, has unbounded polymorphism, and all classes are open to extension.  On the other hand, Java is a statically typed language, &lt;br /&gt;
polymorphism is mainly implemented via interfaces and inheritance, and classes cannot be extended at runtime.  The given examples (in section 1.3, 1.4)&lt;br /&gt;
 illustrate the ease of use of the refactoring tools for both Ruby and Java and how well these tools are integrated into the Eclipse IDE.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[1] Thomas Corbat, Lukas Felber, Mirko Stocker&lt;br /&gt;
Refactoring Support for the Eclipse Ruby Development Tools, Diploma Thesis, HSR University of Applied Sciences Rapperswil Institute for Software.&lt;br /&gt;
&lt;br /&gt;
[2] code refactoring wiki, http://en.wikipedia.org/wiki/Code_refactoring&lt;br /&gt;
&lt;br /&gt;
[3] the first workshop on refactoring, https://netfiles.uiuc.edu/dig/RefactoringWorkshop&lt;br /&gt;
&lt;br /&gt;
[4] refactoring tutorial on ruby on rail, http://www.good-tutorials.com/tutorials/ruby-on-rails/refactoring&lt;/div&gt;</summary>
		<author><name>Syi</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_1a_9b_SJ&amp;diff=19117</id>
		<title>CSC/ECE 517 Fall 2009/wiki 1a 9b SJ</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki_1a_9b_SJ&amp;diff=19117"/>
		<updated>2009-09-12T21:15:18Z</updated>

		<summary type="html">&lt;p&gt;Syi: /* What is Code Refactoring */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== What is Code Refactoring ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
According to the famous book &amp;quot;Refactoring: Improving the Design of Existing Code &amp;quot; by Martin Fowler: Refactoring is the process of applying behavior-preserving transformations &lt;br /&gt;
to a program with the objective of improving the program’s design. Intuitively people refer to code refactoring as &amp;quot;cleaning it up.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Motivation of Refactoring ===&lt;br /&gt;
&lt;br /&gt;
Refactoring is very useful for software engineer to maintain the quality of their code in different environment. In fact, no software can be guaranteed to be perfect when it is first developed. &lt;br /&gt;
Usually when the source code is applied to different customer needs, we want to improve the inner-structure without modify the external behavior. The ability to refactor your code takes &lt;br /&gt;
the pressure off the design phase of software development. Refactoring gives you the ability to change the design of the code at a later stage. This means that you don’t have to get the&lt;br /&gt;
design absolutely right before you write any code. You can get a rough design worked out, code it up and then if (when) you spot a better design you can refactor your code towards the &lt;br /&gt;
better design.&lt;br /&gt;
&lt;br /&gt;
=== List of Common Refactorings ===&lt;br /&gt;
&lt;br /&gt;
In the following we list some popular refactoring to specify how refactoring transform the code. For more detail information, the reader please refer to the section 2.1.2 of the &lt;br /&gt;
thesis of Thomas Corbat[1]. [1] provide Ruby example for each refactoring this list.   &lt;br /&gt;
  &lt;br /&gt;
{|&lt;br /&gt;
| 1. Merge Class Parts &lt;br /&gt;
|-&lt;br /&gt;
|	2. Convert Local Variable to Field &lt;br /&gt;
|-&lt;br /&gt;
|	3. Encapsulate Field &lt;br /&gt;
|-&lt;br /&gt;
|	4. Extract Method &lt;br /&gt;
|-&lt;br /&gt;
|	5. Inline Class &lt;br /&gt;
|-&lt;br /&gt;
|	6. Inline Method &lt;br /&gt;
|-&lt;br /&gt;
|	7. Move Field &lt;br /&gt;
|-&lt;br /&gt;
|	8. Move Method &lt;br /&gt;
|-&lt;br /&gt;
|	9. Rename Class &lt;br /&gt;
|-&lt;br /&gt;
|	10. Rename Field &lt;br /&gt;
|-&lt;br /&gt;
|	11. Rename Local Variable &lt;br /&gt;
|-&lt;br /&gt;
|	12. Rename Method &lt;br /&gt;
|-&lt;br /&gt;
|	13. Replace Temporary Variable with Query &lt;br /&gt;
|-&lt;br /&gt;
|	14. Split Temporary Variable &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Ruby Example of Refactoring ===&lt;br /&gt;
&lt;br /&gt;
before rename:&lt;br /&gt;
&lt;br /&gt;
 def badRenameMethod&lt;br /&gt;
    puts(&amp;quot;Hello World&amp;quot;);&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
after rename:&lt;br /&gt;
&lt;br /&gt;
 def hello&lt;br /&gt;
    puts(&amp;quot;Hello World&amp;quot;);&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
before encapsulation:&lt;br /&gt;
 &lt;br /&gt;
 class SomeClass&lt;br /&gt;
    def initialize&lt;br /&gt;
        @field = 0;&lt;br /&gt;
    end&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
after encapsulation:&lt;br /&gt;
&lt;br /&gt;
 class SomeClass                &lt;br /&gt;
    def initialize&lt;br /&gt;
        @field = 0;&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    def field&lt;br /&gt;
        @field&lt;br /&gt;
    end&lt;br /&gt;
    private :field&lt;br /&gt;
    &lt;br /&gt;
    def field= field&lt;br /&gt;
        @field = field&lt;br /&gt;
    end&lt;br /&gt;
    private :field=&lt;br /&gt;
 end&lt;br /&gt;
&lt;br /&gt;
=== Java Example of Refactoring ===&lt;br /&gt;
&lt;br /&gt;
before rename:&lt;br /&gt;
&lt;br /&gt;
 public class rename_method&lt;br /&gt;
 {&lt;br /&gt;
    static void badRenameMethod()&lt;br /&gt;
    {&lt;br /&gt;
        System.out.println(&amp;quot;Hello, world!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
after rename:&lt;br /&gt;
&lt;br /&gt;
 public class rename_method&lt;br /&gt;
 {&lt;br /&gt;
    static void hello()&lt;br /&gt;
    {&lt;br /&gt;
        System.out.println(&amp;quot;Hello, world!&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
before encapsulation:&lt;br /&gt;
&lt;br /&gt;
 public class encap_field&lt;br /&gt;
 {&lt;br /&gt;
    public String field;&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
after encapsulation:&lt;br /&gt;
&lt;br /&gt;
 public class encap_field&lt;br /&gt;
 {&lt;br /&gt;
    private int field;&lt;br /&gt;
&lt;br /&gt;
    public void setField(int field)&lt;br /&gt;
    {&lt;br /&gt;
        this.field = field;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    public int getField()&lt;br /&gt;
    {&lt;br /&gt;
        return field;&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
== Refactoring support for Current Ruby IDE ==&lt;br /&gt;
&lt;br /&gt;
This the following table we summary the current ruby IDE and their refactoring support situation. &lt;br /&gt;
{| &lt;br /&gt;
 | Current Ruby IDE || Refactoring Support (Y/N)&lt;br /&gt;
|-&lt;br /&gt;
 | ActiveState Komodo  || N&lt;br /&gt;
 |- &lt;br /&gt;
 | NetBeans || N&lt;br /&gt;
 |-&lt;br /&gt;
 | Arachno Ruby ||  N&lt;br /&gt;
|-&lt;br /&gt;
 | FreeRIDE || N&lt;br /&gt;
|-&lt;br /&gt;
 | Mondrian Ruby IDE || N&lt;br /&gt;
|-&lt;br /&gt;
 | Ruby in Steel || N&lt;br /&gt;
|-&lt;br /&gt;
 | RubyMine || Y&lt;br /&gt;
|-&lt;br /&gt;
 | Eclipse (Aptana) || Y  &lt;br /&gt;
 |}&lt;br /&gt;
&lt;br /&gt;
=== Example of Using Ruby Refactoring Tools in Eclipse ===&lt;br /&gt;
Here the renaming of the method &amp;quot;badRenameMethod&amp;quot; to &amp;quot;Hello&amp;quot; is illustrated for Ruby.  The source code is show in section 1.3.&lt;br /&gt;
{|&lt;br /&gt;
| [[Image:r00.jpg|thumb|upright|alt= rename step 1]]&lt;br /&gt;
| [[Image:r01.jpg|thumb|upright|alt= rename step 2]]&lt;br /&gt;
| [[Image:r02.jpg|thumb|upright|alt= rename step 3]]&lt;br /&gt;
| [[Image:r03.jpg|thumb|upright|alt= rename step 4]]&lt;br /&gt;
| [[Image:r04.jpg|thumb|upright|alt= rename step 5]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Here the encapsulation of the field &amp;quot;field&amp;quot; is illustrated for Ruby.  The source code is show in section 1.3.&lt;br /&gt;
{|&lt;br /&gt;
| [[Image:r05.jpg|thumb|upright|alt= encapsulation step 1]]&lt;br /&gt;
| [[Image:r06.jpg|thumb|upright|alt= encapsulation step 2]]&lt;br /&gt;
| [[Image:r07.jpg|thumb|upright|alt= encapsulation step 3]]&lt;br /&gt;
| [[Image:r08.jpg|thumb|upright|alt= encapsulation step 4]]&lt;br /&gt;
| [[Image:r09.jpg|thumb|upright|alt= encapsulation step 5]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Example of Using Java Refactoring Tools in Eclipse ===&lt;br /&gt;
Here the renaming of the method &amp;quot;badRenameMethod&amp;quot; to &amp;quot;Hello&amp;quot; is illustrated for Java. The source code is show in section 1.4. &lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
| [[Image:j00.jpg|thumb|upright|alt= rename step 1]]&lt;br /&gt;
| [[Image:j01.jpg|thumb|upright|alt= rename step 2]]&lt;br /&gt;
| [[Image:j02.jpg|thumb|upright|alt= rename step 3]]&lt;br /&gt;
| [[Image:j03.jpg|thumb|upright|alt= rename step 4]]&lt;br /&gt;
| [[Image:j04.jpg|thumb|upright|alt= rename step 5]]&lt;br /&gt;
| [[Image:j05.jpg|thumb|upright|alt= rename step 6]]&lt;br /&gt;
|}&lt;br /&gt;
Here the encapsulation of the field &amp;quot;field&amp;quot; is illustrated for Java. The source code is show in section 1.4.&lt;br /&gt;
 &lt;br /&gt;
{|&lt;br /&gt;
| [[Image:j06.jpg|thumb|upright|alt= encapsulation step 1]]&lt;br /&gt;
| [[Image:j07.jpg|thumb|upright|alt= encapsulation step 2]]&lt;br /&gt;
| [[Image:j08.jpg|thumb|upright|alt= encapsulation step 3]]&lt;br /&gt;
| [[Image:j09.jpg|thumb|upright|alt= encapsulation step 4]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Comparison of Ruby and Java Refactoring Tools ==&lt;br /&gt;
Comprehensiveness comparison:&lt;br /&gt;
&lt;br /&gt;
{|&lt;br /&gt;
|1. Refactoring Options for Java in Eclipse  ||||  2. Refactoring Options in Eclipse for Ruby&lt;br /&gt;
|-&lt;br /&gt;
|Rename   || || Rename&lt;br /&gt;
|-&lt;br /&gt;
|Move || || Move&lt;br /&gt;
|-&lt;br /&gt;
|Change Method Signature || || Merge Class Parts in File&lt;br /&gt;
|-&lt;br /&gt;
|Extract Local Variable || || Pull Up&lt;br /&gt;
|-&lt;br /&gt;
|Extract Constant || || Pull Down&lt;br /&gt;
|-&lt;br /&gt;
|Inline || || Merge With External Class Parts&lt;br /&gt;
|-&lt;br /&gt;
|Convert Anonymous Class to Nested || || Split Local Variable&lt;br /&gt;
|-&lt;br /&gt;
|Convert Member to Top Level || || Merge With External Class Parts&lt;br /&gt;
|-&lt;br /&gt;
|Convert Local Variable to Field || || Inline&lt;br /&gt;
|-&lt;br /&gt;
|Extract Super Class || || Extract Constant&lt;br /&gt;
|-&lt;br /&gt;
|Extract Interface || || Encapsulate Field&lt;br /&gt;
|-&lt;br /&gt;
|Extract Class || || Convert Local Variable to Field&lt;br /&gt;
|-&lt;br /&gt;
|Use Supertype where possible&lt;br /&gt;
|-&lt;br /&gt;
|Pull Up &lt;br /&gt;
|-&lt;br /&gt;
|Pull Down &lt;br /&gt;
|-&lt;br /&gt;
|Introduce Parameter Object&lt;br /&gt;
|-&lt;br /&gt;
|Introduce Indirection&lt;br /&gt;
|-&lt;br /&gt;
|Introduce Factory&lt;br /&gt;
|-&lt;br /&gt;
|Introduce Parameter&lt;br /&gt;
|-&lt;br /&gt;
|Encapsulate Field&lt;br /&gt;
|-&lt;br /&gt;
|Generalize Declared Type&lt;br /&gt;
|-&lt;br /&gt;
|Infer Generic Type Arguments&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The refactoring options for Ruby and Java cover all the basic refactorings.  The differences in the number of options mainly come from the difference in the two languages. &lt;br /&gt;
 Ruby is a dynamically typed language, has unbounded polymorphism, and all classes are open to extension.  On the other hand, Java is a statically typed language, &lt;br /&gt;
polymorphism is mainly implemented via interfaces and inheritance, and classes cannot be extended at runtime.  The given examples (in section 1.3, 1.4)&lt;br /&gt;
 illustrate the ease of use of the refactoring tools for both Ruby and Java and how well these tools are integrated into the Eclipse IDE.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[1] Thomas Corbat, Lukas Felber, Mirko Stocker&lt;br /&gt;
Refactoring Support for the Eclipse Ruby Development Tools, Diploma Thesis, HSR University of Applied Sciences Rapperswil Institute for Software&lt;br /&gt;
&lt;br /&gt;
[2] code refactoring wiki, http://en.wikipedia.org/wiki/Code_refactoring&lt;br /&gt;
&lt;br /&gt;
[3] the first workshop on refactoring, https://netfiles.uiuc.edu/dig/RefactoringWorkshop&lt;br /&gt;
&lt;br /&gt;
[4] refactoring tutorial on ruby on rail, http://www.good-tutorials.com/tutorials/ruby-on-rails/refactoring&lt;/div&gt;</summary>
		<author><name>Syi</name></author>
	</entry>
</feed>