<?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=Naruto</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=Naruto"/>
	<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=Special:Contributions/Naruto"/>
	<updated>2026-09-12T05:29:08Z</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_1_kp&amp;diff=27655</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27655"/>
		<updated>2009-11-17T21:40:31Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Magic Pushbutton */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti-patterns were used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system.&lt;br /&gt;
*Inexperience on the part of the programmer.&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
Anti-Patterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
Some of the widely used anti-patterns are classified into the following categories,&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Organizational_anti-patterns Organizational anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Project_management_anti-patterns Project management anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Analysis_anti-patterns Analysis anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Software_design_anti-patterns Software design anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Configuration_management_anti-patterns Configuration management anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Programming_anti-patterns Programming anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Methodological_anti-patterns Methodological anti-patterns]&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
Some of the important software design anti-patterns are,&lt;br /&gt;
===Abstraction Inversion===&lt;br /&gt;
Abstraction Inversion means implementing a lower level construct on top of high level constructs. A simple example would be suppose we have 2 constructs A and B. Let B be implemented on top of A but A is not exposed anywhere in the system and if we really require A then we end up building A on top of B and B was already implemented in terms of A.&lt;br /&gt;
A short example of Abstraction Inversion is given below&lt;br /&gt;
&lt;br /&gt;
* '''Example'''&lt;br /&gt;
The below code implements a set of binary values in a String which decide if it is true or false. (e.g. 'T' or 'F'). They then use the index to find the bit.&lt;br /&gt;
    char[] bitString ...;&lt;br /&gt;
    if (bitString[i] == 'T') { // do stuff&lt;br /&gt;
&lt;br /&gt;
So in this case we have a character representing a bit value, but a character is nothing but a sequence of bits. Therefore we have a sequence made up of characters containing bits which are made up of a bit sequence.&lt;br /&gt;
&lt;br /&gt;
* '''Solution'''&lt;br /&gt;
**Choose the infrastructure carefully.&lt;br /&gt;
**If the system offers equivalent functions, use them.&lt;br /&gt;
**Do not inject any weak constructs into the system.&lt;br /&gt;
&lt;br /&gt;
===Big ball of mud===&lt;br /&gt;
&lt;br /&gt;
This term was coined by Brain Foote and Joseph Yoder's paper in 1999. This kind of anti pattern arises over a period of time where a number of programmers have worked on a system on various pieces of code. Dur to the lack of knowledge of the current systems the programmers write code which may have already been present and results in a lot of redundant code. Information being shared across the system which may result in it being globally declared and eventually making the code unreadable and unmanageable.&lt;br /&gt;
&lt;br /&gt;
*'''Example'''&lt;br /&gt;
    float CalculateTotal(int quantity, float price){&lt;br /&gt;
       return quantity*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    float CalculateAmount(int amt, float price){&lt;br /&gt;
       return amt*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The above code shows two functions that perform the same function but was created which results in code redundancy and unreadable.&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Good understanding of the system prior to any major code changes.&lt;br /&gt;
**Modularizing the code and defining the functionality at the proper location can help reduce the code redundancy.&lt;br /&gt;
**Technical shifts([http://en.wikipedia.org/wiki/Client-server client-server] to [http://en.wikipedia.org/wiki/Web-based web based], file based to [http://en.wikipedia.org/wiki/Database database based] etc) can provide good reasons to create the system from scratch.&lt;br /&gt;
&lt;br /&gt;
===Race Hazard===&lt;br /&gt;
A race hazard or a race condition is a flaw in the system where the output of the system depends on the order in which the system executes. This leads to inconsistency in the output. This term was coined with the idea of two signals racing each other to influence each other.&lt;br /&gt;
&lt;br /&gt;
*'''Example'''&lt;br /&gt;
    global integer A = 0;&lt;br /&gt;
    //increments the value of A and prints &amp;quot;RX&amp;quot;&lt;br /&gt;
    // activated whenever an interrupt is received from the controller&lt;br /&gt;
    task Received()&lt;br /&gt;
    {&lt;br /&gt;
        A = A + 1&lt;br /&gt;
        print RX&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    //prints out only even numbers&lt;br /&gt;
    //is activated whenever an  interrupt is received from the serial controller&lt;br /&gt;
    task timeout()&lt;br /&gt;
    {&lt;br /&gt;
       if(A is divisible by 2)&lt;br /&gt;
       {&lt;br /&gt;
           print A&lt;br /&gt;
       }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    Output would look like &lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    2&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    4&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**[http://en.wikipedia.org/wiki/Mutex Mutexes] can be used to address this problem in concurrent programming.&lt;br /&gt;
&lt;br /&gt;
===Magic Pushbutton===&lt;br /&gt;
This is a very common anti-pattern that shows up on graphical user interfaces programming environments. The user first draws the user interface and then builds up the [http://en.wikipedia.org/wiki/Business_Logic business logic] in the automatically created methods.&lt;br /&gt;
Some of the issues faced in this are,&lt;br /&gt;
* The code for in those defined functions grow large.&lt;br /&gt;
* Change in the user interface leads to a lot of changes in the functions and becomes difficult to manage.&lt;br /&gt;
* Testing becomes an issue.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Example'''&lt;br /&gt;
Below is a bad example of Magic PushButton Anti Pattern.    &lt;br /&gt;
    procedure TForm1.ButtonClick(Sender: TObject);&lt;br /&gt;
    var &lt;br /&gt;
       reg:TRegistry;&lt;br /&gt;
    begin&lt;br /&gt;
       reg:TRegistry.Create;&lt;br /&gt;
    try&lt;br /&gt;
       reg.RootKey:= HKey_Current_User;&lt;br /&gt;
       if reg.OpenKey('\Software\mycompany',true) then&lt;br /&gt;
       begin&lt;br /&gt;
         reg.WriteString('Filename',edit1.text);&lt;br /&gt;
       end;&lt;br /&gt;
      finally&lt;br /&gt;
       reg.Free;&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
A good example of the same is given below. This is done by re-factoring the business logic. In the below example this is done by storing the file in an registry in a separate class. &lt;br /&gt;
&lt;br /&gt;
    type&lt;br /&gt;
     TReference = class&lt;br /&gt;
     private  &lt;br /&gt;
       FFilename: string&lt;br /&gt;
       procedure SetFilename(const Value: string)&lt;br /&gt;
     public&lt;br /&gt;
       property Filename:string read FFilename write SetFilename;&lt;br /&gt;
       procedure Load;&lt;br /&gt;
       procedure Save;&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
The above code will call Save method from the click handler.&lt;br /&gt;
    procedure TForm1.ButtonClick  (Sender: Object);&lt;br /&gt;
    begin&lt;br /&gt;
       Preference.Save;&lt;br /&gt;
    end;&lt;br /&gt;
    procedure TForm1.EditChange (Sender: TObject);&lt;br /&gt;
    begin&lt;br /&gt;
      Preferences.Filename:= edit1.text;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Create functions and modularize the code as much as possible so that the code could be well maintained and flexible.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Object-oriented design anti-patterns==&lt;br /&gt;
Some of the important Object-oriented design anti-patterns are,&lt;br /&gt;
&lt;br /&gt;
===Anemic Domain Model===&lt;br /&gt;
Separating the [http://en.wikipedia.org/wiki/Business_logic business logic] from the [http://en.wikipedia.org/wiki/Domain_model Domain Model] is termed as Anemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's [http://en.wikipedia.org/wiki/Entity_Bean Entity beans] and .Net's three layered service application. A short example for Anemic Model is given below,&lt;br /&gt;
*'''Example'''&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Although, the above code looks right by providing segregation of data and service, its in violation of OOPs principle of data and behavior [http://en.wikipedia.org/wiki/Encapsulation encapsulation].It could run into problems when there are multiple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===BaseBean===&lt;br /&gt;
In the practice of BaseBean, subclasses are derived from an utility class, even though delegation is possible. [http://en.wikipedia.org/wiki/Inheritance Inheritance] can be evil sometimes, either breaking some subclass due to change in parent class or very deep hierarchy of classes leading to confusion and no reuse of code. For example, if we want to create a student class and we already have person class, inheritance is not the right way to go. &lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**We can use delegation and create instance of Person class in Student class and utilize all the features of class Person in class Student.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===CallSuper===&lt;br /&gt;
CallSuper is a anti-pattern in which subclass [http://en.wikipedia.org/wiki/Method_overriding overrides] a parent's method and calls the parent's overridden method from the same method. This is considered as a bad practice because, in the future if the parent class's implementation changes it breaks the subclass too. And also it puts an additional responsibility on the subclass's developer to call Super.The correct way to go about this is the parent class declaring a separate hook method for subclass to override.&lt;br /&gt;
*'''Example'''&lt;br /&gt;
  // '''Wrong Way'''                                                         // '''Correct Way'''&lt;br /&gt;
  public class EventHandle{                                             public class EventHandle{&lt;br /&gt;
    public void handle (BankingEvent e) {                                  public void handle (BankingEvent e) {&lt;br /&gt;
      cleanUp(e);                                                            cleanUp(e);&lt;br /&gt;
    }                                                                        doHandle(e);  //hook method&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
  public class TransferEventHandler extends EventHandle{                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    public void handle(BankingEvent e) {                                   }&lt;br /&gt;
      super.handle(e);                                                     public class TransferEventHandler extends EventHandle{&lt;br /&gt;
      initiateTransfer(e);                                                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    }                                                                           initiateTransfer(e);&lt;br /&gt;
                                                                             }&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
The significance of anti-patterns is the same as design patterns, anti-patterns are real helpful in identifying bad design.Thus the beforehand knowledge of anti-patterns comes in handy in making sure that the code base doesn't make use any of it. They should be identified at early stage of [http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle SDLC life cycle], because it might require significant effort to remove anti-patterns as you go down the SDLC life cycle.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Design_pattern_(computer_science) Design Patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Code_smell Code Smell]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Abstraction_inversion Abstraction Inversion]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Big_ball_of_mud Big Ball Of Mud]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Race_hazard Race Hazard]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Magic_pushbutton Magic Pushbutton]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern Anti-pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anemic_Domain_Model Anemic Domain Model]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/BaseBean BaseBean]&lt;br /&gt;
&lt;br /&gt;
==External Links==&lt;br /&gt;
&lt;br /&gt;
[1] [http://en.wikipedia.org/wiki/Anti-pattern AntiPattern]&amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.antipatterns.com/ &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://c2.com/cgi/wiki?AntiPattern &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.martinfowler.com/bliki/CallSuper.html &amp;lt;br&amp;gt;&lt;br /&gt;
[5] AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis by William J.Brown and Raphael C.Malveau&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27654</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27654"/>
		<updated>2009-11-17T21:40:05Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Magic Pushbutton */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti-patterns were used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system.&lt;br /&gt;
*Inexperience on the part of the programmer.&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
Anti-Patterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
Some of the widely used anti-patterns are classified into the following categories,&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Organizational_anti-patterns Organizational anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Project_management_anti-patterns Project management anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Analysis_anti-patterns Analysis anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Software_design_anti-patterns Software design anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Configuration_management_anti-patterns Configuration management anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Programming_anti-patterns Programming anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Methodological_anti-patterns Methodological anti-patterns]&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
Some of the important software design anti-patterns are,&lt;br /&gt;
===Abstraction Inversion===&lt;br /&gt;
Abstraction Inversion means implementing a lower level construct on top of high level constructs. A simple example would be suppose we have 2 constructs A and B. Let B be implemented on top of A but A is not exposed anywhere in the system and if we really require A then we end up building A on top of B and B was already implemented in terms of A.&lt;br /&gt;
A short example of Abstraction Inversion is given below&lt;br /&gt;
&lt;br /&gt;
* '''Example'''&lt;br /&gt;
The below code implements a set of binary values in a String which decide if it is true or false. (e.g. 'T' or 'F'). They then use the index to find the bit.&lt;br /&gt;
    char[] bitString ...;&lt;br /&gt;
    if (bitString[i] == 'T') { // do stuff&lt;br /&gt;
&lt;br /&gt;
So in this case we have a character representing a bit value, but a character is nothing but a sequence of bits. Therefore we have a sequence made up of characters containing bits which are made up of a bit sequence.&lt;br /&gt;
&lt;br /&gt;
* '''Solution'''&lt;br /&gt;
**Choose the infrastructure carefully.&lt;br /&gt;
**If the system offers equivalent functions, use them.&lt;br /&gt;
**Do not inject any weak constructs into the system.&lt;br /&gt;
&lt;br /&gt;
===Big ball of mud===&lt;br /&gt;
&lt;br /&gt;
This term was coined by Brain Foote and Joseph Yoder's paper in 1999. This kind of anti pattern arises over a period of time where a number of programmers have worked on a system on various pieces of code. Dur to the lack of knowledge of the current systems the programmers write code which may have already been present and results in a lot of redundant code. Information being shared across the system which may result in it being globally declared and eventually making the code unreadable and unmanageable.&lt;br /&gt;
&lt;br /&gt;
*'''Example'''&lt;br /&gt;
    float CalculateTotal(int quantity, float price){&lt;br /&gt;
       return quantity*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    float CalculateAmount(int amt, float price){&lt;br /&gt;
       return amt*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The above code shows two functions that perform the same function but was created which results in code redundancy and unreadable.&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Good understanding of the system prior to any major code changes.&lt;br /&gt;
**Modularizing the code and defining the functionality at the proper location can help reduce the code redundancy.&lt;br /&gt;
**Technical shifts([http://en.wikipedia.org/wiki/Client-server client-server] to [http://en.wikipedia.org/wiki/Web-based web based], file based to [http://en.wikipedia.org/wiki/Database database based] etc) can provide good reasons to create the system from scratch.&lt;br /&gt;
&lt;br /&gt;
===Race Hazard===&lt;br /&gt;
A race hazard or a race condition is a flaw in the system where the output of the system depends on the order in which the system executes. This leads to inconsistency in the output. This term was coined with the idea of two signals racing each other to influence each other.&lt;br /&gt;
&lt;br /&gt;
*'''Example'''&lt;br /&gt;
    global integer A = 0;&lt;br /&gt;
    //increments the value of A and prints &amp;quot;RX&amp;quot;&lt;br /&gt;
    // activated whenever an interrupt is received from the controller&lt;br /&gt;
    task Received()&lt;br /&gt;
    {&lt;br /&gt;
        A = A + 1&lt;br /&gt;
        print RX&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    //prints out only even numbers&lt;br /&gt;
    //is activated whenever an  interrupt is received from the serial controller&lt;br /&gt;
    task timeout()&lt;br /&gt;
    {&lt;br /&gt;
       if(A is divisible by 2)&lt;br /&gt;
       {&lt;br /&gt;
           print A&lt;br /&gt;
       }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    Output would look like &lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    2&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    4&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**[http://en.wikipedia.org/wiki/Mutex Mutexes] can be used to address this problem in concurrent programming.&lt;br /&gt;
&lt;br /&gt;
===Magic Pushbutton===&lt;br /&gt;
This is a very common anti-pattern that shows up on graphical user interfaces programming environments. The user first draws the user interface and then builds up the [http://en.wikipedia.org/wiki/Business_Logic business logic] in the automatically created methods.&lt;br /&gt;
Some of the issues faced in this are,&lt;br /&gt;
* The code for in those defined functions grow large.&lt;br /&gt;
* Change in the user interface leads to a lot of changes in the functions and becomes difficult to manage.&lt;br /&gt;
* Testing becomes an issue.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Example'''&lt;br /&gt;
Below is a Bad example of Magic PushButton Anti Pattern.    &lt;br /&gt;
    procedure TForm1.ButtonClick(Sender: TObject);&lt;br /&gt;
    var &lt;br /&gt;
       reg:TRegistry;&lt;br /&gt;
    begin&lt;br /&gt;
       reg:TRegistry.Create;&lt;br /&gt;
    try&lt;br /&gt;
       reg.RootKey:= HKey_Current_User;&lt;br /&gt;
       if reg.OpenKey('\Software\mycompany',true) then&lt;br /&gt;
       begin&lt;br /&gt;
         reg.WriteString('Filename',edit1.text);&lt;br /&gt;
       end;&lt;br /&gt;
      finally&lt;br /&gt;
       reg.Free;&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
A good example of the same is given below. This is done by re-factoring the business logic. In the below example this is done by storing the file in an registry in a separate class. &lt;br /&gt;
&lt;br /&gt;
    type&lt;br /&gt;
     TReference = class&lt;br /&gt;
     private  &lt;br /&gt;
       FFilename: string&lt;br /&gt;
       procedure SetFilename(const Value: string)&lt;br /&gt;
     public&lt;br /&gt;
       property Filename:string read FFilename write SetFilename;&lt;br /&gt;
       procedure Load;&lt;br /&gt;
       procedure Save;&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
The above code will call Save method from the click handler.&lt;br /&gt;
    procedure TForm1.ButtonClick  (Sender: Object);&lt;br /&gt;
    begin&lt;br /&gt;
       Preference.Save;&lt;br /&gt;
    end;&lt;br /&gt;
    procedure TForm1.EditChange (Sender: TObject);&lt;br /&gt;
    begin&lt;br /&gt;
      Preferences.Filename:= edit1.text;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Create functions and modularize the code as much as possible so that the code could be well maintained and flexible.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Object-oriented design anti-patterns==&lt;br /&gt;
Some of the important Object-oriented design anti-patterns are,&lt;br /&gt;
&lt;br /&gt;
===Anemic Domain Model===&lt;br /&gt;
Separating the [http://en.wikipedia.org/wiki/Business_logic business logic] from the [http://en.wikipedia.org/wiki/Domain_model Domain Model] is termed as Anemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's [http://en.wikipedia.org/wiki/Entity_Bean Entity beans] and .Net's three layered service application. A short example for Anemic Model is given below,&lt;br /&gt;
*'''Example'''&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Although, the above code looks right by providing segregation of data and service, its in violation of OOPs principle of data and behavior [http://en.wikipedia.org/wiki/Encapsulation encapsulation].It could run into problems when there are multiple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===BaseBean===&lt;br /&gt;
In the practice of BaseBean, subclasses are derived from an utility class, even though delegation is possible. [http://en.wikipedia.org/wiki/Inheritance Inheritance] can be evil sometimes, either breaking some subclass due to change in parent class or very deep hierarchy of classes leading to confusion and no reuse of code. For example, if we want to create a student class and we already have person class, inheritance is not the right way to go. &lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**We can use delegation and create instance of Person class in Student class and utilize all the features of class Person in class Student.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===CallSuper===&lt;br /&gt;
CallSuper is a anti-pattern in which subclass [http://en.wikipedia.org/wiki/Method_overriding overrides] a parent's method and calls the parent's overridden method from the same method. This is considered as a bad practice because, in the future if the parent class's implementation changes it breaks the subclass too. And also it puts an additional responsibility on the subclass's developer to call Super.The correct way to go about this is the parent class declaring a separate hook method for subclass to override.&lt;br /&gt;
*'''Example'''&lt;br /&gt;
  // '''Wrong Way'''                                                         // '''Correct Way'''&lt;br /&gt;
  public class EventHandle{                                             public class EventHandle{&lt;br /&gt;
    public void handle (BankingEvent e) {                                  public void handle (BankingEvent e) {&lt;br /&gt;
      cleanUp(e);                                                            cleanUp(e);&lt;br /&gt;
    }                                                                        doHandle(e);  //hook method&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
  public class TransferEventHandler extends EventHandle{                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    public void handle(BankingEvent e) {                                   }&lt;br /&gt;
      super.handle(e);                                                     public class TransferEventHandler extends EventHandle{&lt;br /&gt;
      initiateTransfer(e);                                                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    }                                                                           initiateTransfer(e);&lt;br /&gt;
                                                                             }&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
The significance of anti-patterns is the same as design patterns, anti-patterns are real helpful in identifying bad design.Thus the beforehand knowledge of anti-patterns comes in handy in making sure that the code base doesn't make use any of it. They should be identified at early stage of [http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle SDLC life cycle], because it might require significant effort to remove anti-patterns as you go down the SDLC life cycle.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Design_pattern_(computer_science) Design Patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Code_smell Code Smell]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Abstraction_inversion Abstraction Inversion]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Big_ball_of_mud Big Ball Of Mud]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Race_hazard Race Hazard]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Magic_pushbutton Magic Pushbutton]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern Anti-pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anemic_Domain_Model Anemic Domain Model]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/BaseBean BaseBean]&lt;br /&gt;
&lt;br /&gt;
==External Links==&lt;br /&gt;
&lt;br /&gt;
[1] [http://en.wikipedia.org/wiki/Anti-pattern AntiPattern]&amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.antipatterns.com/ &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://c2.com/cgi/wiki?AntiPattern &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.martinfowler.com/bliki/CallSuper.html &amp;lt;br&amp;gt;&lt;br /&gt;
[5] AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis by William J.Brown and Raphael C.Malveau&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27653</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27653"/>
		<updated>2009-11-17T21:39:14Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Big ball of mud */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti-patterns were used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system.&lt;br /&gt;
*Inexperience on the part of the programmer.&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
Anti-Patterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
Some of the widely used anti-patterns are classified into the following categories,&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Organizational_anti-patterns Organizational anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Project_management_anti-patterns Project management anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Analysis_anti-patterns Analysis anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Software_design_anti-patterns Software design anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Configuration_management_anti-patterns Configuration management anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Programming_anti-patterns Programming anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Methodological_anti-patterns Methodological anti-patterns]&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
Some of the important software design anti-patterns are,&lt;br /&gt;
===Abstraction Inversion===&lt;br /&gt;
Abstraction Inversion means implementing a lower level construct on top of high level constructs. A simple example would be suppose we have 2 constructs A and B. Let B be implemented on top of A but A is not exposed anywhere in the system and if we really require A then we end up building A on top of B and B was already implemented in terms of A.&lt;br /&gt;
A short example of Abstraction Inversion is given below&lt;br /&gt;
&lt;br /&gt;
* '''Example'''&lt;br /&gt;
The below code implements a set of binary values in a String which decide if it is true or false. (e.g. 'T' or 'F'). They then use the index to find the bit.&lt;br /&gt;
    char[] bitString ...;&lt;br /&gt;
    if (bitString[i] == 'T') { // do stuff&lt;br /&gt;
&lt;br /&gt;
So in this case we have a character representing a bit value, but a character is nothing but a sequence of bits. Therefore we have a sequence made up of characters containing bits which are made up of a bit sequence.&lt;br /&gt;
&lt;br /&gt;
* '''Solution'''&lt;br /&gt;
**Choose the infrastructure carefully.&lt;br /&gt;
**If the system offers equivalent functions, use them.&lt;br /&gt;
**Do not inject any weak constructs into the system.&lt;br /&gt;
&lt;br /&gt;
===Big ball of mud===&lt;br /&gt;
&lt;br /&gt;
This term was coined by Brain Foote and Joseph Yoder's paper in 1999. This kind of anti pattern arises over a period of time where a number of programmers have worked on a system on various pieces of code. Dur to the lack of knowledge of the current systems the programmers write code which may have already been present and results in a lot of redundant code. Information being shared across the system which may result in it being globally declared and eventually making the code unreadable and unmanageable.&lt;br /&gt;
&lt;br /&gt;
*'''Example'''&lt;br /&gt;
    float CalculateTotal(int quantity, float price){&lt;br /&gt;
       return quantity*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    float CalculateAmount(int amt, float price){&lt;br /&gt;
       return amt*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The above code shows two functions that perform the same function but was created which results in code redundancy and unreadable.&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Good understanding of the system prior to any major code changes.&lt;br /&gt;
**Modularizing the code and defining the functionality at the proper location can help reduce the code redundancy.&lt;br /&gt;
**Technical shifts([http://en.wikipedia.org/wiki/Client-server client-server] to [http://en.wikipedia.org/wiki/Web-based web based], file based to [http://en.wikipedia.org/wiki/Database database based] etc) can provide good reasons to create the system from scratch.&lt;br /&gt;
&lt;br /&gt;
===Race Hazard===&lt;br /&gt;
A race hazard or a race condition is a flaw in the system where the output of the system depends on the order in which the system executes. This leads to inconsistency in the output. This term was coined with the idea of two signals racing each other to influence each other.&lt;br /&gt;
&lt;br /&gt;
*'''Example'''&lt;br /&gt;
    global integer A = 0;&lt;br /&gt;
    //increments the value of A and prints &amp;quot;RX&amp;quot;&lt;br /&gt;
    // activated whenever an interrupt is received from the controller&lt;br /&gt;
    task Received()&lt;br /&gt;
    {&lt;br /&gt;
        A = A + 1&lt;br /&gt;
        print RX&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    //prints out only even numbers&lt;br /&gt;
    //is activated whenever an  interrupt is received from the serial controller&lt;br /&gt;
    task timeout()&lt;br /&gt;
    {&lt;br /&gt;
       if(A is divisible by 2)&lt;br /&gt;
       {&lt;br /&gt;
           print A&lt;br /&gt;
       }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    Output would look like &lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    2&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    4&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**[http://en.wikipedia.org/wiki/Mutex Mutexes] can be used to address this problem in concurrent programming.&lt;br /&gt;
&lt;br /&gt;
===Magic Pushbutton===&lt;br /&gt;
This is a very common anti-pattern that shows up on graphical user interfaces programming environments. The user first draws the user interface and then builds up the business logic in the automatically created methods.&lt;br /&gt;
Some of the issues faced in this are,&lt;br /&gt;
* The code for in those defined functions grow large.&lt;br /&gt;
* Change in the user interface leads to a lot of changes in the functions and becomes difficult to manage.&lt;br /&gt;
* Testing becomes an issue.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Example'''&lt;br /&gt;
Below is a Bad example of Magic PushButton Anti Pattern.    &lt;br /&gt;
    procedure TForm1.ButtonClick(Sender: TObject);&lt;br /&gt;
    var &lt;br /&gt;
       reg:TRegistry;&lt;br /&gt;
    begin&lt;br /&gt;
       reg:TRegistry.Create;&lt;br /&gt;
    try&lt;br /&gt;
       reg.RootKey:= HKey_Current_User;&lt;br /&gt;
       if reg.OpenKey('\Software\mycompany',true) then&lt;br /&gt;
       begin&lt;br /&gt;
         reg.WriteString('Filename',edit1.text);&lt;br /&gt;
       end;&lt;br /&gt;
      finally&lt;br /&gt;
       reg.Free;&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
A good example of the same is given below. This is done by re-factoring the business logic. In the below example this is done by storing the file in an registry in a separate class. &lt;br /&gt;
&lt;br /&gt;
    type&lt;br /&gt;
     TReference = class&lt;br /&gt;
     private  &lt;br /&gt;
       FFilename: string&lt;br /&gt;
       procedure SetFilename(const Value: string)&lt;br /&gt;
     public&lt;br /&gt;
       property Filename:string read FFilename write SetFilename;&lt;br /&gt;
       procedure Load;&lt;br /&gt;
       procedure Save;&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
The above code will call Save method from the click handler.&lt;br /&gt;
    procedure TForm1.ButtonClick  (Sender: Object);&lt;br /&gt;
    begin&lt;br /&gt;
       Preference.Save;&lt;br /&gt;
    end;&lt;br /&gt;
    procedure TForm1.EditChange (Sender: TObject);&lt;br /&gt;
    begin&lt;br /&gt;
      Preferences.Filename:= edit1.text;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Create functions and modularize the code as much as possible so that the code could be well maintained and flexible.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Object-oriented design anti-patterns==&lt;br /&gt;
Some of the important Object-oriented design anti-patterns are,&lt;br /&gt;
&lt;br /&gt;
===Anemic Domain Model===&lt;br /&gt;
Separating the [http://en.wikipedia.org/wiki/Business_logic business logic] from the [http://en.wikipedia.org/wiki/Domain_model Domain Model] is termed as Anemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's [http://en.wikipedia.org/wiki/Entity_Bean Entity beans] and .Net's three layered service application. A short example for Anemic Model is given below,&lt;br /&gt;
*'''Example'''&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Although, the above code looks right by providing segregation of data and service, its in violation of OOPs principle of data and behavior [http://en.wikipedia.org/wiki/Encapsulation encapsulation].It could run into problems when there are multiple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===BaseBean===&lt;br /&gt;
In the practice of BaseBean, subclasses are derived from an utility class, even though delegation is possible. [http://en.wikipedia.org/wiki/Inheritance Inheritance] can be evil sometimes, either breaking some subclass due to change in parent class or very deep hierarchy of classes leading to confusion and no reuse of code. For example, if we want to create a student class and we already have person class, inheritance is not the right way to go. &lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**We can use delegation and create instance of Person class in Student class and utilize all the features of class Person in class Student.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===CallSuper===&lt;br /&gt;
CallSuper is a anti-pattern in which subclass [http://en.wikipedia.org/wiki/Method_overriding overrides] a parent's method and calls the parent's overridden method from the same method. This is considered as a bad practice because, in the future if the parent class's implementation changes it breaks the subclass too. And also it puts an additional responsibility on the subclass's developer to call Super.The correct way to go about this is the parent class declaring a separate hook method for subclass to override.&lt;br /&gt;
*'''Example'''&lt;br /&gt;
  // '''Wrong Way'''                                                         // '''Correct Way'''&lt;br /&gt;
  public class EventHandle{                                             public class EventHandle{&lt;br /&gt;
    public void handle (BankingEvent e) {                                  public void handle (BankingEvent e) {&lt;br /&gt;
      cleanUp(e);                                                            cleanUp(e);&lt;br /&gt;
    }                                                                        doHandle(e);  //hook method&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
  public class TransferEventHandler extends EventHandle{                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    public void handle(BankingEvent e) {                                   }&lt;br /&gt;
      super.handle(e);                                                     public class TransferEventHandler extends EventHandle{&lt;br /&gt;
      initiateTransfer(e);                                                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    }                                                                           initiateTransfer(e);&lt;br /&gt;
                                                                             }&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
The significance of anti-patterns is the same as design patterns, anti-patterns are real helpful in identifying bad design.Thus the beforehand knowledge of anti-patterns comes in handy in making sure that the code base doesn't make use any of it. They should be identified at early stage of [http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle SDLC life cycle], because it might require significant effort to remove anti-patterns as you go down the SDLC life cycle.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Design_pattern_(computer_science) Design Patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Code_smell Code Smell]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Abstraction_inversion Abstraction Inversion]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Big_ball_of_mud Big Ball Of Mud]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Race_hazard Race Hazard]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Magic_pushbutton Magic Pushbutton]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern Anti-pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anemic_Domain_Model Anemic Domain Model]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/BaseBean BaseBean]&lt;br /&gt;
&lt;br /&gt;
==External Links==&lt;br /&gt;
&lt;br /&gt;
[1] [http://en.wikipedia.org/wiki/Anti-pattern AntiPattern]&amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.antipatterns.com/ &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://c2.com/cgi/wiki?AntiPattern &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.martinfowler.com/bliki/CallSuper.html &amp;lt;br&amp;gt;&lt;br /&gt;
[5] AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis by William J.Brown and Raphael C.Malveau&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27652</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27652"/>
		<updated>2009-11-17T21:38:30Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Big ball of mud */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti-patterns were used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system.&lt;br /&gt;
*Inexperience on the part of the programmer.&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
Anti-Patterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
Some of the widely used anti-patterns are classified into the following categories,&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Organizational_anti-patterns Organizational anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Project_management_anti-patterns Project management anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Analysis_anti-patterns Analysis anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Software_design_anti-patterns Software design anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Configuration_management_anti-patterns Configuration management anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Programming_anti-patterns Programming anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Methodological_anti-patterns Methodological anti-patterns]&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
Some of the important software design anti-patterns are,&lt;br /&gt;
===Abstraction Inversion===&lt;br /&gt;
Abstraction Inversion means implementing a lower level construct on top of high level constructs. A simple example would be suppose we have 2 constructs A and B. Let B be implemented on top of A but A is not exposed anywhere in the system and if we really require A then we end up building A on top of B and B was already implemented in terms of A.&lt;br /&gt;
A short example of Abstraction Inversion is given below&lt;br /&gt;
&lt;br /&gt;
* '''Example'''&lt;br /&gt;
The below code implements a set of binary values in a String which decide if it is true or false. (e.g. 'T' or 'F'). They then use the index to find the bit.&lt;br /&gt;
    char[] bitString ...;&lt;br /&gt;
    if (bitString[i] == 'T') { // do stuff&lt;br /&gt;
&lt;br /&gt;
So in this case we have a character representing a bit value, but a character is nothing but a sequence of bits. Therefore we have a sequence made up of characters containing bits which are made up of a bit sequence.&lt;br /&gt;
&lt;br /&gt;
* '''Solution'''&lt;br /&gt;
**Choose the infrastructure carefully.&lt;br /&gt;
**If the system offers equivalent functions, use them.&lt;br /&gt;
**Do not inject any weak constructs into the system.&lt;br /&gt;
&lt;br /&gt;
===Big ball of mud===&lt;br /&gt;
&lt;br /&gt;
This term was coined by Brain Foote and Joseph Yoder's paper in 1999. This kind of anti pattern arises over a period of time where a number of programmers have worked on a system on various pieces of code. Dur to the lack of knowledge of the current systems the programmers write code which may have already been present and results in a lot of redundant code. Information being shared across the system which may result in it being globally declared and eventually making the code unreadable and unmanageable.&lt;br /&gt;
&lt;br /&gt;
*'''Example'''&lt;br /&gt;
    float CalculateTotal(int quantity, float price){&lt;br /&gt;
       return quantity*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    float CalculateAmount(int amt, float price){&lt;br /&gt;
       return amt*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The above code shows two functions that perform the same function but was created which results in code redundancy and unreadable.&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Good understanding of the system prior to any major code changes.&lt;br /&gt;
**Modularizing the code and defining the functionality at the proper location can help reduce the code redundancy.&lt;br /&gt;
**Technical shifts([http://en.wikipedia.org/wiki/Client-server client-server] to [http://en.wikipedia.org/wiki/Web-based web based], file based to database based etc) can provide good reasons to create the system from scratch.&lt;br /&gt;
&lt;br /&gt;
===Race Hazard===&lt;br /&gt;
A race hazard or a race condition is a flaw in the system where the output of the system depends on the order in which the system executes. This leads to inconsistency in the output. This term was coined with the idea of two signals racing each other to influence each other.&lt;br /&gt;
&lt;br /&gt;
*'''Example'''&lt;br /&gt;
    global integer A = 0;&lt;br /&gt;
    //increments the value of A and prints &amp;quot;RX&amp;quot;&lt;br /&gt;
    // activated whenever an interrupt is received from the controller&lt;br /&gt;
    task Received()&lt;br /&gt;
    {&lt;br /&gt;
        A = A + 1&lt;br /&gt;
        print RX&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    //prints out only even numbers&lt;br /&gt;
    //is activated whenever an  interrupt is received from the serial controller&lt;br /&gt;
    task timeout()&lt;br /&gt;
    {&lt;br /&gt;
       if(A is divisible by 2)&lt;br /&gt;
       {&lt;br /&gt;
           print A&lt;br /&gt;
       }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    Output would look like &lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    2&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    4&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**[http://en.wikipedia.org/wiki/Mutex Mutexes] can be used to address this problem in concurrent programming.&lt;br /&gt;
&lt;br /&gt;
===Magic Pushbutton===&lt;br /&gt;
This is a very common anti-pattern that shows up on graphical user interfaces programming environments. The user first draws the user interface and then builds up the business logic in the automatically created methods.&lt;br /&gt;
Some of the issues faced in this are,&lt;br /&gt;
* The code for in those defined functions grow large.&lt;br /&gt;
* Change in the user interface leads to a lot of changes in the functions and becomes difficult to manage.&lt;br /&gt;
* Testing becomes an issue.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Example'''&lt;br /&gt;
Below is a Bad example of Magic PushButton Anti Pattern.    &lt;br /&gt;
    procedure TForm1.ButtonClick(Sender: TObject);&lt;br /&gt;
    var &lt;br /&gt;
       reg:TRegistry;&lt;br /&gt;
    begin&lt;br /&gt;
       reg:TRegistry.Create;&lt;br /&gt;
    try&lt;br /&gt;
       reg.RootKey:= HKey_Current_User;&lt;br /&gt;
       if reg.OpenKey('\Software\mycompany',true) then&lt;br /&gt;
       begin&lt;br /&gt;
         reg.WriteString('Filename',edit1.text);&lt;br /&gt;
       end;&lt;br /&gt;
      finally&lt;br /&gt;
       reg.Free;&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
A good example of the same is given below. This is done by re-factoring the business logic. In the below example this is done by storing the file in an registry in a separate class. &lt;br /&gt;
&lt;br /&gt;
    type&lt;br /&gt;
     TReference = class&lt;br /&gt;
     private  &lt;br /&gt;
       FFilename: string&lt;br /&gt;
       procedure SetFilename(const Value: string)&lt;br /&gt;
     public&lt;br /&gt;
       property Filename:string read FFilename write SetFilename;&lt;br /&gt;
       procedure Load;&lt;br /&gt;
       procedure Save;&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
The above code will call Save method from the click handler.&lt;br /&gt;
    procedure TForm1.ButtonClick  (Sender: Object);&lt;br /&gt;
    begin&lt;br /&gt;
       Preference.Save;&lt;br /&gt;
    end;&lt;br /&gt;
    procedure TForm1.EditChange (Sender: TObject);&lt;br /&gt;
    begin&lt;br /&gt;
      Preferences.Filename:= edit1.text;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Create functions and modularize the code as much as possible so that the code could be well maintained and flexible.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Object-oriented design anti-patterns==&lt;br /&gt;
Some of the important Object-oriented design anti-patterns are,&lt;br /&gt;
&lt;br /&gt;
===Anemic Domain Model===&lt;br /&gt;
Separating the [http://en.wikipedia.org/wiki/Business_logic business logic] from the [http://en.wikipedia.org/wiki/Domain_model Domain Model] is termed as Anemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's [http://en.wikipedia.org/wiki/Entity_Bean Entity beans] and .Net's three layered service application. A short example for Anemic Model is given below,&lt;br /&gt;
*'''Example'''&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Although, the above code looks right by providing segregation of data and service, its in violation of OOPs principle of data and behavior [http://en.wikipedia.org/wiki/Encapsulation encapsulation].It could run into problems when there are multiple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===BaseBean===&lt;br /&gt;
In the practice of BaseBean, subclasses are derived from an utility class, even though delegation is possible. [http://en.wikipedia.org/wiki/Inheritance Inheritance] can be evil sometimes, either breaking some subclass due to change in parent class or very deep hierarchy of classes leading to confusion and no reuse of code. For example, if we want to create a student class and we already have person class, inheritance is not the right way to go. &lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**We can use delegation and create instance of Person class in Student class and utilize all the features of class Person in class Student.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===CallSuper===&lt;br /&gt;
CallSuper is a anti-pattern in which subclass [http://en.wikipedia.org/wiki/Method_overriding overrides] a parent's method and calls the parent's overridden method from the same method. This is considered as a bad practice because, in the future if the parent class's implementation changes it breaks the subclass too. And also it puts an additional responsibility on the subclass's developer to call Super.The correct way to go about this is the parent class declaring a separate hook method for subclass to override.&lt;br /&gt;
*'''Example'''&lt;br /&gt;
  // '''Wrong Way'''                                                         // '''Correct Way'''&lt;br /&gt;
  public class EventHandle{                                             public class EventHandle{&lt;br /&gt;
    public void handle (BankingEvent e) {                                  public void handle (BankingEvent e) {&lt;br /&gt;
      cleanUp(e);                                                            cleanUp(e);&lt;br /&gt;
    }                                                                        doHandle(e);  //hook method&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
  public class TransferEventHandler extends EventHandle{                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    public void handle(BankingEvent e) {                                   }&lt;br /&gt;
      super.handle(e);                                                     public class TransferEventHandler extends EventHandle{&lt;br /&gt;
      initiateTransfer(e);                                                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    }                                                                           initiateTransfer(e);&lt;br /&gt;
                                                                             }&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
The significance of anti-patterns is the same as design patterns, anti-patterns are real helpful in identifying bad design.Thus the beforehand knowledge of anti-patterns comes in handy in making sure that the code base doesn't make use any of it. They should be identified at early stage of [http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle SDLC life cycle], because it might require significant effort to remove anti-patterns as you go down the SDLC life cycle.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Design_pattern_(computer_science) Design Patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Code_smell Code Smell]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Abstraction_inversion Abstraction Inversion]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Big_ball_of_mud Big Ball Of Mud]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Race_hazard Race Hazard]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Magic_pushbutton Magic Pushbutton]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern Anti-pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anemic_Domain_Model Anemic Domain Model]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/BaseBean BaseBean]&lt;br /&gt;
&lt;br /&gt;
==External Links==&lt;br /&gt;
&lt;br /&gt;
[1] [http://en.wikipedia.org/wiki/Anti-pattern AntiPattern]&amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.antipatterns.com/ &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://c2.com/cgi/wiki?AntiPattern &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.martinfowler.com/bliki/CallSuper.html &amp;lt;br&amp;gt;&lt;br /&gt;
[5] AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis by William J.Brown and Raphael C.Malveau&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27651</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27651"/>
		<updated>2009-11-17T21:36:09Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* External Links */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti-patterns were used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system.&lt;br /&gt;
*Inexperience on the part of the programmer.&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
Anti-Patterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
Some of the widely used anti-patterns are classified into the following categories,&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Organizational_anti-patterns Organizational anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Project_management_anti-patterns Project management anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Analysis_anti-patterns Analysis anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Software_design_anti-patterns Software design anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Configuration_management_anti-patterns Configuration management anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Programming_anti-patterns Programming anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Methodological_anti-patterns Methodological anti-patterns]&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
Some of the important software design anti-patterns are,&lt;br /&gt;
===Abstraction Inversion===&lt;br /&gt;
Abstraction Inversion means implementing a lower level construct on top of high level constructs. A simple example would be suppose we have 2 constructs A and B. Let B be implemented on top of A but A is not exposed anywhere in the system and if we really require A then we end up building A on top of B and B was already implemented in terms of A.&lt;br /&gt;
A short example of Abstraction Inversion is given below&lt;br /&gt;
&lt;br /&gt;
* '''Example'''&lt;br /&gt;
The below code implements a set of binary values in a String which decide if it is true or false. (e.g. 'T' or 'F'). They then use the index to find the bit.&lt;br /&gt;
    char[] bitString ...;&lt;br /&gt;
    if (bitString[i] == 'T') { // do stuff&lt;br /&gt;
&lt;br /&gt;
So in this case we have a character representing a bit value, but a character is nothing but a sequence of bits. Therefore we have a sequence made up of characters containing bits which are made up of a bit sequence.&lt;br /&gt;
&lt;br /&gt;
* '''Solution'''&lt;br /&gt;
**Choose the infrastructure carefully.&lt;br /&gt;
**If the system offers equivalent functions, use them.&lt;br /&gt;
**Do not inject any weak constructs into the system.&lt;br /&gt;
&lt;br /&gt;
===Big ball of mud===&lt;br /&gt;
&lt;br /&gt;
This term was coined by Brain Foote and Joseph Yoder's paper in 1999. This kind of anti pattern arises over a period of time where a number of programmers have worked on a system on various pieces of code. Dur to the lack of knowledge of the current systems the programmers write code which may have already been present and results in a lot of redundant code. Information being shared across the system which may result in it being globally declared and eventually making the code unreadable and unmanageable.&lt;br /&gt;
&lt;br /&gt;
*'''Example'''&lt;br /&gt;
    float CalculateTotal(int quantity, float price){&lt;br /&gt;
       return quantity*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    float CalculateAmount(int amt, float price){&lt;br /&gt;
       return amt*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The above code shows two functions that perform the same function but was created which results in code redundancy and unreadable.&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Good understanding of the system prior to any major code changes.&lt;br /&gt;
**Modularizing the code and defining the functionality at the proper location can help reduce the code redundancy.&lt;br /&gt;
**Technical shifts(client-server to web based, file based to database based etc) can provide good reasons to create the system from scratch.&lt;br /&gt;
&lt;br /&gt;
===Race Hazard===&lt;br /&gt;
A race hazard or a race condition is a flaw in the system where the output of the system depends on the order in which the system executes. This leads to inconsistency in the output. This term was coined with the idea of two signals racing each other to influence each other.&lt;br /&gt;
&lt;br /&gt;
*'''Example'''&lt;br /&gt;
    global integer A = 0;&lt;br /&gt;
    //increments the value of A and prints &amp;quot;RX&amp;quot;&lt;br /&gt;
    // activated whenever an interrupt is received from the controller&lt;br /&gt;
    task Received()&lt;br /&gt;
    {&lt;br /&gt;
        A = A + 1&lt;br /&gt;
        print RX&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    //prints out only even numbers&lt;br /&gt;
    //is activated whenever an  interrupt is received from the serial controller&lt;br /&gt;
    task timeout()&lt;br /&gt;
    {&lt;br /&gt;
       if(A is divisible by 2)&lt;br /&gt;
       {&lt;br /&gt;
           print A&lt;br /&gt;
       }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    Output would look like &lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    2&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    4&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**[http://en.wikipedia.org/wiki/Mutex Mutexes] can be used to address this problem in concurrent programming.&lt;br /&gt;
&lt;br /&gt;
===Magic Pushbutton===&lt;br /&gt;
This is a very common anti-pattern that shows up on graphical user interfaces programming environments. The user first draws the user interface and then builds up the business logic in the automatically created methods.&lt;br /&gt;
Some of the issues faced in this are,&lt;br /&gt;
* The code for in those defined functions grow large.&lt;br /&gt;
* Change in the user interface leads to a lot of changes in the functions and becomes difficult to manage.&lt;br /&gt;
* Testing becomes an issue.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Example'''&lt;br /&gt;
Below is a Bad example of Magic PushButton Anti Pattern.    &lt;br /&gt;
    procedure TForm1.ButtonClick(Sender: TObject);&lt;br /&gt;
    var &lt;br /&gt;
       reg:TRegistry;&lt;br /&gt;
    begin&lt;br /&gt;
       reg:TRegistry.Create;&lt;br /&gt;
    try&lt;br /&gt;
       reg.RootKey:= HKey_Current_User;&lt;br /&gt;
       if reg.OpenKey('\Software\mycompany',true) then&lt;br /&gt;
       begin&lt;br /&gt;
         reg.WriteString('Filename',edit1.text);&lt;br /&gt;
       end;&lt;br /&gt;
      finally&lt;br /&gt;
       reg.Free;&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
A good example of the same is given below. This is done by re-factoring the business logic. In the below example this is done by storing the file in an registry in a separate class. &lt;br /&gt;
&lt;br /&gt;
    type&lt;br /&gt;
     TReference = class&lt;br /&gt;
     private  &lt;br /&gt;
       FFilename: string&lt;br /&gt;
       procedure SetFilename(const Value: string)&lt;br /&gt;
     public&lt;br /&gt;
       property Filename:string read FFilename write SetFilename;&lt;br /&gt;
       procedure Load;&lt;br /&gt;
       procedure Save;&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
The above code will call Save method from the click handler.&lt;br /&gt;
    procedure TForm1.ButtonClick  (Sender: Object);&lt;br /&gt;
    begin&lt;br /&gt;
       Preference.Save;&lt;br /&gt;
    end;&lt;br /&gt;
    procedure TForm1.EditChange (Sender: TObject);&lt;br /&gt;
    begin&lt;br /&gt;
      Preferences.Filename:= edit1.text;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Create functions and modularize the code as much as possible so that the code could be well maintained and flexible.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Object-oriented design anti-patterns==&lt;br /&gt;
Some of the important Object-oriented design anti-patterns are,&lt;br /&gt;
&lt;br /&gt;
===Anemic Domain Model===&lt;br /&gt;
Separating the [http://en.wikipedia.org/wiki/Business_logic business logic] from the [http://en.wikipedia.org/wiki/Domain_model Domain Model] is termed as Anemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's [http://en.wikipedia.org/wiki/Entity_Bean Entity beans] and .Net's three layered service application. A short example for Anemic Model is given below,&lt;br /&gt;
*'''Example'''&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Although, the above code looks right by providing segregation of data and service, its in violation of OOPs principle of data and behavior [http://en.wikipedia.org/wiki/Encapsulation encapsulation].It could run into problems when there are multiple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===BaseBean===&lt;br /&gt;
In the practice of BaseBean, subclasses are derived from an utility class, even though delegation is possible. [http://en.wikipedia.org/wiki/Inheritance Inheritance] can be evil sometimes, either breaking some subclass due to change in parent class or very deep hierarchy of classes leading to confusion and no reuse of code. For example, if we want to create a student class and we already have person class, inheritance is not the right way to go. &lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**We can use delegation and create instance of Person class in Student class and utilize all the features of class Person in class Student.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===CallSuper===&lt;br /&gt;
CallSuper is a anti-pattern in which subclass [http://en.wikipedia.org/wiki/Method_overriding overrides] a parent's method and calls the parent's overridden method from the same method. This is considered as a bad practice because, in the future if the parent class's implementation changes it breaks the subclass too. And also it puts an additional responsibility on the subclass's developer to call Super.The correct way to go about this is the parent class declaring a separate hook method for subclass to override.&lt;br /&gt;
*'''Example'''&lt;br /&gt;
  // '''Wrong Way'''                                                         // '''Correct Way'''&lt;br /&gt;
  public class EventHandle{                                             public class EventHandle{&lt;br /&gt;
    public void handle (BankingEvent e) {                                  public void handle (BankingEvent e) {&lt;br /&gt;
      cleanUp(e);                                                            cleanUp(e);&lt;br /&gt;
    }                                                                        doHandle(e);  //hook method&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
  public class TransferEventHandler extends EventHandle{                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    public void handle(BankingEvent e) {                                   }&lt;br /&gt;
      super.handle(e);                                                     public class TransferEventHandler extends EventHandle{&lt;br /&gt;
      initiateTransfer(e);                                                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    }                                                                           initiateTransfer(e);&lt;br /&gt;
                                                                             }&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
The significance of anti-patterns is the same as design patterns, anti-patterns are real helpful in identifying bad design.Thus the beforehand knowledge of anti-patterns comes in handy in making sure that the code base doesn't make use any of it. They should be identified at early stage of [http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle SDLC life cycle], because it might require significant effort to remove anti-patterns as you go down the SDLC life cycle.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Design_pattern_(computer_science) Design Patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Code_smell Code Smell]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Abstraction_inversion Abstraction Inversion]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Big_ball_of_mud Big Ball Of Mud]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Race_hazard Race Hazard]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Magic_pushbutton Magic Pushbutton]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern Anti-pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anemic_Domain_Model Anemic Domain Model]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/BaseBean BaseBean]&lt;br /&gt;
&lt;br /&gt;
==External Links==&lt;br /&gt;
&lt;br /&gt;
[1] [http://en.wikipedia.org/wiki/Anti-pattern AntiPattern]&amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://www.antipatterns.com/ &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://c2.com/cgi/wiki?AntiPattern &amp;lt;br&amp;gt;&lt;br /&gt;
[4] http://www.martinfowler.com/bliki/CallSuper.html &amp;lt;br&amp;gt;&lt;br /&gt;
[5] AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis by William J.Brown and Raphael C.Malveau&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27649</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27649"/>
		<updated>2009-11-17T21:34:26Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Magic Pushbutton */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti-patterns were used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system.&lt;br /&gt;
*Inexperience on the part of the programmer.&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
Anti-Patterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
Some of the widely used anti-patterns are classified into the following categories,&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Organizational_anti-patterns Organizational anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Project_management_anti-patterns Project management anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Analysis_anti-patterns Analysis anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Software_design_anti-patterns Software design anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Configuration_management_anti-patterns Configuration management anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Programming_anti-patterns Programming anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Methodological_anti-patterns Methodological anti-patterns]&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
Some of the important software design anti-patterns are,&lt;br /&gt;
===Abstraction Inversion===&lt;br /&gt;
Abstraction Inversion means implementing a lower level construct on top of high level constructs. A simple example would be suppose we have 2 constructs A and B. Let B be implemented on top of A but A is not exposed anywhere in the system and if we really require A then we end up building A on top of B and B was already implemented in terms of A.&lt;br /&gt;
A short example of Abstraction Inversion is given below&lt;br /&gt;
&lt;br /&gt;
* '''Example'''&lt;br /&gt;
The below code implements a set of binary values in a String which decide if it is true or false. (e.g. 'T' or 'F'). They then use the index to find the bit.&lt;br /&gt;
    char[] bitString ...;&lt;br /&gt;
    if (bitString[i] == 'T') { // do stuff&lt;br /&gt;
&lt;br /&gt;
So in this case we have a character representing a bit value, but a character is nothing but a sequence of bits. Therefore we have a sequence made up of characters containing bits which are made up of a bit sequence.&lt;br /&gt;
&lt;br /&gt;
* '''Solution'''&lt;br /&gt;
**Choose the infrastructure carefully.&lt;br /&gt;
**If the system offers equivalent functions, use them.&lt;br /&gt;
**Do not inject any weak constructs into the system.&lt;br /&gt;
&lt;br /&gt;
===Big ball of mud===&lt;br /&gt;
&lt;br /&gt;
This term was coined by Brain Foote and Joseph Yoder's paper in 1999. This kind of anti pattern arises over a period of time where a number of programmers have worked on a system on various pieces of code. Dur to the lack of knowledge of the current systems the programmers write code which may have already been present and results in a lot of redundant code. Information being shared across the system which may result in it being globally declared and eventually making the code unreadable and unmanageable.&lt;br /&gt;
&lt;br /&gt;
*'''Example'''&lt;br /&gt;
    float CalculateTotal(int quantity, float price){&lt;br /&gt;
       return quantity*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    float CalculateAmount(int amt, float price){&lt;br /&gt;
       return amt*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The above code shows two functions that perform the same function but was created which results in code redundancy and unreadable.&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Good understanding of the system prior to any major code changes.&lt;br /&gt;
**Modularizing the code and defining the functionality at the proper location can help reduce the code redundancy.&lt;br /&gt;
**Technical shifts(client-server to web based, file based to database based etc) can provide good reasons to create the system from scratch.&lt;br /&gt;
&lt;br /&gt;
===Race Hazard===&lt;br /&gt;
A race hazard or a race condition is a flaw in the system where the output of the system depends on the order in which the system executes. This leads to inconsistency in the output. This term was coined with the idea of two signals racing each other to influence each other.&lt;br /&gt;
&lt;br /&gt;
*'''Example'''&lt;br /&gt;
    global integer A = 0;&lt;br /&gt;
    //increments the value of A and prints &amp;quot;RX&amp;quot;&lt;br /&gt;
    // activated whenever an interrupt is received from the controller&lt;br /&gt;
    task Received()&lt;br /&gt;
    {&lt;br /&gt;
        A = A + 1&lt;br /&gt;
        print RX&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    //prints out only even numbers&lt;br /&gt;
    //is activated whenever an  interrupt is received from the serial controller&lt;br /&gt;
    task timeout()&lt;br /&gt;
    {&lt;br /&gt;
       if(A is divisible by 2)&lt;br /&gt;
       {&lt;br /&gt;
           print A&lt;br /&gt;
       }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    Output would look like &lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    2&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    4&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**[http://en.wikipedia.org/wiki/Mutex Mutexes] can be used to address this problem in concurrent programming.&lt;br /&gt;
&lt;br /&gt;
===Magic Pushbutton===&lt;br /&gt;
This is a very common anti-pattern that shows up on graphical user interfaces programming environments. The user first draws the user interface and then builds up the business logic in the automatically created methods.&lt;br /&gt;
Some of the issues faced in this are,&lt;br /&gt;
* The code for in those defined functions grow large.&lt;br /&gt;
* Change in the user interface leads to a lot of changes in the functions and becomes difficult to manage.&lt;br /&gt;
* Testing becomes an issue.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Example'''&lt;br /&gt;
Below is a Bad example of Magic PushButton Anti Pattern.    &lt;br /&gt;
    procedure TForm1.ButtonClick(Sender: TObject);&lt;br /&gt;
    var &lt;br /&gt;
       reg:TRegistry;&lt;br /&gt;
    begin&lt;br /&gt;
       reg:TRegistry.Create;&lt;br /&gt;
    try&lt;br /&gt;
       reg.RootKey:= HKey_Current_User;&lt;br /&gt;
       if reg.OpenKey('\Software\mycompany',true) then&lt;br /&gt;
       begin&lt;br /&gt;
         reg.WriteString('Filename',edit1.text);&lt;br /&gt;
       end;&lt;br /&gt;
      finally&lt;br /&gt;
       reg.Free;&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
A good example of the same is given below. This is done by re-factoring the business logic. In the below example this is done by storing the file in an registry in a separate class. &lt;br /&gt;
&lt;br /&gt;
    type&lt;br /&gt;
     TReference = class&lt;br /&gt;
     private  &lt;br /&gt;
       FFilename: string&lt;br /&gt;
       procedure SetFilename(const Value: string)&lt;br /&gt;
     public&lt;br /&gt;
       property Filename:string read FFilename write SetFilename;&lt;br /&gt;
       procedure Load;&lt;br /&gt;
       procedure Save;&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
The above code will call Save method from the click handler.&lt;br /&gt;
    procedure TForm1.ButtonClick  (Sender: Object);&lt;br /&gt;
    begin&lt;br /&gt;
       Preference.Save;&lt;br /&gt;
    end;&lt;br /&gt;
    procedure TForm1.EditChange (Sender: TObject);&lt;br /&gt;
    begin&lt;br /&gt;
      Preferences.Filename:= edit1.text;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Create functions and modularize the code as much as possible so that the code could be well maintained and flexible.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Object-oriented design anti-patterns==&lt;br /&gt;
Some of the important Object-oriented design anti-patterns are,&lt;br /&gt;
&lt;br /&gt;
===Anemic Domain Model===&lt;br /&gt;
Separating the [http://en.wikipedia.org/wiki/Business_logic business logic] from the [http://en.wikipedia.org/wiki/Domain_model Domain Model] is termed as Anemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's [http://en.wikipedia.org/wiki/Entity_Bean Entity beans] and .Net's three layered service application. A short example for Anaemic Model is given below,&lt;br /&gt;
*'''Example'''&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Although, the above code looks right by providing segregation of data and service, its in violation of OOPs principle of data and behavior [http://en.wikipedia.org/wiki/Encapsulation encapsulation].It could run into problems when there are multiple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
===BaseBean===&lt;br /&gt;
In the practice of BaseBean, subclasses are derived from an utility class, even though delegation is possible. [http://en.wikipedia.org/wiki/Inheritance Inheritance] can be evil sometimes, either breaking some subclass due to change in parent class or very deep hierarchy of classes leading to confusion and no reuse of code. For example, if we want to create a student class and we already have person class, inheritance is not the right way to go. &lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**We can use delegation and create instance of Person class in Student class and utilize all the features of class Person in class Student.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===CallSuper===&lt;br /&gt;
CallSuper is a anti-pattern in which subclass [http://en.wikipedia.org/wiki/Method_overriding overrides] a parent's method and calls the parent's overridden method from the same method. This is considered as a bad practice because, in the future if the parent class's implementation changes it breaks the subclass too. And also it puts an additional responsibility on the subclass's developer to call Super.The correct way to go about this is the parent class declaring a separate hook method for subclass to override.&lt;br /&gt;
*'''Example'''&lt;br /&gt;
  // '''Wrong Way'''                                                         // '''Correct Way'''&lt;br /&gt;
  public class EventHandle{                                             public class EventHandle{&lt;br /&gt;
    public void handle (BankingEvent e) {                                  public void handle (BankingEvent e) {&lt;br /&gt;
      cleanUp(e);                                                            cleanUp(e);&lt;br /&gt;
    }                                                                        doHandle(e);  //hook method&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
  public class TransferEventHandler extends EventHandle{                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    public void handle(BankingEvent e) {                                   }&lt;br /&gt;
      super.handle(e);                                                     public class TransferEventHandler extends EventHandle{&lt;br /&gt;
      initiateTransfer(e);                                                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    }                                                                           initiateTransfer(e);&lt;br /&gt;
                                                                             }&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
The significance of anti-patterns is the same as design patterns, anti-patterns are real helpful in identifying bad design.Thus the beforehand knowledge of anti-patterns comes in handy in making sure that the code base doesn't make use any of it. They should be identified at early stage of [http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle SDLC life cycle], because it might require significant effort to remove anti-patterns as you go down the SDLC life cycle.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Design_pattern_(computer_science) Design Patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Code_smell Code Smell]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Abstraction_inversion Abstraction Inversion]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Big_ball_of_mud Big Ball Of Mud]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Race_hazard Race Hazard]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Magic_pushbutton Magic Pushbutton]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern Anti-pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anemic_Domain_Model Anemic Domain Model]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/BaseBean BaseBean]&lt;br /&gt;
&lt;br /&gt;
==External Links==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.antipatterns.com/ &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://c2.com/cgi/wiki?AntiPattern &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.martinfowler.com/bliki/CallSuper.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis by William J.Brown and Raphael C.Malveau&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27647</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27647"/>
		<updated>2009-11-17T21:33:56Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Magic Pushbutton */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti-patterns were used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system.&lt;br /&gt;
*Inexperience on the part of the programmer.&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
Anti-Patterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
Some of the widely used anti-patterns are classified into the following categories,&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Organizational_anti-patterns Organizational anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Project_management_anti-patterns Project management anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Analysis_anti-patterns Analysis anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Software_design_anti-patterns Software design anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Configuration_management_anti-patterns Configuration management anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Programming_anti-patterns Programming anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Methodological_anti-patterns Methodological anti-patterns]&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
===Abstraction Inversion===&lt;br /&gt;
Abstraction Inversion means implementing a lower level construct on top of high level constructs. A simple example would be suppose we have 2 constructs A and B. Let B be implemented on top of A but A is not exposed anywhere in the system and if we really require A then we end up building A on top of B and B was already implemented in terms of A.&lt;br /&gt;
A short example of Abstraction Inversion is given below&lt;br /&gt;
&lt;br /&gt;
* '''Example'''&lt;br /&gt;
The below code implements a set of binary values in a String which decide if it is true or false. (e.g. 'T' or 'F'). They then use the index to find the bit.&lt;br /&gt;
    char[] bitString ...;&lt;br /&gt;
    if (bitString[i] == 'T') { // do stuff&lt;br /&gt;
&lt;br /&gt;
So in this case we have a character representing a bit value, but a character is nothing but a sequence of bits. Therefore we have a sequence made up of characters containing bits which are made up of a bit sequence.&lt;br /&gt;
&lt;br /&gt;
* '''Solution'''&lt;br /&gt;
**Choose the infrastructure carefully.&lt;br /&gt;
**If the system offers equivalent functions, use them.&lt;br /&gt;
**Do not inject any weak constructs into the system.&lt;br /&gt;
&lt;br /&gt;
===Big ball of mud===&lt;br /&gt;
&lt;br /&gt;
This term was coined by Brain Foote and Joseph Yoder's paper in 1999. This kind of anti pattern arises over a period of time where a number of programmers have worked on a system on various pieces of code. Dur to the lack of knowledge of the current systems the programmers write code which may have already been present and results in a lot of redundant code. Information being shared across the system which may result in it being globally declared and eventually making the code unreadable and unmanageable.&lt;br /&gt;
&lt;br /&gt;
*'''Example'''&lt;br /&gt;
    float CalculateTotal(int quantity, float price){&lt;br /&gt;
       return quantity*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    float CalculateAmount(int amt, float price){&lt;br /&gt;
       return amt*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The above code shows two functions that perform the same function but was created which results in code redundancy and unreadable.&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Good understanding of the system prior to any major code changes.&lt;br /&gt;
**Modularizing the code and defining the functionality at the proper location can help reduce the code redundancy.&lt;br /&gt;
**Technical shifts(client-server to web based, file based to database based etc) can provide good reasons to create the system from scratch.&lt;br /&gt;
&lt;br /&gt;
===Race Hazard===&lt;br /&gt;
A race hazard or a race condition is a flaw in the system where the output of the system depends on the order in which the system executes. This leads to inconsistency in the output. This term was coined with the idea of two signals racing each other to influence each other.&lt;br /&gt;
&lt;br /&gt;
*'''Example'''&lt;br /&gt;
    global integer A = 0;&lt;br /&gt;
    //increments the value of A and prints &amp;quot;RX&amp;quot;&lt;br /&gt;
    // activated whenever an interrupt is received from the controller&lt;br /&gt;
    task Received()&lt;br /&gt;
    {&lt;br /&gt;
        A = A + 1&lt;br /&gt;
        print RX&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    //prints out only even numbers&lt;br /&gt;
    //is activated whenever an  interrupt is received from the serial controller&lt;br /&gt;
    task timeout()&lt;br /&gt;
    {&lt;br /&gt;
       if(A is divisible by 2)&lt;br /&gt;
       {&lt;br /&gt;
           print A&lt;br /&gt;
       }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    Output would look like &lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    2&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    4&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**[http://en.wikipedia.org/wiki/Mutex Mutexes] can be used to address this problem in concurrent programming.&lt;br /&gt;
&lt;br /&gt;
===Magic Pushbutton===&lt;br /&gt;
This is a very common anti-pattern that shows up on graphical user interfaces programming environments. The user first draws the user interface and then builds up the business logic in the automatically created methods.&lt;br /&gt;
Some of the issues faced in this are,&lt;br /&gt;
* The code for in those defined functions grow large.&lt;br /&gt;
* Change in the user interface leads to a lot of changes in the functions and becomes difficult to manage.&lt;br /&gt;
* Testing becomes an issue.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Example'''&lt;br /&gt;
Below is a Bad example of Magic PushButton Anti Pattern.    &lt;br /&gt;
    procedure TForm1.ButtonClick(Sender: TObject);&lt;br /&gt;
    var &lt;br /&gt;
       reg:TRegistry;&lt;br /&gt;
    begin&lt;br /&gt;
       reg:TRegistry.Create;&lt;br /&gt;
    try&lt;br /&gt;
       reg.RootKey:= HKey_Current_User;&lt;br /&gt;
       if reg.OpenKey('\Software\mycompany',true) then&lt;br /&gt;
       begin&lt;br /&gt;
         reg.WriteString('Filename',edit1.text);&lt;br /&gt;
       end;&lt;br /&gt;
      finally&lt;br /&gt;
       reg.Free;&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
A good example of the same is given below. This is done by re-factoring the business logic. In the below example this is done by storing the file in an registry in a separate class. &lt;br /&gt;
&lt;br /&gt;
    type&lt;br /&gt;
     TReference = class&lt;br /&gt;
     private  &lt;br /&gt;
       FFilename: string&lt;br /&gt;
       procedure SetFilename(const Value: string)&lt;br /&gt;
     public&lt;br /&gt;
       property Filename:string read FFilename write SetFilename;&lt;br /&gt;
       procedure Load;&lt;br /&gt;
       procedure Save;&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
The above code will call Save method from the click handler.&lt;br /&gt;
    procedure TForm1.ButtonClick  (Sender: Object);&lt;br /&gt;
    begin&lt;br /&gt;
       Preference.Save;&lt;br /&gt;
    end;&lt;br /&gt;
    procedure TForm1.EditChange (Sender: TObject);&lt;br /&gt;
    begin&lt;br /&gt;
      Preferences.Filename:= edit1.text;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
* Create functions and modularize the code as much as possible so that the code could be well maintained and flexible.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Object-oriented design anti-patterns==&lt;br /&gt;
Some of the important Object-oriented design anti-patterns are,&lt;br /&gt;
&lt;br /&gt;
===Anemic Domain Model===&lt;br /&gt;
Separating the [http://en.wikipedia.org/wiki/Business_logic business logic] from the [http://en.wikipedia.org/wiki/Domain_model Domain Model] is termed as Anemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's [http://en.wikipedia.org/wiki/Entity_Bean Entity beans] and .Net's three layered service application. A short example for Anaemic Model is given below,&lt;br /&gt;
*'''Example'''&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Although, the above code looks right by providing segregation of data and service, its in violation of OOPs principle of data and behavior [http://en.wikipedia.org/wiki/Encapsulation encapsulation].It could run into problems when there are multiple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
===BaseBean===&lt;br /&gt;
In the practice of BaseBean, subclasses are derived from an utility class, even though delegation is possible. [http://en.wikipedia.org/wiki/Inheritance Inheritance] can be evil sometimes, either breaking some subclass due to change in parent class or very deep hierarchy of classes leading to confusion and no reuse of code. For example, if we want to create a student class and we already have person class, inheritance is not the right way to go. &lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**We can use delegation and create instance of Person class in Student class and utilize all the features of class Person in class Student.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===CallSuper===&lt;br /&gt;
CallSuper is a anti-pattern in which subclass [http://en.wikipedia.org/wiki/Method_overriding overrides] a parent's method and calls the parent's overridden method from the same method. This is considered as a bad practice because, in the future if the parent class's implementation changes it breaks the subclass too. And also it puts an additional responsibility on the subclass's developer to call Super.The correct way to go about this is the parent class declaring a separate hook method for subclass to override.&lt;br /&gt;
*'''Example'''&lt;br /&gt;
  // '''Wrong Way'''                                                         // '''Correct Way'''&lt;br /&gt;
  public class EventHandle{                                             public class EventHandle{&lt;br /&gt;
    public void handle (BankingEvent e) {                                  public void handle (BankingEvent e) {&lt;br /&gt;
      cleanUp(e);                                                            cleanUp(e);&lt;br /&gt;
    }                                                                        doHandle(e);  //hook method&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
  public class TransferEventHandler extends EventHandle{                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    public void handle(BankingEvent e) {                                   }&lt;br /&gt;
      super.handle(e);                                                     public class TransferEventHandler extends EventHandle{&lt;br /&gt;
      initiateTransfer(e);                                                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    }                                                                           initiateTransfer(e);&lt;br /&gt;
                                                                             }&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
The significance of anti-patterns is the same as design patterns, anti-patterns are real helpful in identifying bad design.Thus the beforehand knowledge of anti-patterns comes in handy in making sure that the code base doesn't make use any of it. They should be identified at early stage of [http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle SDLC life cycle], because it might require significant effort to remove anti-patterns as you go down the SDLC life cycle.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Design_pattern_(computer_science) Design Patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Code_smell Code Smell]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Abstraction_inversion Abstraction Inversion]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Big_ball_of_mud Big Ball Of Mud]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Race_hazard Race Hazard]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Magic_pushbutton Magic Pushbutton]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern Anti-pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anemic_Domain_Model Anemic Domain Model]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/BaseBean BaseBean]&lt;br /&gt;
&lt;br /&gt;
==External Links==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.antipatterns.com/ &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://c2.com/cgi/wiki?AntiPattern &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.martinfowler.com/bliki/CallSuper.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis by William J.Brown and Raphael C.Malveau&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27646</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27646"/>
		<updated>2009-11-17T21:33:04Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Race Hazard */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti-patterns were used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system.&lt;br /&gt;
*Inexperience on the part of the programmer.&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
Anti-Patterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
Some of the widely used anti-patterns are classified into the following categories,&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Organizational_anti-patterns Organizational anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Project_management_anti-patterns Project management anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Analysis_anti-patterns Analysis anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Software_design_anti-patterns Software design anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Configuration_management_anti-patterns Configuration management anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Programming_anti-patterns Programming anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Methodological_anti-patterns Methodological anti-patterns]&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
===Abstraction Inversion===&lt;br /&gt;
Abstraction Inversion means implementing a lower level construct on top of high level constructs. A simple example would be suppose we have 2 constructs A and B. Let B be implemented on top of A but A is not exposed anywhere in the system and if we really require A then we end up building A on top of B and B was already implemented in terms of A.&lt;br /&gt;
A short example of Abstraction Inversion is given below&lt;br /&gt;
&lt;br /&gt;
* '''Example'''&lt;br /&gt;
The below code implements a set of binary values in a String which decide if it is true or false. (e.g. 'T' or 'F'). They then use the index to find the bit.&lt;br /&gt;
    char[] bitString ...;&lt;br /&gt;
    if (bitString[i] == 'T') { // do stuff&lt;br /&gt;
&lt;br /&gt;
So in this case we have a character representing a bit value, but a character is nothing but a sequence of bits. Therefore we have a sequence made up of characters containing bits which are made up of a bit sequence.&lt;br /&gt;
&lt;br /&gt;
* '''Solution'''&lt;br /&gt;
**Choose the infrastructure carefully.&lt;br /&gt;
**If the system offers equivalent functions, use them.&lt;br /&gt;
**Do not inject any weak constructs into the system.&lt;br /&gt;
&lt;br /&gt;
===Big ball of mud===&lt;br /&gt;
&lt;br /&gt;
This term was coined by Brain Foote and Joseph Yoder's paper in 1999. This kind of anti pattern arises over a period of time where a number of programmers have worked on a system on various pieces of code. Dur to the lack of knowledge of the current systems the programmers write code which may have already been present and results in a lot of redundant code. Information being shared across the system which may result in it being globally declared and eventually making the code unreadable and unmanageable.&lt;br /&gt;
&lt;br /&gt;
*'''Example'''&lt;br /&gt;
    float CalculateTotal(int quantity, float price){&lt;br /&gt;
       return quantity*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    float CalculateAmount(int amt, float price){&lt;br /&gt;
       return amt*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The above code shows two functions that perform the same function but was created which results in code redundancy and unreadable.&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Good understanding of the system prior to any major code changes.&lt;br /&gt;
**Modularizing the code and defining the functionality at the proper location can help reduce the code redundancy.&lt;br /&gt;
**Technical shifts(client-server to web based, file based to database based etc) can provide good reasons to create the system from scratch.&lt;br /&gt;
&lt;br /&gt;
===Race Hazard===&lt;br /&gt;
A race hazard or a race condition is a flaw in the system where the output of the system depends on the order in which the system executes. This leads to inconsistency in the output. This term was coined with the idea of two signals racing each other to influence each other.&lt;br /&gt;
&lt;br /&gt;
*'''Example'''&lt;br /&gt;
    global integer A = 0;&lt;br /&gt;
    //increments the value of A and prints &amp;quot;RX&amp;quot;&lt;br /&gt;
    // activated whenever an interrupt is received from the controller&lt;br /&gt;
    task Received()&lt;br /&gt;
    {&lt;br /&gt;
        A = A + 1&lt;br /&gt;
        print RX&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    //prints out only even numbers&lt;br /&gt;
    //is activated whenever an  interrupt is received from the serial controller&lt;br /&gt;
    task timeout()&lt;br /&gt;
    {&lt;br /&gt;
       if(A is divisible by 2)&lt;br /&gt;
       {&lt;br /&gt;
           print A&lt;br /&gt;
       }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    Output would look like &lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    2&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    4&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**[http://en.wikipedia.org/wiki/Mutex Mutexes] can be used to address this problem in concurrent programming.&lt;br /&gt;
&lt;br /&gt;
===Magic Pushbutton===&lt;br /&gt;
This is a very common anti pattern that shows up on graphical user interfaces programming environments. The user first draws the user interface and then builds up the business logic in the automatically created methods.&lt;br /&gt;
Some of the issues faced in this are,&lt;br /&gt;
*The code for in those defined functions grow large.&lt;br /&gt;
*Change in the user interface leads to a lot of changes in the functions and becomes difficult to manage.&lt;br /&gt;
*Testing becomes an issue.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Example'''&lt;br /&gt;
Below is a Bad example of Magic PushButton Anti Pattern.    &lt;br /&gt;
    procedure TForm1.ButtonClick(Sender: TObject);&lt;br /&gt;
    var &lt;br /&gt;
       reg:TRegistry;&lt;br /&gt;
    begin&lt;br /&gt;
       reg:TRegistry.Create;&lt;br /&gt;
    try&lt;br /&gt;
       reg.RootKey:= HKey_Current_User;&lt;br /&gt;
       if reg.OpenKey('\Software\mycompany',true) then&lt;br /&gt;
       begin&lt;br /&gt;
         reg.WriteString('Filename',edit1.text);&lt;br /&gt;
       end;&lt;br /&gt;
      finally&lt;br /&gt;
       reg.Free;&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
A good example of the same is given below. This is done by re-factoring the business logic. In the below example this is done by storing the file in an registry in a separate class. &lt;br /&gt;
&lt;br /&gt;
    type&lt;br /&gt;
     TReference = class&lt;br /&gt;
     private  &lt;br /&gt;
       FFilename: string&lt;br /&gt;
       procedure SetFilename(const Value: string)&lt;br /&gt;
     public&lt;br /&gt;
       property Filename:string read FFilename write SetFilename;&lt;br /&gt;
       procedure Load;&lt;br /&gt;
       procedure Save;&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
The above code will call Save method from the click handler.&lt;br /&gt;
    procedure TForm1.ButtonClick  (Sender: Object);&lt;br /&gt;
    begin&lt;br /&gt;
       Preference.Save;&lt;br /&gt;
    end;&lt;br /&gt;
    procedure TForm1.EditChange (Sender: TObject);&lt;br /&gt;
    begin&lt;br /&gt;
      Preferences.Filename:= edit1.text;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Create functions and modularize the code as much as possible so that the code could be well maintained and flexible.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
==Object-oriented design anti-patterns==&lt;br /&gt;
Some of the important Object-oriented design anti-patterns are,&lt;br /&gt;
&lt;br /&gt;
===Anemic Domain Model===&lt;br /&gt;
Separating the [http://en.wikipedia.org/wiki/Business_logic business logic] from the [http://en.wikipedia.org/wiki/Domain_model Domain Model] is termed as Anemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's [http://en.wikipedia.org/wiki/Entity_Bean Entity beans] and .Net's three layered service application. A short example for Anaemic Model is given below,&lt;br /&gt;
*'''Example'''&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Although, the above code looks right by providing segregation of data and service, its in violation of OOPs principle of data and behavior [http://en.wikipedia.org/wiki/Encapsulation encapsulation].It could run into problems when there are multiple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
===BaseBean===&lt;br /&gt;
In the practice of BaseBean, subclasses are derived from an utility class, even though delegation is possible. [http://en.wikipedia.org/wiki/Inheritance Inheritance] can be evil sometimes, either breaking some subclass due to change in parent class or very deep hierarchy of classes leading to confusion and no reuse of code. For example, if we want to create a student class and we already have person class, inheritance is not the right way to go. &lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**We can use delegation and create instance of Person class in Student class and utilize all the features of class Person in class Student.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===CallSuper===&lt;br /&gt;
CallSuper is a anti-pattern in which subclass [http://en.wikipedia.org/wiki/Method_overriding overrides] a parent's method and calls the parent's overridden method from the same method. This is considered as a bad practice because, in the future if the parent class's implementation changes it breaks the subclass too. And also it puts an additional responsibility on the subclass's developer to call Super.The correct way to go about this is the parent class declaring a separate hook method for subclass to override.&lt;br /&gt;
*'''Example'''&lt;br /&gt;
  // '''Wrong Way'''                                                         // '''Correct Way'''&lt;br /&gt;
  public class EventHandle{                                             public class EventHandle{&lt;br /&gt;
    public void handle (BankingEvent e) {                                  public void handle (BankingEvent e) {&lt;br /&gt;
      cleanUp(e);                                                            cleanUp(e);&lt;br /&gt;
    }                                                                        doHandle(e);  //hook method&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
  public class TransferEventHandler extends EventHandle{                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    public void handle(BankingEvent e) {                                   }&lt;br /&gt;
      super.handle(e);                                                     public class TransferEventHandler extends EventHandle{&lt;br /&gt;
      initiateTransfer(e);                                                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    }                                                                           initiateTransfer(e);&lt;br /&gt;
                                                                             }&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
The significance of anti-patterns is the same as design patterns, anti-patterns are real helpful in identifying bad design.Thus the beforehand knowledge of anti-patterns comes in handy in making sure that the code base doesn't make use any of it. They should be identified at early stage of [http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle SDLC life cycle], because it might require significant effort to remove anti-patterns as you go down the SDLC life cycle.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Design_pattern_(computer_science) Design Patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Code_smell Code Smell]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Abstraction_inversion Abstraction Inversion]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Big_ball_of_mud Big Ball Of Mud]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Race_hazard Race Hazard]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Magic_pushbutton Magic Pushbutton]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern Anti-pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anemic_Domain_Model Anemic Domain Model]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/BaseBean BaseBean]&lt;br /&gt;
&lt;br /&gt;
==External Links==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.antipatterns.com/ &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://c2.com/cgi/wiki?AntiPattern &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.martinfowler.com/bliki/CallSuper.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis by William J.Brown and Raphael C.Malveau&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27642</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27642"/>
		<updated>2009-11-17T21:30:39Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Abstraction Inversion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti-patterns were used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system.&lt;br /&gt;
*Inexperience on the part of the programmer.&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
Anti-Patterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
Some of the widely used anti-patterns are classified into the following categories,&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Organizational_anti-patterns Organizational anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Project_management_anti-patterns Project management anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Analysis_anti-patterns Analysis anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Software_design_anti-patterns Software design anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Configuration_management_anti-patterns Configuration management anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Programming_anti-patterns Programming anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Methodological_anti-patterns Methodological anti-patterns]&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
===Abstraction Inversion===&lt;br /&gt;
Abstraction Inversion means implementing a lower level construct on top of high level constructs. A simple example would be suppose we have 2 constructs A and B. Let B be implemented on top of A but A is not exposed anywhere in the system and if we really require A then we end up building A on top of B and B was already implemented in terms of A.&lt;br /&gt;
A short example of Abstraction Inversion is given below&lt;br /&gt;
&lt;br /&gt;
* '''Example'''&lt;br /&gt;
The below code implements a set of binary values in a String which decide if it is true or false. (e.g. 'T' or 'F'). They then use the index to find the bit.&lt;br /&gt;
    char[] bitString ...;&lt;br /&gt;
    if (bitString[i] == 'T') { // do stuff&lt;br /&gt;
&lt;br /&gt;
So in this case we have a character representing a bit value, but a character is nothing but a sequence of bits. Therefore we have a sequence made up of characters containing bits which are made up of a bit sequence.&lt;br /&gt;
&lt;br /&gt;
* '''Solution'''&lt;br /&gt;
**Choose the infrastructure carefully.&lt;br /&gt;
**If the system offers equivalent functions, use them.&lt;br /&gt;
**Do not inject any weak constructs into the system.&lt;br /&gt;
&lt;br /&gt;
===Big ball of mud===&lt;br /&gt;
&lt;br /&gt;
This term was coined by Brain Foote and Joseph Yoder's paper in 1999. This kind of anti pattern arises over a period of time where a number of programmers have worked on a system on various pieces of code. Dur to the lack of knowledge of the current systems the programmers write code which may have already been present and results in a lot of redundant code. Information being shared across the system which may result in it being globally declared and eventually making the code unreadable and unmanageable.&lt;br /&gt;
&lt;br /&gt;
*'''Example'''&lt;br /&gt;
    float CalculateTotal(int quantity, float price){&lt;br /&gt;
       return quantity*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    float CalculateAmount(int amt, float price){&lt;br /&gt;
       return amt*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The above code shows two functions that perform the same function but was created which results in code redundancy and unreadable.&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Good understanding of the system prior to any major code changes.&lt;br /&gt;
**Modularizing the code and defining the functionality at the proper location can help reduce the code redundancy.&lt;br /&gt;
**Technical shifts(client-server to web based, file based to database based etc) can provide good reasons to create the system from scratch.&lt;br /&gt;
&lt;br /&gt;
===Race Hazard===&lt;br /&gt;
A race hazard or a race condition is a flaw in the system where the output of the system depends on the order in which the system executes. This leads to inconsistency in the output. This term was coined with the idea of two signals racing each other to influence each other.&lt;br /&gt;
&lt;br /&gt;
*'''Example'''&lt;br /&gt;
    global integer A = 0;&lt;br /&gt;
    //increments the value of A and prints &amp;quot;RX&amp;quot;&lt;br /&gt;
    // activated whenever an interrupt is received from the controller&lt;br /&gt;
    task Received()&lt;br /&gt;
    {&lt;br /&gt;
        A = A + 1&lt;br /&gt;
        print RX&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    //prints out only even numbers&lt;br /&gt;
    //is activated whenever an  interrupt is received from the serial controller&lt;br /&gt;
    task timeout()&lt;br /&gt;
    {&lt;br /&gt;
       if(A is divisible by 2)&lt;br /&gt;
       {&lt;br /&gt;
           print A&lt;br /&gt;
       }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    Output would look like &lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    2&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    4&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Mutexes can be used to address this problem in concurrent programming.&lt;br /&gt;
&lt;br /&gt;
===Magic Pushbutton===&lt;br /&gt;
This is a very common anti pattern that shows up on graphical user interfaces programming environments. The user first draws the user interface and then builds up the business logic in the automatically created methods.&lt;br /&gt;
Some of the issues faced in this are,&lt;br /&gt;
*The code for in those defined functions grow large.&lt;br /&gt;
*Change in the user interface leads to a lot of changes in the functions and becomes difficult to manage.&lt;br /&gt;
*Testing becomes an issue.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Example'''&lt;br /&gt;
Below is a Bad example of Magic PushButton Anti Pattern.    &lt;br /&gt;
    procedure TForm1.ButtonClick(Sender: TObject);&lt;br /&gt;
    var &lt;br /&gt;
       reg:TRegistry;&lt;br /&gt;
    begin&lt;br /&gt;
       reg:TRegistry.Create;&lt;br /&gt;
    try&lt;br /&gt;
       reg.RootKey:= HKey_Current_User;&lt;br /&gt;
       if reg.OpenKey('\Software\mycompany',true) then&lt;br /&gt;
       begin&lt;br /&gt;
         reg.WriteString('Filename',edit1.text);&lt;br /&gt;
       end;&lt;br /&gt;
      finally&lt;br /&gt;
       reg.Free;&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
A good example of the same is given below. This is done by re-factoring the business logic. In the below example this is done by storing the file in an registry in a separate class. &lt;br /&gt;
&lt;br /&gt;
    type&lt;br /&gt;
     TReference = class&lt;br /&gt;
     private  &lt;br /&gt;
       FFilename: string&lt;br /&gt;
       procedure SetFilename(const Value: string)&lt;br /&gt;
     public&lt;br /&gt;
       property Filename:string read FFilename write SetFilename;&lt;br /&gt;
       procedure Load;&lt;br /&gt;
       procedure Save;&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
The above code will call Save method from the click handler.&lt;br /&gt;
    procedure TForm1.ButtonClick  (Sender: Object);&lt;br /&gt;
    begin&lt;br /&gt;
       Preference.Save;&lt;br /&gt;
    end;&lt;br /&gt;
    procedure TForm1.EditChange (Sender: TObject);&lt;br /&gt;
    begin&lt;br /&gt;
      Preferences.Filename:= edit1.text;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Create functions and modularize the code as much as possible so that the code could be well maintained and flexible.&lt;br /&gt;
&lt;br /&gt;
==Object-oriented design anti-patterns==&lt;br /&gt;
Some of the important Object-oriented design anti-patterns are,&lt;br /&gt;
&lt;br /&gt;
===Anemic Domain Model===&lt;br /&gt;
Separating the [http://en.wikipedia.org/wiki/Business_logic business logic] from the [http://en.wikipedia.org/wiki/Domain_model Domain Model] is termed as Anemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's [http://en.wikipedia.org/wiki/Entity_Bean Entity beans] and .Net's three layered service application. A short example for Anaemic Model is given below,&lt;br /&gt;
*'''Example'''&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Although, the above code looks right by providing segregation of data and service, its in violation of OOPs principle of data and behavior [http://en.wikipedia.org/wiki/Encapsulation encapsulation].It could run into problems when there are multiple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
===BaseBean===&lt;br /&gt;
In the practice of BaseBean, subclasses are derived from an utility class, even though delegation is possible. [http://en.wikipedia.org/wiki/Inheritance Inheritance] can be evil sometimes, either breaking some subclass due to change in parent class or very deep hierarchy of classes leading to confusion and no reuse of code. For example, if we want to create a student class and we already have person class, inheritance is not the right way to go. &lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**We can use delegation and create instance of Person class in Student class and utilize all the features of class Person in class Student.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===CallSuper===&lt;br /&gt;
CallSuper is a anti-pattern in which subclass [http://en.wikipedia.org/wiki/Method_overriding overrides] a parent's method and calls the parent's overridden method from the same method. This is considered as a bad practice because, in the future if the parent class's implementation changes it breaks the subclass too. And also it puts an additional responsibility on the subclass's developer to call Super.The correct way to go about this is the parent class declaring a separate hook method for subclass to override.&lt;br /&gt;
*'''Example'''&lt;br /&gt;
  // '''Wrong Way'''                                                         // '''Correct Way'''&lt;br /&gt;
  public class EventHandle{                                             public class EventHandle{&lt;br /&gt;
    public void handle (BankingEvent e) {                                  public void handle (BankingEvent e) {&lt;br /&gt;
      cleanUp(e);                                                            cleanUp(e);&lt;br /&gt;
    }                                                                        doHandle(e);  //hook method&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
  public class TransferEventHandler extends EventHandle{                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    public void handle(BankingEvent e) {                                   }&lt;br /&gt;
      super.handle(e);                                                     public class TransferEventHandler extends EventHandle{&lt;br /&gt;
      initiateTransfer(e);                                                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    }                                                                           initiateTransfer(e);&lt;br /&gt;
                                                                             }&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
The significance of anti-patterns is the same as design patterns, anti-patterns are real helpful in identifying bad design.Thus the beforehand knowledge of anti-patterns comes in handy in making sure that the code base doesn't make use any of it. They should be identified at early stage of [http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle SDLC life cycle], because it might require significant effort to remove anti-patterns as you go down the SDLC life cycle.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Design_pattern_(computer_science) Design Patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Code_smell Code Smell]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Abstraction_inversion Abstraction Inversion]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Big_ball_of_mud Big Ball Of Mud]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Race_hazard Race Hazard]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Magic_pushbutton Magic Pushbutton]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern Anti-pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anemic_Domain_Model Anemic Domain Model]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/BaseBean BaseBean]&lt;br /&gt;
&lt;br /&gt;
==External Links==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.antipatterns.com/ &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://c2.com/cgi/wiki?AntiPattern &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.martinfowler.com/bliki/CallSuper.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis by William J.Brown and Raphael C.Malveau&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27638</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27638"/>
		<updated>2009-11-17T21:28:56Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Abstraction Inversion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti-patterns were used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system.&lt;br /&gt;
*Inexperience on the part of the programmer.&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
Anti-Patterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
Some of the widely used anti-patterns are classified into the following categories,&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Organizational_anti-patterns Organizational anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Project_management_anti-patterns Project management anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Analysis_anti-patterns Analysis anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Software_design_anti-patterns Software design anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Configuration_management_anti-patterns Configuration management anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Programming_anti-patterns Programming anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Methodological_anti-patterns Methodological anti-patterns]&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
===Abstraction Inversion===&lt;br /&gt;
Abstraction Inversion means implementing a lower level construct on top of high level constructs. A simple example would be suppose we have 2 constructs A and B. Let B be implemented on top of A but A is not exposed anywhere in the system and if we really require A then we end up building A on top of B and B was already implemented in terms of A.&lt;br /&gt;
A short example of Abstraction Inversion is given below&lt;br /&gt;
&lt;br /&gt;
* '''Example'''&lt;br /&gt;
The below code implements a set of binary values in a String which decide if it is true or false. (e.g. 'T' or 'F'). They then use the indexer to find the bit.&lt;br /&gt;
    char[] bitString ...;&lt;br /&gt;
    if (bitString[i] == 'T') { // do stuff&lt;br /&gt;
&lt;br /&gt;
So in this case we have a character representing a bit value, but a character is nothing but a sequence of bits. Therefore we have a sequence made up of characters containing bits which are made up of a bit sequence.&lt;br /&gt;
&lt;br /&gt;
* '''Solution'''&lt;br /&gt;
**Choose the infrastructure carefully.&lt;br /&gt;
**If the system offers equivalent functions, use them.&lt;br /&gt;
**Do not inject any weak constructs into the system.&lt;br /&gt;
&lt;br /&gt;
===Big ball of mud===&lt;br /&gt;
&lt;br /&gt;
This term was coined by Brain Foote and Joseph Yoder's paper in 1999. This kind of anti pattern arises over a period of time where a number of programmers have worked on a system on various pieces of code. Dur to the lack of knowledge of the current systems the programmers write code which may have already been present and results in a lot of redundant code. Information being shared across the system which may result in it being globally declared and eventually making the code unreadable and unmanageable.&lt;br /&gt;
&lt;br /&gt;
*'''Example'''&lt;br /&gt;
    float CalculateTotal(int quantity, float price){&lt;br /&gt;
       return quantity*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    float CalculateAmount(int amt, float price){&lt;br /&gt;
       return amt*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The above code shows two functions that perform the same function but was created which results in code redundancy and unreadable.&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Good understanding of the system prior to any major code changes.&lt;br /&gt;
**Modularizing the code and defining the functionality at the proper location can help reduce the code redundancy.&lt;br /&gt;
**Technical shifts(client-server to web based, file based to database based etc) can provide good reasons to create the system from scratch.&lt;br /&gt;
&lt;br /&gt;
===Race Hazard===&lt;br /&gt;
A race hazard or a race condition is a flaw in the system where the output of the system depends on the order in which the system executes. This leads to inconsistency in the output. This term was coined with the idea of two signals racing each other to influence each other.&lt;br /&gt;
&lt;br /&gt;
*'''Example'''&lt;br /&gt;
    global integer A = 0;&lt;br /&gt;
    //increments the value of A and prints &amp;quot;RX&amp;quot;&lt;br /&gt;
    // activated whenever an interrupt is received from the controller&lt;br /&gt;
    task Received()&lt;br /&gt;
    {&lt;br /&gt;
        A = A + 1&lt;br /&gt;
        print RX&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    //prints out only even numbers&lt;br /&gt;
    //is activated whenever an  interrupt is received from the serial controller&lt;br /&gt;
    task timeout()&lt;br /&gt;
    {&lt;br /&gt;
       if(A is divisible by 2)&lt;br /&gt;
       {&lt;br /&gt;
           print A&lt;br /&gt;
       }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    Output would look like &lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    2&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    4&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Mutexes can be used to address this problem in concurrent programming.&lt;br /&gt;
&lt;br /&gt;
===Magic Pushbutton===&lt;br /&gt;
This is a very common anti pattern that shows up on graphical user interfaces programming environments. The user first draws the user interface and then builds up the business logic in the automatically created methods.&lt;br /&gt;
Some of the issues faced in this are,&lt;br /&gt;
*The code for in those defined functions grow large.&lt;br /&gt;
*Change in the user interface leads to a lot of changes in the functions and becomes difficult to manage.&lt;br /&gt;
*Testing becomes an issue.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Example'''&lt;br /&gt;
Below is a Bad example of Magic PushButton Anti Pattern.    &lt;br /&gt;
    procedure TForm1.ButtonClick(Sender: TObject);&lt;br /&gt;
    var &lt;br /&gt;
       reg:TRegistry;&lt;br /&gt;
    begin&lt;br /&gt;
       reg:TRegistry.Create;&lt;br /&gt;
    try&lt;br /&gt;
       reg.RootKey:= HKey_Current_User;&lt;br /&gt;
       if reg.OpenKey('\Software\mycompany',true) then&lt;br /&gt;
       begin&lt;br /&gt;
         reg.WriteString('Filename',edit1.text);&lt;br /&gt;
       end;&lt;br /&gt;
      finally&lt;br /&gt;
       reg.Free;&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
A good example of the same is given below. This is done by re-factoring the business logic. In the below example this is done by storing the file in an registry in a separate class. &lt;br /&gt;
&lt;br /&gt;
    type&lt;br /&gt;
     TReference = class&lt;br /&gt;
     private  &lt;br /&gt;
       FFilename: string&lt;br /&gt;
       procedure SetFilename(const Value: string)&lt;br /&gt;
     public&lt;br /&gt;
       property Filename:string read FFilename write SetFilename;&lt;br /&gt;
       procedure Load;&lt;br /&gt;
       procedure Save;&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
The above code will call Save method from the click handler.&lt;br /&gt;
    procedure TForm1.ButtonClick  (Sender: Object);&lt;br /&gt;
    begin&lt;br /&gt;
       Preference.Save;&lt;br /&gt;
    end;&lt;br /&gt;
    procedure TForm1.EditChange (Sender: TObject);&lt;br /&gt;
    begin&lt;br /&gt;
      Preferences.Filename:= edit1.text;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Create functions and modularize the code as much as possible so that the code could be well maintained and flexible.&lt;br /&gt;
&lt;br /&gt;
==Object-oriented design anti-patterns==&lt;br /&gt;
&lt;br /&gt;
===Anemic Domain Model===&lt;br /&gt;
Separating the [http://en.wikipedia.org/wiki/Business_logic business logic] from the [http://en.wikipedia.org/wiki/Domain_model Domain Model] is termed as Anemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's [http://en.wikipedia.org/wiki/Entity_Bean Entity beans] and .Net's three layered service application. A short example for Anaemic Model is given below,&lt;br /&gt;
*'''Example'''&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Although, the above code looks right by providing segregation of data and service, its in violation of OOPs principle of data and behavior [http://en.wikipedia.org/wiki/Encapsulation encapsulation].It could run into problems when there are multiple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behavior (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
===BaseBean===&lt;br /&gt;
In the practice of BaseBean, subclasses are derived from an utility class, even though delegation is possible. [http://en.wikipedia.org/wiki/Inheritance Inheritance] can be evil sometimes, either breaking some subclass due to change in parent class or very deep hierarchy of classes leading to confusion and no reuse of code. For example, if we want to create a student class and we already have person class, inheritance is not the right way to go. &lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**We can use delegation and create instance of Person class in Student class and utilize all the features of class Person in class Student.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===CallSuper===&lt;br /&gt;
CallSuper is a anti-pattern in which subclass [http://en.wikipedia.org/wiki/Method_overriding overrides] a parent's method and calls the parent's overridden method from the same method. This is considered as a bad practice because, in the future if the parent class's implementation changes it breaks the subclass too. And also it puts an additional responsibility on the subclass's developer to call Super.The correct way to go about this is the parent class declaring a separate hook method for subclass to override.&lt;br /&gt;
*'''Example'''&lt;br /&gt;
  // '''Wrong Way'''                                                         // '''Correct Way'''&lt;br /&gt;
  public class EventHandle{                                             public class EventHandle{&lt;br /&gt;
    public void handle (BankingEvent e) {                                  public void handle (BankingEvent e) {&lt;br /&gt;
      cleanUp(e);                                                            cleanUp(e);&lt;br /&gt;
    }                                                                        doHandle(e);  //hook method&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
  public class TransferEventHandler extends EventHandle{                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    public void handle(BankingEvent e) {                                   }&lt;br /&gt;
      super.handle(e);                                                     public class TransferEventHandler extends EventHandle{&lt;br /&gt;
      initiateTransfer(e);                                                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    }                                                                           initiateTransfer(e);&lt;br /&gt;
                                                                             }&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
The significance of anti-patterns is the same as design patterns, anti-patterns are real helpful in identifying bad design.Thus the beforehand knowledge of anti-patterns comes in handy in making sure that the code base doesn't make use any of it. They should be identified at early stage of [http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle SDLC life cycle], because it might require significant effort to remove anti-patterns as you go down the SDLC life cycle.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Design_pattern_(computer_science) Design Patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Code_smell Code Smell]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Abstraction_inversion Abstraction Inversion]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Big_ball_of_mud Big Ball Of Mud]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Race_hazard Race Hazard]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Magic_pushbutton Magic Pushbutton]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern Anti-pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anemic_Domain_Model Anemic Domain Model]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/BaseBean BaseBean]&lt;br /&gt;
&lt;br /&gt;
==External Links==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.antipatterns.com/ &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://c2.com/cgi/wiki?AntiPattern &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.martinfowler.com/bliki/CallSuper.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis by William J.Brown and Raphael C.Malveau&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27637</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27637"/>
		<updated>2009-11-17T21:28:33Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Abstraction Inversion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti-patterns were used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system.&lt;br /&gt;
*Inexperience on the part of the programmer.&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
Anti-Patterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
Some of the widely used anti-patterns are classified into the following categories,&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Organizational_anti-patterns Organizational anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Project_management_anti-patterns Project management anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Analysis_anti-patterns Analysis anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Software_design_anti-patterns Software design anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Configuration_management_anti-patterns Configuration management anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Programming_anti-patterns Programming anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Methodological_anti-patterns Methodological anti-patterns]&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
===Abstraction Inversion===&lt;br /&gt;
Abstraction Inversion means implementing a lower level construct on top of high level constructs. A simple example would be suppose we have 2 constructs A and B. Let B be implemented on top of A but A is not exposed anywhere in the system and if we really require A then we end up building A on top of B and B was already implemented in terms of A.&lt;br /&gt;
A short example of Abstraction Inversion is given below&lt;br /&gt;
&lt;br /&gt;
* '''Example'''&lt;br /&gt;
The below code implements a set of binary values in a String which decide if it is true or false. (e.g. 'T' or 'F'). They then use the indexer to find the bit.&lt;br /&gt;
    char[] bitString ...;&lt;br /&gt;
    if (bitString[i] == 'T') { // do stuff&lt;br /&gt;
&lt;br /&gt;
So in this case we have a character representing a bit value, but a character is nothing but a sequence of bits. Therefore we have a sequence made up of characters containing bits which are made up of a bit sequence.&lt;br /&gt;
&lt;br /&gt;
* '''Solution'''&lt;br /&gt;
**Choose the infrastructure carefully.&lt;br /&gt;
**If the system offers w=equivalent functions, use them.&lt;br /&gt;
**Do not inject any weak constructs into the system.&lt;br /&gt;
&lt;br /&gt;
===Big ball of mud===&lt;br /&gt;
&lt;br /&gt;
This term was coined by Brain Foote and Joseph Yoder's paper in 1999. This kind of anti pattern arises over a period of time where a number of programmers have worked on a system on various pieces of code. Dur to the lack of knowledge of the current systems the programmers write code which may have already been present and results in a lot of redundant code. Information being shared across the system which may result in it being globally declared and eventually making the code unreadable and unmanageable.&lt;br /&gt;
&lt;br /&gt;
*'''Example'''&lt;br /&gt;
    float CalculateTotal(int quantity, float price){&lt;br /&gt;
       return quantity*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    float CalculateAmount(int amt, float price){&lt;br /&gt;
       return amt*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The above code shows two functions that perform the same function but was created which results in code redundancy and unreadable.&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Good understanding of the system prior to any major code changes.&lt;br /&gt;
**Modularizing the code and defining the functionality at the proper location can help reduce the code redundancy.&lt;br /&gt;
**Technical shifts(client-server to web based, file based to database based etc) can provide good reasons to create the system from scratch.&lt;br /&gt;
&lt;br /&gt;
===Race Hazard===&lt;br /&gt;
A race hazard or a race condition is a flaw in the system where the output of the system depends on the order in which the system executes. This leads to inconsistency in the output. This term was coined with the idea of two signals racing each other to influence each other.&lt;br /&gt;
&lt;br /&gt;
*'''Example'''&lt;br /&gt;
    global integer A = 0;&lt;br /&gt;
    //increments the value of A and prints &amp;quot;RX&amp;quot;&lt;br /&gt;
    // activated whenever an interrupt is received from the controller&lt;br /&gt;
    task Received()&lt;br /&gt;
    {&lt;br /&gt;
        A = A + 1&lt;br /&gt;
        print RX&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    //prints out only even numbers&lt;br /&gt;
    //is activated whenever an  interrupt is received from the serial controller&lt;br /&gt;
    task timeout()&lt;br /&gt;
    {&lt;br /&gt;
       if(A is divisible by 2)&lt;br /&gt;
       {&lt;br /&gt;
           print A&lt;br /&gt;
       }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    Output would look like &lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    2&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    4&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Mutexes can be used to address this problem in concurrent programming.&lt;br /&gt;
&lt;br /&gt;
===Magic Pushbutton===&lt;br /&gt;
This is a very common anti pattern that shows up on graphical user interfaces programming environments. The user first draws the user interface and then builds up the business logic in the automatically created methods.&lt;br /&gt;
Some of the issues faced in this are,&lt;br /&gt;
*The code for in those defined functions grow large.&lt;br /&gt;
*Change in the user interface leads to a lot of changes in the functions and becomes difficult to manage.&lt;br /&gt;
*Testing becomes an issue.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Example'''&lt;br /&gt;
Below is a Bad example of Magic PushButton Anti Pattern.    &lt;br /&gt;
    procedure TForm1.ButtonClick(Sender: TObject);&lt;br /&gt;
    var &lt;br /&gt;
       reg:TRegistry;&lt;br /&gt;
    begin&lt;br /&gt;
       reg:TRegistry.Create;&lt;br /&gt;
    try&lt;br /&gt;
       reg.RootKey:= HKey_Current_User;&lt;br /&gt;
       if reg.OpenKey('\Software\mycompany',true) then&lt;br /&gt;
       begin&lt;br /&gt;
         reg.WriteString('Filename',edit1.text);&lt;br /&gt;
       end;&lt;br /&gt;
      finally&lt;br /&gt;
       reg.Free;&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
A good example of the same is given below. This is done by re-factoring the business logic. In the below example this is done by storing the file in an registry in a separate class. &lt;br /&gt;
&lt;br /&gt;
    type&lt;br /&gt;
     TReference = class&lt;br /&gt;
     private  &lt;br /&gt;
       FFilename: string&lt;br /&gt;
       procedure SetFilename(const Value: string)&lt;br /&gt;
     public&lt;br /&gt;
       property Filename:string read FFilename write SetFilename;&lt;br /&gt;
       procedure Load;&lt;br /&gt;
       procedure Save;&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
The above code will call Save method from the click handler.&lt;br /&gt;
    procedure TForm1.ButtonClick  (Sender: Object);&lt;br /&gt;
    begin&lt;br /&gt;
       Preference.Save;&lt;br /&gt;
    end;&lt;br /&gt;
    procedure TForm1.EditChange (Sender: TObject);&lt;br /&gt;
    begin&lt;br /&gt;
      Preferences.Filename:= edit1.text;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Create functions and modularize the code as much as possible so that the code could be well maintained and flexible.&lt;br /&gt;
&lt;br /&gt;
==Object-oriented design anti-patterns==&lt;br /&gt;
&lt;br /&gt;
===Anemic Domain Model===&lt;br /&gt;
Separating the [http://en.wikipedia.org/wiki/Business_logic business logic] from the [http://en.wikipedia.org/wiki/Domain_model Domain Model] is termed as Anemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's [http://en.wikipedia.org/wiki/Entity_Bean Entity beans] and .Net's three layered service application. A short example for Anaemic Model is given below,&lt;br /&gt;
*'''Example'''&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Although, the above code looks right by providing segregation of data and service, its in violation of OOPs principle of data and behavior [http://en.wikipedia.org/wiki/Encapsulation encapsulation].It could run into problems when there are multiple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behavior (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
===BaseBean===&lt;br /&gt;
In the practice of BaseBean, subclasses are derived from an utility class, even though delegation is possible. [http://en.wikipedia.org/wiki/Inheritance Inheritance] can be evil sometimes, either breaking some subclass due to change in parent class or very deep hierarchy of classes leading to confusion and no reuse of code. For example, if we want to create a student class and we already have person class, inheritance is not the right way to go. &lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**We can use delegation and create instance of Person class in Student class and utilize all the features of class Person in class Student.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===CallSuper===&lt;br /&gt;
CallSuper is a anti-pattern in which subclass [http://en.wikipedia.org/wiki/Method_overriding overrides] a parent's method and calls the parent's overridden method from the same method. This is considered as a bad practice because, in the future if the parent class's implementation changes it breaks the subclass too. And also it puts an additional responsibility on the subclass's developer to call Super.The correct way to go about this is the parent class declaring a separate hook method for subclass to override.&lt;br /&gt;
*'''Example'''&lt;br /&gt;
  // '''Wrong Way'''                                                         // '''Correct Way'''&lt;br /&gt;
  public class EventHandle{                                             public class EventHandle{&lt;br /&gt;
    public void handle (BankingEvent e) {                                  public void handle (BankingEvent e) {&lt;br /&gt;
      cleanUp(e);                                                            cleanUp(e);&lt;br /&gt;
    }                                                                        doHandle(e);  //hook method&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
  public class TransferEventHandler extends EventHandle{                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    public void handle(BankingEvent e) {                                   }&lt;br /&gt;
      super.handle(e);                                                     public class TransferEventHandler extends EventHandle{&lt;br /&gt;
      initiateTransfer(e);                                                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    }                                                                           initiateTransfer(e);&lt;br /&gt;
                                                                             }&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
The significance of anti-patterns is the same as design patterns, anti-patterns are real helpful in identifying bad design.Thus the beforehand knowledge of anti-patterns comes in handy in making sure that the code base doesn't make use any of it. They should be identified at early stage of [http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle SDLC life cycle], because it might require significant effort to remove anti-patterns as you go down the SDLC life cycle.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Design_pattern_(computer_science) Design Patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Code_smell Code Smell]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Abstraction_inversion Abstraction Inversion]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Big_ball_of_mud Big Ball Of Mud]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Race_hazard Race Hazard]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Magic_pushbutton Magic Pushbutton]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern Anti-pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anemic_Domain_Model Anemic Domain Model]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/BaseBean BaseBean]&lt;br /&gt;
&lt;br /&gt;
==External Links==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.antipatterns.com/ &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://c2.com/cgi/wiki?AntiPattern &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.martinfowler.com/bliki/CallSuper.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis by William J.Brown and Raphael C.Malveau&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27635</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27635"/>
		<updated>2009-11-17T21:28:05Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti-patterns were used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system.&lt;br /&gt;
*Inexperience on the part of the programmer.&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
Anti-Patterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
Some of the widely used anti-patterns are classified into the following categories,&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Organizational_anti-patterns Organizational anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Project_management_anti-patterns Project management anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Analysis_anti-patterns Analysis anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Software_design_anti-patterns Software design anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Configuration_management_anti-patterns Configuration management anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Programming_anti-patterns Programming anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Methodological_anti-patterns Methodological anti-patterns]&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
===Abstraction Inversion===&lt;br /&gt;
Abstraction Inversion means implementing a lower level construct on top of high level constructs. A simple example would be suppose we have 2 constructs A and B. Let B be implemented on top of A but A is not exposed anywhere in the system and if we really require A then we end up building A on top of B and B was already implemented in terms of A.&lt;br /&gt;
A short Example of Abstraction Inversion is given below&lt;br /&gt;
&lt;br /&gt;
* '''Example'''&lt;br /&gt;
The below code implements a set of binary values in a String which decide if it is true or false. (e.g. 'T' or 'F'). They then use the indexer to find the bit.&lt;br /&gt;
    char[] bitString ...;&lt;br /&gt;
    if (bitString[i] == 'T') { // do stuff&lt;br /&gt;
&lt;br /&gt;
So in this case we have a character representing a bit value, but a character is nothing but a sequence of bits. Therefore we have a sequence made up of characters containing bits which are made up of a bit sequence.&lt;br /&gt;
&lt;br /&gt;
* '''Solution'''&lt;br /&gt;
**Choose the infrastructure carefully.&lt;br /&gt;
**If the system offers w=equivalent functions, use them.&lt;br /&gt;
**Do not inject any weak constructs into the system.&lt;br /&gt;
&lt;br /&gt;
===Big ball of mud===&lt;br /&gt;
&lt;br /&gt;
This term was coined by Brain Foote and Joseph Yoder's paper in 1999. This kind of anti pattern arises over a period of time where a number of programmers have worked on a system on various pieces of code. Dur to the lack of knowledge of the current systems the programmers write code which may have already been present and results in a lot of redundant code. Information being shared across the system which may result in it being globally declared and eventually making the code unreadable and unmanageable.&lt;br /&gt;
&lt;br /&gt;
*'''Example'''&lt;br /&gt;
    float CalculateTotal(int quantity, float price){&lt;br /&gt;
       return quantity*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    float CalculateAmount(int amt, float price){&lt;br /&gt;
       return amt*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The above code shows two functions that perform the same function but was created which results in code redundancy and unreadable.&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Good understanding of the system prior to any major code changes.&lt;br /&gt;
**Modularizing the code and defining the functionality at the proper location can help reduce the code redundancy.&lt;br /&gt;
**Technical shifts(client-server to web based, file based to database based etc) can provide good reasons to create the system from scratch.&lt;br /&gt;
&lt;br /&gt;
===Race Hazard===&lt;br /&gt;
A race hazard or a race condition is a flaw in the system where the output of the system depends on the order in which the system executes. This leads to inconsistency in the output. This term was coined with the idea of two signals racing each other to influence each other.&lt;br /&gt;
&lt;br /&gt;
*'''Example'''&lt;br /&gt;
    global integer A = 0;&lt;br /&gt;
    //increments the value of A and prints &amp;quot;RX&amp;quot;&lt;br /&gt;
    // activated whenever an interrupt is received from the controller&lt;br /&gt;
    task Received()&lt;br /&gt;
    {&lt;br /&gt;
        A = A + 1&lt;br /&gt;
        print RX&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    //prints out only even numbers&lt;br /&gt;
    //is activated whenever an  interrupt is received from the serial controller&lt;br /&gt;
    task timeout()&lt;br /&gt;
    {&lt;br /&gt;
       if(A is divisible by 2)&lt;br /&gt;
       {&lt;br /&gt;
           print A&lt;br /&gt;
       }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    Output would look like &lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    2&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    4&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Mutexes can be used to address this problem in concurrent programming.&lt;br /&gt;
&lt;br /&gt;
===Magic Pushbutton===&lt;br /&gt;
This is a very common anti pattern that shows up on graphical user interfaces programming environments. The user first draws the user interface and then builds up the business logic in the automatically created methods.&lt;br /&gt;
Some of the issues faced in this are,&lt;br /&gt;
*The code for in those defined functions grow large.&lt;br /&gt;
*Change in the user interface leads to a lot of changes in the functions and becomes difficult to manage.&lt;br /&gt;
*Testing becomes an issue.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Example'''&lt;br /&gt;
Below is a Bad example of Magic PushButton Anti Pattern.    &lt;br /&gt;
    procedure TForm1.ButtonClick(Sender: TObject);&lt;br /&gt;
    var &lt;br /&gt;
       reg:TRegistry;&lt;br /&gt;
    begin&lt;br /&gt;
       reg:TRegistry.Create;&lt;br /&gt;
    try&lt;br /&gt;
       reg.RootKey:= HKey_Current_User;&lt;br /&gt;
       if reg.OpenKey('\Software\mycompany',true) then&lt;br /&gt;
       begin&lt;br /&gt;
         reg.WriteString('Filename',edit1.text);&lt;br /&gt;
       end;&lt;br /&gt;
      finally&lt;br /&gt;
       reg.Free;&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
A good example of the same is given below. This is done by re-factoring the business logic. In the below example this is done by storing the file in an registry in a separate class. &lt;br /&gt;
&lt;br /&gt;
    type&lt;br /&gt;
     TReference = class&lt;br /&gt;
     private  &lt;br /&gt;
       FFilename: string&lt;br /&gt;
       procedure SetFilename(const Value: string)&lt;br /&gt;
     public&lt;br /&gt;
       property Filename:string read FFilename write SetFilename;&lt;br /&gt;
       procedure Load;&lt;br /&gt;
       procedure Save;&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
The above code will call Save method from the click handler.&lt;br /&gt;
    procedure TForm1.ButtonClick  (Sender: Object);&lt;br /&gt;
    begin&lt;br /&gt;
       Preference.Save;&lt;br /&gt;
    end;&lt;br /&gt;
    procedure TForm1.EditChange (Sender: TObject);&lt;br /&gt;
    begin&lt;br /&gt;
      Preferences.Filename:= edit1.text;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Create functions and modularize the code as much as possible so that the code could be well maintained and flexible.&lt;br /&gt;
&lt;br /&gt;
==Object-oriented design anti-patterns==&lt;br /&gt;
&lt;br /&gt;
===Anemic Domain Model===&lt;br /&gt;
Separating the [http://en.wikipedia.org/wiki/Business_logic business logic] from the [http://en.wikipedia.org/wiki/Domain_model Domain Model] is termed as Anemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's [http://en.wikipedia.org/wiki/Entity_Bean Entity beans] and .Net's three layered service application. A short example for Anaemic Model is given below,&lt;br /&gt;
*'''Example'''&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Although, the above code looks right by providing segregation of data and service, its in violation of OOPs principle of data and behavior [http://en.wikipedia.org/wiki/Encapsulation encapsulation].It could run into problems when there are multiple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behavior (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
===BaseBean===&lt;br /&gt;
In the practice of BaseBean, subclasses are derived from an utility class, even though delegation is possible. [http://en.wikipedia.org/wiki/Inheritance Inheritance] can be evil sometimes, either breaking some subclass due to change in parent class or very deep hierarchy of classes leading to confusion and no reuse of code. For example, if we want to create a student class and we already have person class, inheritance is not the right way to go. &lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**We can use delegation and create instance of Person class in Student class and utilize all the features of class Person in class Student.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===CallSuper===&lt;br /&gt;
CallSuper is a anti-pattern in which subclass [http://en.wikipedia.org/wiki/Method_overriding overrides] a parent's method and calls the parent's overridden method from the same method. This is considered as a bad practice because, in the future if the parent class's implementation changes it breaks the subclass too. And also it puts an additional responsibility on the subclass's developer to call Super.The correct way to go about this is the parent class declaring a separate hook method for subclass to override.&lt;br /&gt;
*'''Example'''&lt;br /&gt;
  // '''Wrong Way'''                                                         // '''Correct Way'''&lt;br /&gt;
  public class EventHandle{                                             public class EventHandle{&lt;br /&gt;
    public void handle (BankingEvent e) {                                  public void handle (BankingEvent e) {&lt;br /&gt;
      cleanUp(e);                                                            cleanUp(e);&lt;br /&gt;
    }                                                                        doHandle(e);  //hook method&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
  public class TransferEventHandler extends EventHandle{                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    public void handle(BankingEvent e) {                                   }&lt;br /&gt;
      super.handle(e);                                                     public class TransferEventHandler extends EventHandle{&lt;br /&gt;
      initiateTransfer(e);                                                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    }                                                                           initiateTransfer(e);&lt;br /&gt;
                                                                             }&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
The significance of anti-patterns is the same as design patterns, anti-patterns are real helpful in identifying bad design.Thus the beforehand knowledge of anti-patterns comes in handy in making sure that the code base doesn't make use any of it. They should be identified at early stage of [http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle SDLC life cycle], because it might require significant effort to remove anti-patterns as you go down the SDLC life cycle.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Design_pattern_(computer_science) Design Patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Code_smell Code Smell]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Abstraction_inversion Abstraction Inversion]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Big_ball_of_mud Big Ball Of Mud]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Race_hazard Race Hazard]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Magic_pushbutton Magic Pushbutton]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern Anti-pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anemic_Domain_Model Anemic Domain Model]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/BaseBean BaseBean]&lt;br /&gt;
&lt;br /&gt;
==External Links==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.antipatterns.com/ &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://c2.com/cgi/wiki?AntiPattern &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.martinfowler.com/bliki/CallSuper.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis by William J.Brown and Raphael C.Malveau&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27634</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27634"/>
		<updated>2009-11-17T21:27:43Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti-patterns were used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system&lt;br /&gt;
*Inexperience on the part of the programmer&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
Anti-Patterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
Some of the widely used anti-patterns are classified into the following categories,&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Organizational_anti-patterns Organizational anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Project_management_anti-patterns Project management anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Analysis_anti-patterns Analysis anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Software_design_anti-patterns Software design anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Configuration_management_anti-patterns Configuration management anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Programming_anti-patterns Programming anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Methodological_anti-patterns Methodological anti-patterns]&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
===Abstraction Inversion===&lt;br /&gt;
Abstraction Inversion means implementing a lower level construct on top of high level constructs. A simple example would be suppose we have 2 constructs A and B. Let B be implemented on top of A but A is not exposed anywhere in the system and if we really require A then we end up building A on top of B and B was already implemented in terms of A.&lt;br /&gt;
A short Example of Abstraction Inversion is given below&lt;br /&gt;
&lt;br /&gt;
* '''Example'''&lt;br /&gt;
The below code implements a set of binary values in a String which decide if it is true or false. (e.g. 'T' or 'F'). They then use the indexer to find the bit.&lt;br /&gt;
    char[] bitString ...;&lt;br /&gt;
    if (bitString[i] == 'T') { // do stuff&lt;br /&gt;
&lt;br /&gt;
So in this case we have a character representing a bit value, but a character is nothing but a sequence of bits. Therefore we have a sequence made up of characters containing bits which are made up of a bit sequence.&lt;br /&gt;
&lt;br /&gt;
* '''Solution'''&lt;br /&gt;
**Choose the infrastructure carefully.&lt;br /&gt;
**If the system offers w=equivalent functions, use them.&lt;br /&gt;
**Do not inject any weak constructs into the system.&lt;br /&gt;
&lt;br /&gt;
===Big ball of mud===&lt;br /&gt;
&lt;br /&gt;
This term was coined by Brain Foote and Joseph Yoder's paper in 1999. This kind of anti pattern arises over a period of time where a number of programmers have worked on a system on various pieces of code. Dur to the lack of knowledge of the current systems the programmers write code which may have already been present and results in a lot of redundant code. Information being shared across the system which may result in it being globally declared and eventually making the code unreadable and unmanageable.&lt;br /&gt;
&lt;br /&gt;
*'''Example'''&lt;br /&gt;
    float CalculateTotal(int quantity, float price){&lt;br /&gt;
       return quantity*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    float CalculateAmount(int amt, float price){&lt;br /&gt;
       return amt*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The above code shows two functions that perform the same function but was created which results in code redundancy and unreadable.&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Good understanding of the system prior to any major code changes.&lt;br /&gt;
**Modularizing the code and defining the functionality at the proper location can help reduce the code redundancy.&lt;br /&gt;
**Technical shifts(client-server to web based, file based to database based etc) can provide good reasons to create the system from scratch.&lt;br /&gt;
&lt;br /&gt;
===Race Hazard===&lt;br /&gt;
A race hazard or a race condition is a flaw in the system where the output of the system depends on the order in which the system executes. This leads to inconsistency in the output. This term was coined with the idea of two signals racing each other to influence each other.&lt;br /&gt;
&lt;br /&gt;
*'''Example'''&lt;br /&gt;
    global integer A = 0;&lt;br /&gt;
    //increments the value of A and prints &amp;quot;RX&amp;quot;&lt;br /&gt;
    // activated whenever an interrupt is received from the controller&lt;br /&gt;
    task Received()&lt;br /&gt;
    {&lt;br /&gt;
        A = A + 1&lt;br /&gt;
        print RX&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    //prints out only even numbers&lt;br /&gt;
    //is activated whenever an  interrupt is received from the serial controller&lt;br /&gt;
    task timeout()&lt;br /&gt;
    {&lt;br /&gt;
       if(A is divisible by 2)&lt;br /&gt;
       {&lt;br /&gt;
           print A&lt;br /&gt;
       }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    Output would look like &lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    2&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    4&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Mutexes can be used to address this problem in concurrent programming.&lt;br /&gt;
&lt;br /&gt;
===Magic Pushbutton===&lt;br /&gt;
This is a very common anti pattern that shows up on graphical user interfaces programming environments. The user first draws the user interface and then builds up the business logic in the automatically created methods.&lt;br /&gt;
Some of the issues faced in this are,&lt;br /&gt;
*The code for in those defined functions grow large.&lt;br /&gt;
*Change in the user interface leads to a lot of changes in the functions and becomes difficult to manage.&lt;br /&gt;
*Testing becomes an issue.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Example'''&lt;br /&gt;
Below is a Bad example of Magic PushButton Anti Pattern.    &lt;br /&gt;
    procedure TForm1.ButtonClick(Sender: TObject);&lt;br /&gt;
    var &lt;br /&gt;
       reg:TRegistry;&lt;br /&gt;
    begin&lt;br /&gt;
       reg:TRegistry.Create;&lt;br /&gt;
    try&lt;br /&gt;
       reg.RootKey:= HKey_Current_User;&lt;br /&gt;
       if reg.OpenKey('\Software\mycompany',true) then&lt;br /&gt;
       begin&lt;br /&gt;
         reg.WriteString('Filename',edit1.text);&lt;br /&gt;
       end;&lt;br /&gt;
      finally&lt;br /&gt;
       reg.Free;&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
A good example of the same is given below. This is done by re-factoring the business logic. In the below example this is done by storing the file in an registry in a separate class. &lt;br /&gt;
&lt;br /&gt;
    type&lt;br /&gt;
     TReference = class&lt;br /&gt;
     private  &lt;br /&gt;
       FFilename: string&lt;br /&gt;
       procedure SetFilename(const Value: string)&lt;br /&gt;
     public&lt;br /&gt;
       property Filename:string read FFilename write SetFilename;&lt;br /&gt;
       procedure Load;&lt;br /&gt;
       procedure Save;&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
The above code will call Save method from the click handler.&lt;br /&gt;
    procedure TForm1.ButtonClick  (Sender: Object);&lt;br /&gt;
    begin&lt;br /&gt;
       Preference.Save;&lt;br /&gt;
    end;&lt;br /&gt;
    procedure TForm1.EditChange (Sender: TObject);&lt;br /&gt;
    begin&lt;br /&gt;
      Preferences.Filename:= edit1.text;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Create functions and modularize the code as much as possible so that the code could be well maintained and flexible.&lt;br /&gt;
&lt;br /&gt;
==Object-oriented design anti-patterns==&lt;br /&gt;
&lt;br /&gt;
===Anemic Domain Model===&lt;br /&gt;
Separating the [http://en.wikipedia.org/wiki/Business_logic business logic] from the [http://en.wikipedia.org/wiki/Domain_model Domain Model] is termed as Anemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's [http://en.wikipedia.org/wiki/Entity_Bean Entity beans] and .Net's three layered service application. A short example for Anaemic Model is given below,&lt;br /&gt;
*'''Example'''&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Although, the above code looks right by providing segregation of data and service, its in violation of OOPs principle of data and behavior [http://en.wikipedia.org/wiki/Encapsulation encapsulation].It could run into problems when there are multiple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behavior (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
===BaseBean===&lt;br /&gt;
In the practice of BaseBean, subclasses are derived from an utility class, even though delegation is possible. [http://en.wikipedia.org/wiki/Inheritance Inheritance] can be evil sometimes, either breaking some subclass due to change in parent class or very deep hierarchy of classes leading to confusion and no reuse of code. For example, if we want to create a student class and we already have person class, inheritance is not the right way to go. &lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**We can use delegation and create instance of Person class in Student class and utilize all the features of class Person in class Student.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===CallSuper===&lt;br /&gt;
CallSuper is a anti-pattern in which subclass [http://en.wikipedia.org/wiki/Method_overriding overrides] a parent's method and calls the parent's overridden method from the same method. This is considered as a bad practice because, in the future if the parent class's implementation changes it breaks the subclass too. And also it puts an additional responsibility on the subclass's developer to call Super.The correct way to go about this is the parent class declaring a separate hook method for subclass to override.&lt;br /&gt;
*'''Example'''&lt;br /&gt;
  // '''Wrong Way'''                                                         // '''Correct Way'''&lt;br /&gt;
  public class EventHandle{                                             public class EventHandle{&lt;br /&gt;
    public void handle (BankingEvent e) {                                  public void handle (BankingEvent e) {&lt;br /&gt;
      cleanUp(e);                                                            cleanUp(e);&lt;br /&gt;
    }                                                                        doHandle(e);  //hook method&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
  public class TransferEventHandler extends EventHandle{                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    public void handle(BankingEvent e) {                                   }&lt;br /&gt;
      super.handle(e);                                                     public class TransferEventHandler extends EventHandle{&lt;br /&gt;
      initiateTransfer(e);                                                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    }                                                                           initiateTransfer(e);&lt;br /&gt;
                                                                             }&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
The significance of anti-patterns is the same as design patterns, anti-patterns are real helpful in identifying bad design.Thus the beforehand knowledge of anti-patterns comes in handy in making sure that the code base doesn't make use any of it. They should be identified at early stage of [http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle SDLC life cycle], because it might require significant effort to remove anti-patterns as you go down the SDLC life cycle.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Design_pattern_(computer_science) Design Patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Code_smell Code Smell]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Abstraction_inversion Abstraction Inversion]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Big_ball_of_mud Big Ball Of Mud]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Race_hazard Race Hazard]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Magic_pushbutton Magic Pushbutton]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern Anti-pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anemic_Domain_Model Anemic Domain Model]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/BaseBean BaseBean]&lt;br /&gt;
&lt;br /&gt;
==External Links==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.antipatterns.com/ &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://c2.com/cgi/wiki?AntiPattern &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.martinfowler.com/bliki/CallSuper.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis by William J.Brown and Raphael C.Malveau&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27633</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27633"/>
		<updated>2009-11-17T21:27:19Z</updated>

		<summary type="html">&lt;p&gt;Naruto: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti pattern was used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system&lt;br /&gt;
*Inexperience on the part of the programmer&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
Anti-Patterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
Some of the widely used anti-patterns are classified into the following categories,&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Organizational_anti-patterns Organizational anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Project_management_anti-patterns Project management anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Analysis_anti-patterns Analysis anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Software_design_anti-patterns Software design anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Configuration_management_anti-patterns Configuration management anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Programming_anti-patterns Programming anti-patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern#Methodological_anti-patterns Methodological anti-patterns]&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
===Abstraction Inversion===&lt;br /&gt;
Abstraction Inversion means implementing a lower level construct on top of high level constructs. A simple example would be suppose we have 2 constructs A and B. Let B be implemented on top of A but A is not exposed anywhere in the system and if we really require A then we end up building A on top of B and B was already implemented in terms of A.&lt;br /&gt;
A short Example of Abstraction Inversion is given below&lt;br /&gt;
&lt;br /&gt;
* '''Example'''&lt;br /&gt;
The below code implements a set of binary values in a String which decide if it is true or false. (e.g. 'T' or 'F'). They then use the indexer to find the bit.&lt;br /&gt;
    char[] bitString ...;&lt;br /&gt;
    if (bitString[i] == 'T') { // do stuff&lt;br /&gt;
&lt;br /&gt;
So in this case we have a character representing a bit value, but a character is nothing but a sequence of bits. Therefore we have a sequence made up of characters containing bits which are made up of a bit sequence.&lt;br /&gt;
&lt;br /&gt;
* '''Solution'''&lt;br /&gt;
**Choose the infrastructure carefully.&lt;br /&gt;
**If the system offers w=equivalent functions, use them.&lt;br /&gt;
**Do not inject any weak constructs into the system.&lt;br /&gt;
&lt;br /&gt;
===Big ball of mud===&lt;br /&gt;
&lt;br /&gt;
This term was coined by Brain Foote and Joseph Yoder's paper in 1999. This kind of anti pattern arises over a period of time where a number of programmers have worked on a system on various pieces of code. Dur to the lack of knowledge of the current systems the programmers write code which may have already been present and results in a lot of redundant code. Information being shared across the system which may result in it being globally declared and eventually making the code unreadable and unmanageable.&lt;br /&gt;
&lt;br /&gt;
*'''Example'''&lt;br /&gt;
    float CalculateTotal(int quantity, float price){&lt;br /&gt;
       return quantity*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    float CalculateAmount(int amt, float price){&lt;br /&gt;
       return amt*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The above code shows two functions that perform the same function but was created which results in code redundancy and unreadable.&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Good understanding of the system prior to any major code changes.&lt;br /&gt;
**Modularizing the code and defining the functionality at the proper location can help reduce the code redundancy.&lt;br /&gt;
**Technical shifts(client-server to web based, file based to database based etc) can provide good reasons to create the system from scratch.&lt;br /&gt;
&lt;br /&gt;
===Race Hazard===&lt;br /&gt;
A race hazard or a race condition is a flaw in the system where the output of the system depends on the order in which the system executes. This leads to inconsistency in the output. This term was coined with the idea of two signals racing each other to influence each other.&lt;br /&gt;
&lt;br /&gt;
*'''Example'''&lt;br /&gt;
    global integer A = 0;&lt;br /&gt;
    //increments the value of A and prints &amp;quot;RX&amp;quot;&lt;br /&gt;
    // activated whenever an interrupt is received from the controller&lt;br /&gt;
    task Received()&lt;br /&gt;
    {&lt;br /&gt;
        A = A + 1&lt;br /&gt;
        print RX&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    //prints out only even numbers&lt;br /&gt;
    //is activated whenever an  interrupt is received from the serial controller&lt;br /&gt;
    task timeout()&lt;br /&gt;
    {&lt;br /&gt;
       if(A is divisible by 2)&lt;br /&gt;
       {&lt;br /&gt;
           print A&lt;br /&gt;
       }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    Output would look like &lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    2&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    4&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Mutexes can be used to address this problem in concurrent programming.&lt;br /&gt;
&lt;br /&gt;
===Magic Pushbutton===&lt;br /&gt;
This is a very common anti pattern that shows up on graphical user interfaces programming environments. The user first draws the user interface and then builds up the business logic in the automatically created methods.&lt;br /&gt;
Some of the issues faced in this are,&lt;br /&gt;
*The code for in those defined functions grow large.&lt;br /&gt;
*Change in the user interface leads to a lot of changes in the functions and becomes difficult to manage.&lt;br /&gt;
*Testing becomes an issue.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
*'''Example'''&lt;br /&gt;
Below is a Bad example of Magic PushButton Anti Pattern.    &lt;br /&gt;
    procedure TForm1.ButtonClick(Sender: TObject);&lt;br /&gt;
    var &lt;br /&gt;
       reg:TRegistry;&lt;br /&gt;
    begin&lt;br /&gt;
       reg:TRegistry.Create;&lt;br /&gt;
    try&lt;br /&gt;
       reg.RootKey:= HKey_Current_User;&lt;br /&gt;
       if reg.OpenKey('\Software\mycompany',true) then&lt;br /&gt;
       begin&lt;br /&gt;
         reg.WriteString('Filename',edit1.text);&lt;br /&gt;
       end;&lt;br /&gt;
      finally&lt;br /&gt;
       reg.Free;&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
A good example of the same is given below. This is done by re-factoring the business logic. In the below example this is done by storing the file in an registry in a separate class. &lt;br /&gt;
&lt;br /&gt;
    type&lt;br /&gt;
     TReference = class&lt;br /&gt;
     private  &lt;br /&gt;
       FFilename: string&lt;br /&gt;
       procedure SetFilename(const Value: string)&lt;br /&gt;
     public&lt;br /&gt;
       property Filename:string read FFilename write SetFilename;&lt;br /&gt;
       procedure Load;&lt;br /&gt;
       procedure Save;&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
The above code will call Save method from the click handler.&lt;br /&gt;
    procedure TForm1.ButtonClick  (Sender: Object);&lt;br /&gt;
    begin&lt;br /&gt;
       Preference.Save;&lt;br /&gt;
    end;&lt;br /&gt;
    procedure TForm1.EditChange (Sender: TObject);&lt;br /&gt;
    begin&lt;br /&gt;
      Preferences.Filename:= edit1.text;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Create functions and modularize the code as much as possible so that the code could be well maintained and flexible.&lt;br /&gt;
&lt;br /&gt;
==Object-oriented design anti-patterns==&lt;br /&gt;
&lt;br /&gt;
===Anemic Domain Model===&lt;br /&gt;
Separating the [http://en.wikipedia.org/wiki/Business_logic business logic] from the [http://en.wikipedia.org/wiki/Domain_model Domain Model] is termed as Anemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's [http://en.wikipedia.org/wiki/Entity_Bean Entity beans] and .Net's three layered service application. A short example for Anaemic Model is given below,&lt;br /&gt;
*'''Example'''&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**Although, the above code looks right by providing segregation of data and service, its in violation of OOPs principle of data and behavior [http://en.wikipedia.org/wiki/Encapsulation encapsulation].It could run into problems when there are multiple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behavior (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
===BaseBean===&lt;br /&gt;
In the practice of BaseBean, subclasses are derived from an utility class, even though delegation is possible. [http://en.wikipedia.org/wiki/Inheritance Inheritance] can be evil sometimes, either breaking some subclass due to change in parent class or very deep hierarchy of classes leading to confusion and no reuse of code. For example, if we want to create a student class and we already have person class, inheritance is not the right way to go. &lt;br /&gt;
&lt;br /&gt;
*'''Solution'''&lt;br /&gt;
**We can use delegation and create instance of Person class in Student class and utilize all the features of class Person in class Student.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===CallSuper===&lt;br /&gt;
CallSuper is a anti-pattern in which subclass [http://en.wikipedia.org/wiki/Method_overriding overrides] a parent's method and calls the parent's overridden method from the same method. This is considered as a bad practice because, in the future if the parent class's implementation changes it breaks the subclass too. And also it puts an additional responsibility on the subclass's developer to call Super.The correct way to go about this is the parent class declaring a separate hook method for subclass to override.&lt;br /&gt;
*'''Example'''&lt;br /&gt;
  // '''Wrong Way'''                                                         // '''Correct Way'''&lt;br /&gt;
  public class EventHandle{                                             public class EventHandle{&lt;br /&gt;
    public void handle (BankingEvent e) {                                  public void handle (BankingEvent e) {&lt;br /&gt;
      cleanUp(e);                                                            cleanUp(e);&lt;br /&gt;
    }                                                                        doHandle(e);  //hook method&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
  public class TransferEventHandler extends EventHandle{                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    public void handle(BankingEvent e) {                                   }&lt;br /&gt;
      super.handle(e);                                                     public class TransferEventHandler extends EventHandle{&lt;br /&gt;
      initiateTransfer(e);                                                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    }                                                                           initiateTransfer(e);&lt;br /&gt;
                                                                             }&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
The significance of anti-patterns is the same as design patterns, anti-patterns are real helpful in identifying bad design.Thus the beforehand knowledge of anti-patterns comes in handy in making sure that the code base doesn't make use any of it. They should be identified at early stage of [http://en.wikipedia.org/wiki/Systems_Development_Life_Cycle SDLC life cycle], because it might require significant effort to remove anti-patterns as you go down the SDLC life cycle.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Design_pattern_(computer_science) Design Patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Code_smell Code Smell]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Abstraction_inversion Abstraction Inversion]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Big_ball_of_mud Big Ball Of Mud]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Race_hazard Race Hazard]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Magic_pushbutton Magic Pushbutton]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern Anti-pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anemic_Domain_Model Anemic Domain Model]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/BaseBean BaseBean]&lt;br /&gt;
&lt;br /&gt;
==External Links==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.antipatterns.com/ &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://c2.com/cgi/wiki?AntiPattern &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.martinfowler.com/bliki/CallSuper.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis by William J.Brown and Raphael C.Malveau&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27569</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27569"/>
		<updated>2009-11-17T20:24:09Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti pattern was used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system&lt;br /&gt;
*Inexperience on the part of the programmer&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
Anti-Patterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
===Abstraction Inversion===&lt;br /&gt;
====Definition====&lt;br /&gt;
Abstarction Inversion means implementing a lower level construct on top of high level constructs. A simple example would be suppose we have 2 constructs A and B. Let B be implemented on top of A but A is not exposed anywhere in the system and if we really require A then we end up building A on top of B and B was already implemented in terms of A.&lt;br /&gt;
A short Example of Abstraction Inversion is given below&lt;br /&gt;
====Example====&lt;br /&gt;
The below code implements a set of binary values in a String which decide if it is true or false. (e.g. 'T' or 'F'). They then use the indexer to find the bit.&lt;br /&gt;
    char[] bitString ...;&lt;br /&gt;
    if (bitString[i] == 'T') { // do stuff&lt;br /&gt;
&lt;br /&gt;
So in this case we have a character representing a bit value, but a character is nothing but a sequence of bits. Therefore we have a sequence made up of characters containing bits which are made up of a bit sequence.&lt;br /&gt;
====Solution====&lt;br /&gt;
*Choose the infrastructure carefully.&lt;br /&gt;
*If the system offers w=equivalent functions, use them.&lt;br /&gt;
*Do not inject any weak constructs into the system.&lt;br /&gt;
&lt;br /&gt;
===Big ball of mud===&lt;br /&gt;
====Definition====&lt;br /&gt;
This term was coined by Brain Foote and Joseph Yoder's paper in 1999. This kind of anti pattern arises over a period of time where a number of programmers have worked on a system on various pieces of code. Dur to the lack of knowledge of the current systems the programmers write code which may have already been present and results in a lot of redundant code. Information being shared across the system which may result in it being globally declared and eventually making the code unreadable and unmanageable.&lt;br /&gt;
====Example====&lt;br /&gt;
    float CalculateTotal(int quantity, float price){&lt;br /&gt;
       return quantity*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    float CalculateAmount(int amt, float price){&lt;br /&gt;
       return amt*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The above code shows two functions that perform the same function but was created which results in code redundancy and unreadable.&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
*Good understanding of the system prior to any major code changes.&lt;br /&gt;
*Modularizing the code and defining the functionality at the proper location can help reduce the code redundancy.&lt;br /&gt;
*Technical shifts(client-server to web based, file based to database based etc) can provide good reasons to create the system from scratch.  &lt;br /&gt;
&lt;br /&gt;
===Race Hazard===&lt;br /&gt;
====Definition====&lt;br /&gt;
A race hazard or a race condition is a flaw in the system where the output of the system depends on the order in which the system executes. This leads to inconsistency in the output. This term was coined with the idea of two signals racing each other to influence each other.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
    global integer A = 0;&lt;br /&gt;
    //increments the value of A and prints &amp;quot;RX&amp;quot;&lt;br /&gt;
    // activated whenever an interrupt is received from the controller&lt;br /&gt;
    task Received()&lt;br /&gt;
    {&lt;br /&gt;
        A = A + 1&lt;br /&gt;
        print RX&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    //prints out only even numbers&lt;br /&gt;
    //is activated whenever an  interrupt is received from the serial controller&lt;br /&gt;
    task timeout()&lt;br /&gt;
    {&lt;br /&gt;
       if(A is divisible by 2)&lt;br /&gt;
       {&lt;br /&gt;
           print A&lt;br /&gt;
       }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    Output would look like &lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    2&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    4&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
Mutexes can be used to address this problem in concurrent programming.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Magic Bushbutton===&lt;br /&gt;
====Definition====&lt;br /&gt;
This is a very common anti pattern that shows up on graphical user interfaces programming environments. The user first draws the user interface and then builds up the business logic in the automatically created methods.&lt;br /&gt;
Some of the issues faced in this&lt;br /&gt;
*The code for in those defined functions grow large.&lt;br /&gt;
*Change in the user interface leads to a lot of changes in the functions and becomes difficult to manage.&lt;br /&gt;
*Testing becomes an issue.&lt;br /&gt;
====Example====&lt;br /&gt;
Below is a Bad example of Magic PushButton Anti Pattern.    &lt;br /&gt;
    procedure TForm1.ButtonClick(Sender: TObject);&lt;br /&gt;
    var &lt;br /&gt;
       reg:TRegistry;&lt;br /&gt;
    begin&lt;br /&gt;
       reg:TRegistry.Create;&lt;br /&gt;
    try&lt;br /&gt;
       reg.RootKey:= HKey_Current_User;&lt;br /&gt;
       if reg.OpenKey('\Software\mycompany',true) then&lt;br /&gt;
       begin&lt;br /&gt;
         reg.WriteString('Filename',edit1.text);&lt;br /&gt;
       end;&lt;br /&gt;
      finally&lt;br /&gt;
       reg.Free;&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
A good example of the same is given below. This is done by refactoring the business logic. IN the below example this is done by storing the file in an registry in a separate class. &lt;br /&gt;
&lt;br /&gt;
    type&lt;br /&gt;
     TReference = class&lt;br /&gt;
     private  &lt;br /&gt;
       FFilename: string&lt;br /&gt;
       procedure SetFilename(const Value: string)&lt;br /&gt;
     public&lt;br /&gt;
       property Filename:string read FFilename write SetFilename;&lt;br /&gt;
       procedure Load;&lt;br /&gt;
       procedure Save;&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
The above code will call Save method from the click handler.&lt;br /&gt;
    procedure TForm1.ButtonClick  (Sender: Object);&lt;br /&gt;
    begin&lt;br /&gt;
       Preference.Save;&lt;br /&gt;
    end;&lt;br /&gt;
    procedure TForm1.EditChange (Sender: TObject);&lt;br /&gt;
    begin&lt;br /&gt;
      Preferences.Filename:= edit1.text;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
*Create functions and modularize the code as much as possible so that the code could be well maintained and flexible.&lt;br /&gt;
&lt;br /&gt;
==Object-oriented design anti-patterns==&lt;br /&gt;
&lt;br /&gt;
* Anemic Domain Model&lt;br /&gt;
Separating the [http://en.wikipedia.org/wiki/Business_logic business logic] from the [http://en.wikipedia.org/wiki/Domain_model Domain Model] is termed as Anemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's [http://en.wikipedia.org/wiki/Entity_Bean Entity beans] and .Net's three layered service application. A short example for Anaemic Model is given below,&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
Although, the above code looks right by providing segregation of data and service, its in violation of OOP principle of data and behaviour [http://en.wikipedia.org/wiki/Encapsulation encapsulation].It could run into problems when there are muliple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* BaseBean&lt;br /&gt;
In the practise of BaseBean, subclasses are derived from an utility class, even though delegation is possible. [http://en.wikipedia.org/wiki/Inheritance Inheritance] can be evil sometimes, either breaking some subclass due to change in parent class or very deep hierarchy of classes leading to confusion and no reuse of code. For example, if we want to create a student class and we already have person class, inheritance is not the right way to go. We can use delegation and create instance of Person class in Student class and utilize all the features of class Person in class Student.&lt;br /&gt;
&lt;br /&gt;
* CallSuper &lt;br /&gt;
CallSuper is a antipattern in which subclass [http://en.wikipedia.org/wiki/Method_overriding overrides] a parent's method and calls the parent's overridden method from the same method. This is considered as a bad practise because, in the future if the parent class's implementation changes it breaks the subclass too. And also it puts an additional responsiblity on the subclass's developer to call Super.The correct way to go about this is the parent class declaring a separate hook method for subclass to override.&lt;br /&gt;
  // '''Wrong Way'''                                                         // '''Correct Way'''&lt;br /&gt;
  public class EventHandle{                                             public class EventHandle{&lt;br /&gt;
    public void handle (BankingEvent e) {                                  public void handle (BankingEvent e) {&lt;br /&gt;
      cleanUp(e);                                                            cleanUp(e);&lt;br /&gt;
    }                                                                        doHandle(e);  //hook method&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
  public class TransferEventHandler extends EventHandle{                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    public void handle(BankingEvent e) {                                   }&lt;br /&gt;
      super.handle(e);                                                     public class TransferEventHandler extends EventHandle{&lt;br /&gt;
      initiateTransfer(e);                                                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    }                                                                           initiateTransfer(e);&lt;br /&gt;
                                                                             }&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Design_pattern_(computer_science) Design Patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Code_smell Code Smell]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Abstraction_inversion Abstraction Inversion]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Big_ball_of_mud Big Ball Of Mud]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Race_hazard Race Hazard]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Magic_pushbutton Magic Pushbutton]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern Anti-pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anemic_Domain_Model Anemic Domain Model]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/BaseBean BaseBean]&lt;br /&gt;
&lt;br /&gt;
==External Links==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.antipatterns.com/ &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://c2.com/cgi/wiki?AntiPattern &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.martinfowler.com/bliki/CallSuper.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis by William J.Brown and Raphael C.Malveau&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27565</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27565"/>
		<updated>2009-11-17T20:20:03Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti pattern was used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system&lt;br /&gt;
*Inexperience on the part of the programmer&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
Anti-Patterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
===Abstraction Inversion===&lt;br /&gt;
====Definition====&lt;br /&gt;
Abstarction Inversion means implementing a lower level construct on top of high level constructs. A simple example would be suppose we have 2 constructs A and B. Let B be implemented on top of A but A is not exposed anywhere in the system and if we really require A then we end up building A on top of B and B was already implemented in terms of A.&lt;br /&gt;
A short Example of Abstraction Inversion is given below&lt;br /&gt;
====Example====&lt;br /&gt;
The below code implements a set of binary values in a String which decide if it is true or false. (e.g. 'T' or 'F'). They then use the indexer to find the bit.&lt;br /&gt;
    char[] bitString ...;&lt;br /&gt;
    if (bitString[i] == 'T') { // do stuff&lt;br /&gt;
&lt;br /&gt;
So in this case we have a character representing a bit value, but a character is nothing but a sequence of bits. Therefore we have a sequence made up of characters containing bits which are made up of a bit sequence.&lt;br /&gt;
====Solution====&lt;br /&gt;
*Choose the infrastructure carefully.&lt;br /&gt;
*If the system offers w=equivalent functions, use them.&lt;br /&gt;
*Do not inject any weak constructs into the system.&lt;br /&gt;
&lt;br /&gt;
===Big ball of mud===&lt;br /&gt;
====Definition====&lt;br /&gt;
This term was coined by Brain Foote and Joseph Yoder's paper in 1999. This kind of anti pattern arises over a period of time where a number of programmers have worked on a system on various pieces of code. Dur to the lack of knowledge of the current systems the programmers write code which may have already been present and results in a lot of redundant code. Information being shared across the system which may result in it being globally declared and eventually making the code unreadable and unmanageable.&lt;br /&gt;
====Example====&lt;br /&gt;
    float CalculateTotal(int quantity, float price){&lt;br /&gt;
       return quantity*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    float CalculateAmount(int amt, float price){&lt;br /&gt;
       return amt*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The above code shows two functions that perform the same function but was created which results in code redundancy and unreadable.&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
*Good understanding of the system prior to any major code changes.&lt;br /&gt;
*Modularizing the code and defining the functionality at the proper location can help reduce the code redundancy.&lt;br /&gt;
*Technical shifts(client-server to web based, file based to database based etc) can provide good reasons to create the system from scratch.  &lt;br /&gt;
&lt;br /&gt;
===Race Hazard===&lt;br /&gt;
====Definition====&lt;br /&gt;
A race hazard or a race condition is a flaw in the system where the output of the system depends on the order in which the system executes. This leads to inconsistency in the output. This term was coined with the idea of two signals racing each other to influence each other.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
    global integer A = 0;&lt;br /&gt;
    //increments the value of A and prints &amp;quot;RX&amp;quot;&lt;br /&gt;
    // activated whenever an interrupt is received from the controller&lt;br /&gt;
    task Received()&lt;br /&gt;
    {&lt;br /&gt;
        A = A + 1&lt;br /&gt;
        print RX&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    //prints out only even numbers&lt;br /&gt;
    //is activated whenever an  interrupt is received from the serial controller&lt;br /&gt;
    task timeout()&lt;br /&gt;
    {&lt;br /&gt;
       if(A is divisible by 2)&lt;br /&gt;
       {&lt;br /&gt;
           print A&lt;br /&gt;
       }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    Output would look like &lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    2&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    4&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
Mutexes can be used to address this problem in concurrent programming.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Magic Bushbutton===&lt;br /&gt;
====Definition====&lt;br /&gt;
This is a very common anti pattern that shows up on graphical user interfaces programming environments. The user first draws the user interface and then builds up the business logic in the automatically created methods.&lt;br /&gt;
Some of the issues faced in this&lt;br /&gt;
*The code for in those defined functions grow large.&lt;br /&gt;
*Change in the user interface leads to a lot of changes in the functions and becomes difficult to manage.&lt;br /&gt;
*Testing becomes an issue.&lt;br /&gt;
====Example====&lt;br /&gt;
Below is a Bad example of Magic PushButton Anti Pattern.    &lt;br /&gt;
    procedure TForm1.ButtonClick(Sender: TObject);&lt;br /&gt;
    var &lt;br /&gt;
       reg:TRegistry;&lt;br /&gt;
    begin&lt;br /&gt;
       reg:TRegistry.Create;&lt;br /&gt;
    try&lt;br /&gt;
       reg.RootKey:= HKey_Current_User;&lt;br /&gt;
       if reg.OpenKey('\Software\mycompany',true) then&lt;br /&gt;
       begin&lt;br /&gt;
         reg.WriteString('Filename',edit1.text);&lt;br /&gt;
       end;&lt;br /&gt;
      finally&lt;br /&gt;
       reg.Free;&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
A good example of the same is given below. This is done by refactoring the business logic. IN the below example this is done by storing the file in an registry in a separate class. &lt;br /&gt;
&lt;br /&gt;
    type&lt;br /&gt;
     TReference = class&lt;br /&gt;
     private  &lt;br /&gt;
       FFilename: string&lt;br /&gt;
       procedure SetFilename(const Value: string)&lt;br /&gt;
     public&lt;br /&gt;
       property Filename:string read FFilename write SetFilename;&lt;br /&gt;
       procedure Load;&lt;br /&gt;
       procedure Save;&lt;br /&gt;
     end&lt;br /&gt;
&lt;br /&gt;
The above code will call Save method from the click handler.&lt;br /&gt;
    procedure TForm1.ButtonClick  (Sender: Object);&lt;br /&gt;
    begin&lt;br /&gt;
       Preference.Save;&lt;br /&gt;
    end;&lt;br /&gt;
    procedure TForm1.EditChange (Sender: TObject);&lt;br /&gt;
    begin&lt;br /&gt;
      Preferences.Filename:= edit1.text;&lt;br /&gt;
    end;&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
*Create functions and modularize the code as much as possible so that the code could be well maintained and flexible.&lt;br /&gt;
&lt;br /&gt;
==Object-oriented design anti-patterns==&lt;br /&gt;
&lt;br /&gt;
* Anemic Domain Model&lt;br /&gt;
Separating the [http://en.wikipedia.org/wiki/Business_logic business logic] from the [http://en.wikipedia.org/wiki/Domain_model Domain Model] is termed as Anemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's [http://en.wikipedia.org/wiki/Entity_Bean Entity beans] and .Net's three layered service application. A short example for Anaemic Model is given below,&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
Although, the above code looks right by providing segregation of data and service, its in violation of OOP principle of data and behaviour [http://en.wikipedia.org/wiki/Encapsulation encapsulation].It could run into problems when there are muliple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* BaseBean&lt;br /&gt;
In the practise of BaseBean, subclasses are derived from an utility class, even though delegation is possible. [http://en.wikipedia.org/wiki/Inheritance Inheritance] can be evil sometimes, either breaking some subclass due to change in parent class or very deep hierarchy of classes leading to confusion and no reuse of code. For example, if we want to create a student class and we already have person class, inheritance is not the right way to go. We can use delegation and create instance of Person class in Student class and utilize all the features of class Person in class Student.&lt;br /&gt;
&lt;br /&gt;
* CallSuper &lt;br /&gt;
CallSuper is a antipattern in which subclass [http://en.wikipedia.org/wiki/Method_overriding overrides] a parent's method and calls the parent's overridden method from the same method. This is considered as a bad practise because, in the future if the parent class's implementation changes it breaks the subclass too. And also it puts an additional responsiblity on the subclass's developer to call Super.The correct way to go about this is the parent class declaring a separate hook method for subclass to override.&lt;br /&gt;
  // '''Wrong Way'''                                                         // '''Correct Way'''&lt;br /&gt;
  public class EventHandle{                                             public class EventHandle{&lt;br /&gt;
    public void handle (BankingEvent e) {                                  public void handle (BankingEvent e) {&lt;br /&gt;
      cleanUp(e);                                                            cleanUp(e);&lt;br /&gt;
    }                                                                        doHandle(e);  //hook method&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
  public class TransferEventHandler extends EventHandle{                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    public void handle(BankingEvent e) {                                   }&lt;br /&gt;
      super.handle(e);                                                     public class TransferEventHandler extends EventHandle{&lt;br /&gt;
      initiateTransfer(e);                                                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    }                                                                           initiateTransfer(e);&lt;br /&gt;
                                                                             }&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Design_pattern_(computer_science) Design Patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Code_smell Code Smell]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern Anti-pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anemic_Domain_Model Anemic Domain Model]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/BaseBean BaseBean]&lt;br /&gt;
&lt;br /&gt;
==External Links==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.antipatterns.com/ &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://c2.com/cgi/wiki?AntiPattern &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.martinfowler.com/bliki/CallSuper.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis by William J.Brown and Raphael C.Malveau&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27547</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27547"/>
		<updated>2009-11-17T19:51:52Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Definition */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti pattern was used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system&lt;br /&gt;
*Inexperience on the part of the programmer&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
Anti-Patterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
===Abstraction Inversion===&lt;br /&gt;
====Definition====&lt;br /&gt;
Abstarction Inversion means implementing a lower level construct on top of high level constructs. A simple example would be suppose we have 2 constructs A and B. Let B be implemented on top of A but A is not exposed anywhere in the system and if we really require A then we end up building A on top of B and B was already implemented in terms of A.&lt;br /&gt;
A short Example of Abstraction Inversion is given below&lt;br /&gt;
====Example====&lt;br /&gt;
The below code implements a set of binary values in a String which decide if it is true or false. (e.g. 'T' or 'F'). They then use the indexer to find the bit.&lt;br /&gt;
    char[] bitString ...;&lt;br /&gt;
    if (bitString[i] == 'T') { // do stuff&lt;br /&gt;
&lt;br /&gt;
So in this case we have a character representing a bit value, but a character is nothing but a sequence of bits. Therefore we have a sequence made up of characters containing bits which are made up of a bit sequence.&lt;br /&gt;
====Solution====&lt;br /&gt;
*Choose the infrastructure carefully.&lt;br /&gt;
*If the system offers w=equivalent functions, use them.&lt;br /&gt;
*Do not inject any weak constructs into the system.&lt;br /&gt;
&lt;br /&gt;
===Big ball of mud===&lt;br /&gt;
====Definition====&lt;br /&gt;
This term was coined by Brain Foote and Joseph Yoder's paper in 1999. This kind of anti pattern arises over a period of time where a number of programmers have worked on a system on various pieces of code. Dur to the lack of knowledge of the current systems the programmers write code which may have already been present and results in a lot of redundant code. Information being shared across the system which may result in it being globally declared and eventually making the code unreadable and unmanageable.&lt;br /&gt;
====Example====&lt;br /&gt;
    float CalculateTotal(int quantity, float price){&lt;br /&gt;
       return quantity*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    float CalculateAmount(int amt, float price){&lt;br /&gt;
       return amt*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The above code shows two functions that perform the same function but was created which results in code redundancy and unreadable.&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
*Good understanding of the system prior to any major code changes.&lt;br /&gt;
*Modularizing the code and defining the functionality at the proper location can help reduce the code redundancy.&lt;br /&gt;
*Technical shifts(client-server to web based, file based to database based etc) can provide good reasons to create the system from scratch.  &lt;br /&gt;
&lt;br /&gt;
===Race Hazard===&lt;br /&gt;
====Definition====&lt;br /&gt;
A race hazard or a race condition is a flaw in the system where the output of the system depends on the order in which the system executes. This leads to inconsistency in the output. This term was coined with the idea of two signals racing each other to influence each other.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
    global integer A = 0;&lt;br /&gt;
    //increments the value of A and prints &amp;quot;RX&amp;quot;&lt;br /&gt;
    // activated whenever an interrupt is received from the controller&lt;br /&gt;
    task Received()&lt;br /&gt;
    {&lt;br /&gt;
        A = A + 1&lt;br /&gt;
        print RX&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    //prints out only even numbers&lt;br /&gt;
    //is activated whenever an  interrupt is received from the serial controller&lt;br /&gt;
    task timeout()&lt;br /&gt;
    {&lt;br /&gt;
       if(A is divisible by 2)&lt;br /&gt;
       {&lt;br /&gt;
           print A&lt;br /&gt;
       }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    Output would look like &lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    2&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    4&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
Mutexes can be used to address this problem in concurrent programming.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Magic Bushbutton===&lt;br /&gt;
====Definition====&lt;br /&gt;
This is a very common anti pattern that shows up on graphical user interfaces programming environments. The user first draws the user interface and then builds up the business logic in the automatically created methods.&lt;br /&gt;
Some of the issues faced in this&lt;br /&gt;
*The code for in those defined functions grow large.&lt;br /&gt;
*Change in the user interface leads to a lot of changes in the functions and becomes difficult to manage.&lt;br /&gt;
*Testing becomes an issue.&lt;br /&gt;
====Example====&lt;br /&gt;
    procedure TForm1.ButtonClick(Sender: TObject);&lt;br /&gt;
    var &lt;br /&gt;
       reg:TRegistry;&lt;br /&gt;
    begin&lt;br /&gt;
       reg:TRegistry.Create;&lt;br /&gt;
    try&lt;br /&gt;
       reg.RootKey:= HKey_Current_User;&lt;br /&gt;
       if reg.OpenKey('\Software\mycompany',true) then&lt;br /&gt;
       begin&lt;br /&gt;
         reg.WriteString('Filename',edit1.text);&lt;br /&gt;
       end;&lt;br /&gt;
      finally&lt;br /&gt;
       reg.Free;&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
==Object-oriented design anti-patterns==&lt;br /&gt;
&lt;br /&gt;
* Anemic Domain Model&lt;br /&gt;
Separating the [http://en.wikipedia.org/wiki/Business_logic business logic] from the [http://en.wikipedia.org/wiki/Domain_model Domain Model] is termed as Anemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's [http://en.wikipedia.org/wiki/Entity_Bean Entity beans] and .Net's three layered service application. A short example for Anaemic Model is given below,&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
Although, the above code looks right by providing segregation of data and service, its in violation of OOP principle of data and behaviour [http://en.wikipedia.org/wiki/Encapsulation encapsulation].It could run into problems when there are muliple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* BaseBean&lt;br /&gt;
In the practise of BaseBean, subclasses are derived from an utility class, even though delegation is possible. [http://en.wikipedia.org/wiki/Inheritance Inheritance] can be evil sometimes, either breaking some subclass due to change in parent class or very deep hierarchy of classes leading to confusion and no reuse of code. For example, if we want to create a student class and we already have person class, inheritance is not the right way to go. We can use delegation and create instance of Person class in Student class and utilize all the features of class Person in class Student.&lt;br /&gt;
&lt;br /&gt;
* CallSuper &lt;br /&gt;
CallSuper is a antipattern in which subclass [http://en.wikipedia.org/wiki/Method_overriding overrides] a parent's method and calls the parent's overridden method from the same method. This is considered as a bad practise because, in the future if the parent class's implementation changes it breaks the subclass too. And also it puts an additional responsiblity on the subclass's developer to call Super.The correct way to go about this is the parent class declaring a separate hook method for subclass to override.&lt;br /&gt;
  // '''Wrong Way'''                                                         // '''Correct Way'''&lt;br /&gt;
  public class EventHandle{                                             public class EventHandle{&lt;br /&gt;
    public void handle (BankingEvent e) {                                  public void handle (BankingEvent e) {&lt;br /&gt;
      cleanUp(e);                                                            cleanUp(e);&lt;br /&gt;
    }                                                                        doHandle(e);  //hook method&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
  public class TransferEventHandler extends EventHandle{                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    public void handle(BankingEvent e) {                                   }&lt;br /&gt;
      super.handle(e);                                                     public class TransferEventHandler extends EventHandle{&lt;br /&gt;
      initiateTransfer(e);                                                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    }                                                                           initiateTransfer(e);&lt;br /&gt;
                                                                             }&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Design_pattern_(computer_science) Design Patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Code_smell Code Smell]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern Anti-pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anemic_Domain_Model Anemic Domain Model]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/BaseBean BaseBean]&lt;br /&gt;
&lt;br /&gt;
==External Links==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.antipatterns.com/ &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://c2.com/cgi/wiki?AntiPattern &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.martinfowler.com/bliki/CallSuper.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis by William J.Brown and Raphael C.Malveau&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27544</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27544"/>
		<updated>2009-11-17T19:46:46Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Object-oriented design anti-patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti pattern was used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system&lt;br /&gt;
*Inexperience on the part of the programmer&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
Anti-Patterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
===Abstraction Inversion===&lt;br /&gt;
====Definition====&lt;br /&gt;
Abstarction Inversion means implementing a lower level construct on top of high level constructs. A simple example would be suppose we have 2 constructs A and B. Let B be implemented on top of A but A is not exposed anywhere in the system and if we really require A then we end up building A on top of B and B was already implemented in terms of A.&lt;br /&gt;
A short Example of Abstraction Inversion is given below&lt;br /&gt;
====Example====&lt;br /&gt;
The below code implements a set of binary values in a String which decide if it is true or false. (e.g. 'T' or 'F'). They then use the indexer to find the bit.&lt;br /&gt;
    char[] bitString ...;&lt;br /&gt;
    if (bitString[i] == 'T') { // do stuff&lt;br /&gt;
&lt;br /&gt;
So in this case we have a character representing a bit value, but a character is nothing but a sequence of bits. Therefore we have a sequence made up of characters containing bits which are made up of a bit sequence.&lt;br /&gt;
====Solution====&lt;br /&gt;
*Choose the infrastructure carefully.&lt;br /&gt;
*If the system offers w=equivalent functions, use them.&lt;br /&gt;
*Do not inject any weak constructs into the system.&lt;br /&gt;
&lt;br /&gt;
===Big ball of mud===&lt;br /&gt;
====Definition====&lt;br /&gt;
This term was coined by Brain Foote and Joseph Yoder's paper in 1999. This kind of anti pattern arises over a period of time where a number of programmers have worked on a system on various pieces of code. Dur to the lack of knowledge of the current systems the programmers write code which may have already been present and results in a lot of redundant code. Information being shared across the system which may result in it being globally declared and eventually making the code unreadable and unmanageable.&lt;br /&gt;
====Example====&lt;br /&gt;
    float CalculateTotal(int quantity, float price){&lt;br /&gt;
       return quantity*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    float CalculateAmount(int amt, float price){&lt;br /&gt;
       return amt*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The above code shows two functions that perform the same function but was created which results in code redundancy and unreadable.&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
*Good understanding of the system prior to any major code changes.&lt;br /&gt;
*Modularizing the code and defining the functionality at the proper location can help reduce the code redundancy.&lt;br /&gt;
*Technical shifts(client-server to web based, file based to database based etc) can provide good reasons to create the system from scratch.  &lt;br /&gt;
&lt;br /&gt;
===Race Hazard===&lt;br /&gt;
====Definition====&lt;br /&gt;
A race hazard or a race condition is a flaw in the system where the output of the system depends on the order in which the system executes. This leads to inconsistency in the output. This term was coined with the idea of two signals racing each other to influence each other.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
    global integer A = 0;&lt;br /&gt;
    //increments the value of A and prints &amp;quot;RX&amp;quot;&lt;br /&gt;
    // activated whenever an interrupt is received from the controller&lt;br /&gt;
    task Received()&lt;br /&gt;
    {&lt;br /&gt;
        A = A + 1&lt;br /&gt;
        print RX&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    //prints out only even numbers&lt;br /&gt;
    //is activated whenever an  interrupt is received from the serial controller&lt;br /&gt;
    task timeout()&lt;br /&gt;
    {&lt;br /&gt;
       if(A is divisible by 2)&lt;br /&gt;
       {&lt;br /&gt;
           print A&lt;br /&gt;
       }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    Output would look like &lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    2&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    4&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
Mutexes can be used to address this problem in concurrent programming.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Magic Bushbutton===&lt;br /&gt;
====Definition====&lt;br /&gt;
This is a very common anti pattern that shows up on graphical user interfaces programming environments. The user first draws the user interface and then builds up the business logic in the automatically created methods.&lt;br /&gt;
Some of the issues faced in this&lt;br /&gt;
*The code for in those defined functions grow large.&lt;br /&gt;
*Change in the user interface leads to a lot of changes in the functions and becomes difficult to manage.&lt;br /&gt;
*Testing becomes an issue.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Object-oriented design anti-patterns==&lt;br /&gt;
&lt;br /&gt;
* Anemic Domain Model&lt;br /&gt;
Separating the [http://en.wikipedia.org/wiki/Business_logic business logic] from the [http://en.wikipedia.org/wiki/Domain_model Domain Model] is termed as Anemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's [http://en.wikipedia.org/wiki/Entity_Bean Entity beans] and .Net's three layered service application. A short example for Anaemic Model is given below,&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
Although, the above code looks right by providing segregation of data and service, its in violation of OOP principle of data and behaviour [http://en.wikipedia.org/wiki/Encapsulation encapsulation].It could run into problems when there are muliple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* BaseBean&lt;br /&gt;
In the practise of BaseBean, subclasses are derived from an utility class, even though delegation is possible. [http://en.wikipedia.org/wiki/Inheritance Inheritance] can be evil sometimes, either breaking some subclass due to change in parent class or very deep hierarchy of classes leading to confusion and no reuse of code. For example, if we want to create a student class and we already have person class, inheritance is not the right way to go. We can use delegation and create instance of Person class in Student class and utilize all the features of class Person in class Student.&lt;br /&gt;
&lt;br /&gt;
* CallSuper &lt;br /&gt;
CallSuper is a antipattern in which subclass [http://en.wikipedia.org/wiki/Method_overriding overrides] a parent's method and calls the parent's overridden method from the same method. This is considered as a bad practise because, in the future if the parent class's implementation changes it breaks the subclass too. And also it puts an additional responsiblity on the subclass's developer to call Super.The correct way to go about this is the parent class declaring a separate hook method for subclass to override.&lt;br /&gt;
  // '''Wrong Way'''                                                         // '''Correct Way'''&lt;br /&gt;
  public class EventHandle{                                             public class EventHandle{&lt;br /&gt;
    public void handle (BankingEvent e) {                                  public void handle (BankingEvent e) {&lt;br /&gt;
      cleanUp(e);                                                            cleanUp(e);&lt;br /&gt;
    }                                                                        doHandle(e);  //hook method&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
  public class TransferEventHandler extends EventHandle{                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    public void handle(BankingEvent e) {                                   }&lt;br /&gt;
      super.handle(e);                                                     public class TransferEventHandler extends EventHandle{&lt;br /&gt;
      initiateTransfer(e);                                                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    }                                                                           initiateTransfer(e);&lt;br /&gt;
                                                                             }&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Design_pattern_(computer_science) Design Patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Code_smell Code Smell]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern Anti-pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anemic_Domain_Model Anemic Domain Model]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/BaseBean BaseBean]&lt;br /&gt;
&lt;br /&gt;
==External Links==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.antipatterns.com/ &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://c2.com/cgi/wiki?AntiPattern &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.martinfowler.com/bliki/CallSuper.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis by William J.Brown and Raphael C.Malveau&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27530</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27530"/>
		<updated>2009-11-17T19:30:05Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti pattern was used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system&lt;br /&gt;
*Inexperience on the part of the programmer&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
Anti-Patterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
===Abstraction Inversion===&lt;br /&gt;
====Definition====&lt;br /&gt;
Abstarction Inversion means implementing a lower level construct on top of high level constructs. A simple example would be suppose we have 2 constructs A and B. Let B be implemented on top of A but A is not exposed anywhere in the system and if we really require A then we end up building A on top of B and B was already implemented in terms of A.&lt;br /&gt;
A short Example of Abstraction Inversion is given below&lt;br /&gt;
====Example====&lt;br /&gt;
The below code implements a set of binary values in a String which decide if it is true or false. (e.g. 'T' or 'F'). They then use the indexer to find the bit.&lt;br /&gt;
    char[] bitString ...;&lt;br /&gt;
    if (bitString[i] == 'T') { // do stuff&lt;br /&gt;
&lt;br /&gt;
So in this case we have a character representing a bit value, but a character is nothing but a sequence of bits. Therefore we have a sequence made up of characters containing bits which are made up of a bit sequence.&lt;br /&gt;
====Solution====&lt;br /&gt;
*Choose the infrastructure carefully.&lt;br /&gt;
*If the system offers w=equivalent functions, use them.&lt;br /&gt;
*Do not inject any weak constructs into the system.&lt;br /&gt;
&lt;br /&gt;
===Big ball of mud===&lt;br /&gt;
====Definition====&lt;br /&gt;
This term was coined by Brain Foote and Joseph Yoder's paper in 1999. This kind of anti pattern arises over a period of time where a number of programmers have worked on a system on various pieces of code. Dur to the lack of knowledge of the current systems the programmers write code which may have already been present and results in a lot of redundant code. Information being shared across the system which may result in it being globally declared and eventually making the code unreadable and unmanageable.&lt;br /&gt;
====Example====&lt;br /&gt;
    float CalculateTotal(int quantity, float price){&lt;br /&gt;
       return quantity*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    float CalculateAmount(int amt, float price){&lt;br /&gt;
       return amt*price;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The above code shows two functions that perform the same function but was created which results in code redundancy and unreadable.&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
*Good understanding of the system prior to any major code changes.&lt;br /&gt;
*Modularizing the code and defining the functionality at the proper location can help reduce the code redundancy.&lt;br /&gt;
*Technical shifts(client-server to web based, file based to database based etc) can provide good reasons to create the system from scratch.  &lt;br /&gt;
&lt;br /&gt;
===Race Hazard===&lt;br /&gt;
====Definition====&lt;br /&gt;
A race hazard or a race condition is a flaw in the system where the output of the system depends on the order in which the system executes. This leads to inconsistency in the output. This term was coined with the idea of two signals racing each other to influence each other.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
    global integer A = 0;&lt;br /&gt;
    //increments the value of A and prints &amp;quot;RX&amp;quot;&lt;br /&gt;
    // activated whenever an interrupt is received from the controller&lt;br /&gt;
    task Received()&lt;br /&gt;
    {&lt;br /&gt;
        A = A + 1&lt;br /&gt;
        print RX&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    //prints out only even numbers&lt;br /&gt;
    //is activated whenever an  interrupt is received from the serial controller&lt;br /&gt;
    task timeout()&lt;br /&gt;
    {&lt;br /&gt;
       if(A is divisible by 2)&lt;br /&gt;
       {&lt;br /&gt;
           print A&lt;br /&gt;
       }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    Output would look like &lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    2&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    4&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
Mutexes can be used to address this problem in concurrent programming.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Object-oriented design anti-patterns==&lt;br /&gt;
&lt;br /&gt;
* Anemic Domain Model&lt;br /&gt;
Separating the [http://en.wikipedia.org/wiki/Business_logic business logic] from the [http://en.wikipedia.org/wiki/Domain_model Domain Model] is termed as Anemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's [http://en.wikipedia.org/wiki/Entity_Bean Entity beans] and .Net's three layered service application. A short example for Anaemic Model is given below,&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
Although, the above code looks right by providing segregation of data and service, its in violation of OOP principle of data and behaviour [http://en.wikipedia.org/wiki/Encapsulation encapsulation].It could run into problems when there are muliple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* BaseBean&lt;br /&gt;
In the practise of BaseBean, subclasses are derived from an utility class, even though delegation is possible. [http://en.wikipedia.org/wiki/Inheritance Inheritance] can be evil sometimes, either breaking some subclass due to change in parent class or very deep hierarchy of classes leading to confusion and no reuse of code. For example, if we want to create a student class and we already have person class, inheritance is not the right way to go. We can use delegation and create instance of Person class in Student class and utilize all the features of class Person in class Student.&lt;br /&gt;
&lt;br /&gt;
* CallSuper &lt;br /&gt;
CallSuper is a antipattern in which subclass [http://en.wikipedia.org/wiki/Method_overriding overrides] a parent's method and calls the parent's overridden method from the same method. This is considered as a bad practise because, in the future if the parent class's implementation changes it breaks the subclass too. And also it puts an additional responsiblity on the subclass's developer to call Super.The correct way to go about this is the parent class declaring a separate hook method for subclass to override.&lt;br /&gt;
  // '''Wrong Way'''                                                         // '''Correct Way'''&lt;br /&gt;
  public class EventHandle{                                             public class EventHandle{&lt;br /&gt;
    public void handle (BankingEvent e) {                                  public void handle (BankingEvent e) {&lt;br /&gt;
      cleanUp(e);                                                            cleanUp(e);&lt;br /&gt;
    }                                                                        doHandle(e);  //hook method&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
  public class TransferEventHandler extends EventHandle{                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    public void handle(BankingEvent e) {                                   }&lt;br /&gt;
      super.handle(e);                                                     public class TransferEventHandler extends EventHandle{&lt;br /&gt;
      initiateTransfer(e);                                                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    }                                                                           initiateTransfer(e);&lt;br /&gt;
                                                                             }&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Design_pattern_(computer_science) Design Patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Code_smell Code Smell]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern Anti-pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anemic_Domain_Model Anemic Domain Model]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/BaseBean BaseBean]&lt;br /&gt;
&lt;br /&gt;
==External Links==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.antipatterns.com/ &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://c2.com/cgi/wiki?AntiPattern &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.martinfowler.com/bliki/CallSuper.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis by William J.Brown and Raphael C.Malveau&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27529</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=27529"/>
		<updated>2009-11-17T19:29:37Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti pattern was used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system&lt;br /&gt;
*Inexperience on the part of the programmer&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
Anti-Patterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
===Abstraction Inversion===&lt;br /&gt;
====Definition====&lt;br /&gt;
Abstarction Inversion means implementing a lower level construct on top of high level constructs. A simple example would be suppose we have 2 constructs A and B. Let B be implemented on top of A but A is not exposed anywhere in the system and if we really require A then we end up building A on top of B and B was already implemented in terms of A.&lt;br /&gt;
A short Example of Abstraction Inversion is given below&lt;br /&gt;
====Example====&lt;br /&gt;
The below code implements a set of binary values in a String which decide if it is true or false. (e.g. 'T' or 'F'). They then use the indexer to find the bit.&lt;br /&gt;
    char[] bitString ...;&lt;br /&gt;
    if (bitString[i] == 'T') { // do stuff&lt;br /&gt;
&lt;br /&gt;
So in this case we have a character representing a bit value, but a character is nothing but a sequence of bits. Therefore we have a sequence made up of characters containing bits which are made up of a bit sequence.&lt;br /&gt;
====Solution====&lt;br /&gt;
*Choose the infrastructure carefully.&lt;br /&gt;
*If the system offers w=equivalent functions, use them.&lt;br /&gt;
*Do not inject any weak constructs into the system.&lt;br /&gt;
&lt;br /&gt;
===Big ball of mud===&lt;br /&gt;
====Definition====&lt;br /&gt;
This term was coined by Brain Foote and Joseph Yoder's paper in 1999. This kind of anti pattern arises over a period of time where a number of programmers have worked on a system on various pieces of code. Dur to the lack of knowledge of the current systems the programmers write code which may have already been present and results in a lot of redundant code. Information being shared across the system which may result in it being globally declared and eventually making the code unreadable and unmanageable.&lt;br /&gt;
====Example====&lt;br /&gt;
float CalculateTotal(int quantity, float price){&lt;br /&gt;
   return quantity*price;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float CalculateAmount(int amt, float price){&lt;br /&gt;
   return amt*price;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
The above code shows two functions that perform the same function but was created which results in code redundancy and unreadable.&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
*Good understanding of the system prior to any major code changes.&lt;br /&gt;
*Modularizing the code and defining the functionality at the proper location can help reduce the code redundancy.&lt;br /&gt;
*Technical shifts(client-server to web based, file based to database based etc) can provide good reasons to create the system from scratch.  &lt;br /&gt;
&lt;br /&gt;
===Race Hazard===&lt;br /&gt;
====Definition====&lt;br /&gt;
A race hazard or a race condition is a flaw in the system where the output of the system depends on the order in which the system executes. This leads to inconsistency in the output. This term was coined with the idea of two signals racing each other to influence each other.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
    global integer A = 0;&lt;br /&gt;
    //increments the value of A and prints &amp;quot;RX&amp;quot;&lt;br /&gt;
    // activated whenever an interrupt is received from the controller&lt;br /&gt;
    task Received()&lt;br /&gt;
    {&lt;br /&gt;
        A = A + 1&lt;br /&gt;
        print RX&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    //prints out only even numbers&lt;br /&gt;
    //is activated whenever an  interrupt is received from the serial controller&lt;br /&gt;
    task timeout()&lt;br /&gt;
    {&lt;br /&gt;
       if(A is divisible by 2)&lt;br /&gt;
       {&lt;br /&gt;
           print A&lt;br /&gt;
       }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    Output would look like &lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    0&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    2&lt;br /&gt;
    RX&lt;br /&gt;
    RX&lt;br /&gt;
    4&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
Mutexes can be used to address this problem in concurrent programming.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Object-oriented design anti-patterns==&lt;br /&gt;
&lt;br /&gt;
* Anemic Domain Model&lt;br /&gt;
Separating the [http://en.wikipedia.org/wiki/Business_logic business logic] from the [http://en.wikipedia.org/wiki/Domain_model Domain Model] is termed as Anemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's [http://en.wikipedia.org/wiki/Entity_Bean Entity beans] and .Net's three layered service application. A short example for Anaemic Model is given below,&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
Although, the above code looks right by providing segregation of data and service, its in violation of OOP principle of data and behaviour [http://en.wikipedia.org/wiki/Encapsulation encapsulation].It could run into problems when there are muliple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* BaseBean&lt;br /&gt;
In the practise of BaseBean, subclasses are derived from an utility class, even though delegation is possible. [http://en.wikipedia.org/wiki/Inheritance Inheritance] can be evil sometimes, either breaking some subclass due to change in parent class or very deep hierarchy of classes leading to confusion and no reuse of code. For example, if we want to create a student class and we already have person class, inheritance is not the right way to go. We can use delegation and create instance of Person class in Student class and utilize all the features of class Person in class Student.&lt;br /&gt;
&lt;br /&gt;
* CallSuper &lt;br /&gt;
CallSuper is a antipattern in which subclass [http://en.wikipedia.org/wiki/Method_overriding overrides] a parent's method and calls the parent's overridden method from the same method. This is considered as a bad practise because, in the future if the parent class's implementation changes it breaks the subclass too. And also it puts an additional responsiblity on the subclass's developer to call Super.The correct way to go about this is the parent class declaring a separate hook method for subclass to override.&lt;br /&gt;
  // '''Wrong Way'''                                                         // '''Correct Way'''&lt;br /&gt;
  public class EventHandle{                                             public class EventHandle{&lt;br /&gt;
    public void handle (BankingEvent e) {                                  public void handle (BankingEvent e) {&lt;br /&gt;
      cleanUp(e);                                                            cleanUp(e);&lt;br /&gt;
    }                                                                        doHandle(e);  //hook method&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
  public class TransferEventHandler extends EventHandle{                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    public void handle(BankingEvent e) {                                   }&lt;br /&gt;
      super.handle(e);                                                     public class TransferEventHandler extends EventHandle{&lt;br /&gt;
      initiateTransfer(e);                                                   protected void doHandle(BankingEvent e) {&lt;br /&gt;
    }                                                                           initiateTransfer(e);&lt;br /&gt;
                                                                             }&lt;br /&gt;
  }                                                                        }&lt;br /&gt;
&lt;br /&gt;
==Conclusion==&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Design_pattern_(computer_science) Design Patterns]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Code_smell Code Smell]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anti-pattern Anti-pattern]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/Anemic_Domain_Model Anemic Domain Model]&lt;br /&gt;
* [http://en.wikipedia.org/wiki/BaseBean BaseBean]&lt;br /&gt;
&lt;br /&gt;
==External Links==&lt;br /&gt;
&lt;br /&gt;
[1] http://www.antipatterns.com/ &amp;lt;br&amp;gt;&lt;br /&gt;
[2] http://c2.com/cgi/wiki?AntiPattern &amp;lt;br&amp;gt;&lt;br /&gt;
[3] http://www.martinfowler.com/bliki/CallSuper.html &amp;lt;br&amp;gt;&lt;br /&gt;
[4] AntiPatterns: Refactoring Software, Architectures, and Projects in Crisis by William J.Brown and Raphael C.Malveau&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=26750</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=26750"/>
		<updated>2009-11-13T04:00:49Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Object-oriented design anti-patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti pattern was used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system&lt;br /&gt;
*Inexperience on the part of the programmer&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
Anti-Patterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
===Abstraction Inversion===&lt;br /&gt;
====Definition====&lt;br /&gt;
Abstarction Inversion means implementing a lower level construct on top of high level constructs. A simple example would be suppose we have 2 constructs A and B. Let B be implemented on top of A but A is not exposed anywhere in the system and if we really require A then we end up building A on top of B and B was already implemented in terms of A.&lt;br /&gt;
A short Example of Abstraction Inversion is given below&lt;br /&gt;
====Example====&lt;br /&gt;
The below code implements a set of binary values in a String which decide if it is true or false. (e.g. 'T' or 'F'). They then use the indexer to find the bit.&lt;br /&gt;
    char[] bitString ...;&lt;br /&gt;
    if (bitString[i] == 'T') { // do stuff&lt;br /&gt;
&lt;br /&gt;
So in this case we have a character representing a bit value, but a character is nothing but a sequence of bits. Therefore we have a sequence made up of characters containing bits which are made up of a bit sequence.&lt;br /&gt;
====Solution====&lt;br /&gt;
*Choose the infrastructure carefully.&lt;br /&gt;
*If the system offers w=equivalent functions, use them.&lt;br /&gt;
*Do not inject any weak constructs into the system.&lt;br /&gt;
&lt;br /&gt;
===Big ball of mud===&lt;br /&gt;
====Definition====&lt;br /&gt;
This term was coined by Brain Foote and Joseph Yoder's paper in 1999. This kind of anti pattern arises over a period of time where a number of programmers have worked on a system on various pieces of code. Dur to the lack of knowledge of the current systems the programmers write code which may have already been present and results in a lot of redundant code. Information being shared across the system which may result in it being globally declared and eventually making the code unreadable and unmanageable.&lt;br /&gt;
====Example====&lt;br /&gt;
float CalculateTotal(int quantity, float price){&lt;br /&gt;
   return quantity*price;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float CalculateAmount(int amt, float price){&lt;br /&gt;
   return amt*price;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
The above code shows two functions that perform the same function but was created which results in code redundancy and unreadable.&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
*Good understanding of the system prior to any major code changes.&lt;br /&gt;
*Modularizing the code and defining the functionality at the proper location can help reduce the code redundancy.&lt;br /&gt;
*Technical shifts(client-server to web based, file based to database based etc) can provide good reasons to create the system from scratch.  &lt;br /&gt;
&lt;br /&gt;
===Race Hazard===&lt;br /&gt;
====Definition====&lt;br /&gt;
A race hazard or a race condition is a flaw in the system where the output of the system depends on the order in which the system executes. This leads to inconsistency in the output. This term was coined with the idea of two signals racing each other to influence each other.&lt;br /&gt;
&lt;br /&gt;
====Example====&lt;br /&gt;
global integer A = 0;&lt;br /&gt;
//increments the value of A and prints &amp;quot;RX&amp;quot;&lt;br /&gt;
// activated whenever an interrupt is received from the controller&lt;br /&gt;
task Received()&lt;br /&gt;
{&lt;br /&gt;
    A = A + 1&lt;br /&gt;
    print RX&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//prints out only even numbers&lt;br /&gt;
//is activated whenever an  interrupt is received from the serial controller&lt;br /&gt;
task timeout()&lt;br /&gt;
{&lt;br /&gt;
   if(A is divisible by 2)&lt;br /&gt;
   {&lt;br /&gt;
       print A&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
Output would look like &lt;br /&gt;
0&lt;br /&gt;
0&lt;br /&gt;
0&lt;br /&gt;
RX&lt;br /&gt;
RX&lt;br /&gt;
2&lt;br /&gt;
RX&lt;br /&gt;
RX&lt;br /&gt;
4&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
Mutexes can be used to address this problem in concurrent programming.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Object-oriented design anti-patterns==&lt;br /&gt;
&lt;br /&gt;
* Anaemic Domain Model&lt;br /&gt;
Separating the business logic from the Domain Model is termed as Anaemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's Entity beans and .Net's three layered service application. A short example for Anaemic Model is given below,&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
Although, the above code looks right by providing segregation of data and service, its in violation of OOP principle of data and behaviour encapsulation.It could run into problems when there are muliple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* BaseBean&lt;br /&gt;
In the practise of BaseBean, subclasses are derived from an utility class, even though delegation is possible. Inheritance can be evil sometimes, either breaking some subclass due to change in parent class or very deep hierarchy of classes leading to confusion and no resuse of code. For example, if we want to create a student class and we already have person class, inheritance is not the right way to go. We can use delegation and create instance of Person class in Student class and utilize all the features of person class in Student class.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
==References==&lt;br /&gt;
==External Links==&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=26749</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=26749"/>
		<updated>2009-11-13T03:36:18Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Example */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti pattern was used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system&lt;br /&gt;
*Inexperience on the part of the programmer&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
Anti-Patterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
===Abstraction Inversion===&lt;br /&gt;
====Definition====&lt;br /&gt;
Abstarction Inversion means implementing a lower level construct on top of high level constructs. A simple example would be suppose we have 2 constructs A and B. Let B be implemented on top of A but A is not exposed anywhere in the system and if we really require A then we end up building A on top of B and B was already implemented in terms of A.&lt;br /&gt;
A short Example of Abstraction Inversion is given below&lt;br /&gt;
====Example====&lt;br /&gt;
The below code implements a set of binary values in a String which decide if it is true or false. (e.g. 'T' or 'F'). They then use the indexer to find the bit.&lt;br /&gt;
    char[] bitString ...;&lt;br /&gt;
    if (bitString[i] == 'T') { // do stuff&lt;br /&gt;
&lt;br /&gt;
So in this case we have a character representing a bit value, but a character is nothing but a sequence of bits. Therefore we have a sequence made up of characters containing bits which are made up of a bit sequence.&lt;br /&gt;
====Solution====&lt;br /&gt;
*Choose the infrastructure carefully.&lt;br /&gt;
*If the system offers w=equivalent functions, use them.&lt;br /&gt;
*Do not inject any weak constructs into the system.&lt;br /&gt;
&lt;br /&gt;
===Big ball of mud===&lt;br /&gt;
====Definition====&lt;br /&gt;
This term was coined by Brain Foote and Joseph Yoder's paper in 1999. This kind of anti pattern arises over a period of time where a number of programmers have worked on a system on various pieces of code. Dur to the lack of knowledge of the current systems the programmers write code which may have already been present and results in a lot of redundant code. Information being shared across the system which may result in it being globally declared and eventually making the code unreadable and unmanageable.&lt;br /&gt;
====Example====&lt;br /&gt;
float CalculateTotal(int quantity, float price){&lt;br /&gt;
   return quantity*price;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float CalculateAmount(int amt, float price){&lt;br /&gt;
   return amt*price;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
The above code shows two functions that perform the same function but was created which results in code redundancy and unreadable.&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
*Good understanding of the system prior to any major code changes.&lt;br /&gt;
*Modularizing the code and defining the functionality at the proper location can help reduce the code redundancy.&lt;br /&gt;
*Technical shifts(client-server to web based, file based to database based etc) can provide good reasons to create the system from scratch.  &lt;br /&gt;
&lt;br /&gt;
==Object-oriented design anti-patterns==&lt;br /&gt;
&lt;br /&gt;
* Anaemic Domain Model&lt;br /&gt;
Separating the business logic from the Domain Model is termed as Anaemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's Entity beans and .Net's three layered service application. A short example for Anaemic Model is given below,&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
Although, the above code looks right by providing segregation of data and service, its in violation of OOP principle of data and behaviour encapsulation.It could run into problems when there are muliple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* BaseBean&lt;br /&gt;
In the practise of BaseBean, subclasses are derived from an utility class, even though delegation is possible. Inheritance can be evil sometimes, either breaking some subclass due to change in parent class or very deep hierarchy of classes leading to confusion and no resuse of code. For example, if we want to create a student class and we already have person class, inheritance is not the right way to go. We can use delegation and create instance of Person class in Student class and utilize all the features of person class in Student class.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
==References==&lt;br /&gt;
==External Links==&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=26748</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=26748"/>
		<updated>2009-11-13T03:35:27Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Object-oriented design anti-patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti pattern was used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system&lt;br /&gt;
*Inexperience on the part of the programmer&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
Anti-Patterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
===Abstraction Inversion===&lt;br /&gt;
====Definition====&lt;br /&gt;
Abstarction Inversion means implementing a lower level construct on top of high level constructs. A simple example would be suppose we have 2 constructs A and B. Let B be implemented on top of A but A is not exposed anywhere in the system and if we really require A then we end up building A on top of B and B was already implemented in terms of A.&lt;br /&gt;
A short Example of Abstraction Inversion is given below&lt;br /&gt;
====Example====&lt;br /&gt;
The below code implements a set of binary values in a String which decide if it is true or false. (e.g. 'T' or 'F'). They then use the indexer to find the bit.&lt;br /&gt;
    char[] bitString ...;&lt;br /&gt;
    if (bitString[i] == 'T') { // do stuff&lt;br /&gt;
&lt;br /&gt;
So in this case we have a character representing a bit value, but a character is nothing but a sequence of bits. Therefore we have a sequence made up of characters containing bits which are made up of a bit sequence.&lt;br /&gt;
====Solution====&lt;br /&gt;
*Choose the infrastructure carefully.&lt;br /&gt;
*If the system offers w=equivalent functions, use them.&lt;br /&gt;
*Do not inject any weak constructs into the system.&lt;br /&gt;
&lt;br /&gt;
===Big ball of mud===&lt;br /&gt;
====Definition====&lt;br /&gt;
This term was coined by Brain Foote and Joseph Yoder's paper in 1999. This kind of anti pattern arises over a period of time where a number of programmers have worked on a system on various pieces of code. Dur to the lack of knowledge of the current systems the programmers write code which may have already been present and results in a lot of redundant code. Information being shared across the system which may result in it being globally declared and eventually making the code unreadable and unmanageable.&lt;br /&gt;
====Example====&lt;br /&gt;
float CalculateTotal(int quantity, float price)&lt;br /&gt;
{&lt;br /&gt;
   return quantity*price;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
float CalculateAmount(int amt, float price)&lt;br /&gt;
{&lt;br /&gt;
   return amt*price;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
The above code shows two functions that perform the same function but was created which results in code redundancy and unreadable.&lt;br /&gt;
&lt;br /&gt;
====Solution====&lt;br /&gt;
*Good understanding of the system prior to any major code changes.&lt;br /&gt;
*Modularizing the code and defining the functionality at the proper location can help reduce the code redundancy.&lt;br /&gt;
*Technical shifts(client-server to web based, file based to database based etc) can provide good reasons to create the system from scratch.  &lt;br /&gt;
&lt;br /&gt;
==Object-oriented design anti-patterns==&lt;br /&gt;
&lt;br /&gt;
* Anaemic Domain Model&lt;br /&gt;
Separating the business logic from the Domain Model is termed as Anaemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's Entity beans and .Net's three layered service application. A short example for Anaemic Model is given below,&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
Although, the above code looks right by providing segregation of data and service, its in violation of OOP principle of data and behaviour encapsulation.It could run into problems when there are muliple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* BaseBean&lt;br /&gt;
In the practise of BaseBean, subclasses are derived from an utility class, even though delegation is possible. Inheritance can be evil sometimes, either breaking some subclass due to change in parent class or very deep hierarchy of classes leading to confusion and no resuse of code. For example, if we want to create a student class and we already have person class, inheritance is not the right way to go. We can use delegation and create instance of Person class in Student class and utilize all the features of person class in Student class.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
==References==&lt;br /&gt;
==External Links==&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=26747</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=26747"/>
		<updated>2009-11-13T03:22:34Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Object-oriented design anti-patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti pattern was used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system&lt;br /&gt;
*Inexperience on the part of the programmer&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
Anti-Patterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
===Abstraction Inversion===&lt;br /&gt;
====Definition====&lt;br /&gt;
Abstarction Inversion means implementing a lower level construct on top of high level constructs. A simple example would be suppose we have 2 constructs A and B. Let B be implemented on top of A but A is not exposed anywhere in the system and if we really require A then we end up building A on top of B and B was already implemented in terms of A.&lt;br /&gt;
A short Example of Abstraction Inversion is given below&lt;br /&gt;
====Example====&lt;br /&gt;
The below code implements a set of binary values in a String which decide if it is true or false. (e.g. 'T' or 'F'). They then use the indexer to find the bit.&lt;br /&gt;
    char[] bitString ...;&lt;br /&gt;
    if (bitString[i] == 'T') { // do stuff&lt;br /&gt;
&lt;br /&gt;
So in this case we have a character representing a bit value, but a character is nothing but a sequence of bits. Therefore we have a sequence made up of characters containing bits which are made up of a bit sequence.&lt;br /&gt;
====Solution====&lt;br /&gt;
*Choose the infrastructure carefully.&lt;br /&gt;
*If the system offers w=equivalent functions, use them.&lt;br /&gt;
*Do not inject any weak constructs into the system.&lt;br /&gt;
&lt;br /&gt;
==Object-oriented design anti-patterns==&lt;br /&gt;
&lt;br /&gt;
* Anaemic Domain Model&lt;br /&gt;
Separating the business logic from the Domain Model is termed as Anaemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's Entity beans and .Net's three layered service application. A short example for Anaemic Model is given below,&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
Although, the above code looks right by providing segregation of data and service, its in violation of OOP principle of data and behaviour encapsulation.It could run into problems when there are muliple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* BaseBean&lt;br /&gt;
In the practise of BaseBean, subclasses are derived from an utility class, even though delegation is possible. Inheritance can be evil sometimes, either breaking some subclass due to change in parent class or very deep hierarchy of classes leading to confusion and no resuse of code. For example, if we want to create a student class and we already have person class, inheritance is not the right way to go. We can use delegation and create instance of Person class in Student class and utilize all the features of person class in Student class.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
==References==&lt;br /&gt;
==External Links==&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=26746</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=26746"/>
		<updated>2009-11-13T03:21:33Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Software design anti-patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti pattern was used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system&lt;br /&gt;
*Inexperience on the part of the programmer&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
Anti-Patterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
===Abstraction Inversion===&lt;br /&gt;
====Definition====&lt;br /&gt;
Abstarction Inversion means implementing a lower level construct on top of high level constructs. A simple example would be suppose we have 2 constructs A and B. Let B be implemented on top of A but A is not exposed anywhere in the system and if we really require A then we end up building A on top of B and B was already implemented in terms of A.&lt;br /&gt;
A short Example of Abstraction Inversion is given below&lt;br /&gt;
====Example====&lt;br /&gt;
The below code implements a set of binary values in a String which decide if it is true or false. (e.g. 'T' or 'F'). They then use the indexer to find the bit.&lt;br /&gt;
    char[] bitString ...;&lt;br /&gt;
    if (bitString[i] == 'T') { // do stuff&lt;br /&gt;
&lt;br /&gt;
So in this case we have a character representing a bit value, but a character is nothing but a sequence of bits. Therefore we have a sequence made up of characters containing bits which are made up of a bit sequence.&lt;br /&gt;
====Solution====&lt;br /&gt;
*Choose the infrastructure carefully.&lt;br /&gt;
*If the system offers w=equivalent functions, use them.&lt;br /&gt;
*Do not inject any weak constructs into the system.&lt;br /&gt;
&lt;br /&gt;
===Object-oriented design anti-patterns===&lt;br /&gt;
&lt;br /&gt;
* Anaemic Domain Model&lt;br /&gt;
Separating the business logic from the Domain Model is termed as Anaemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's Entity beans and .Net's three layered service application. A short example for Anaemic Model is given below,&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
Although, the above code looks right by providing segregation of data and service, its in violation of OOP principle of data and behaviour encapsulation.It could run into problems when there are muliple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* BaseBean&lt;br /&gt;
In the practise of BaseBean, subclasses are derived from an utility class, even though delegation is possible. Inheritance can be evil sometimes, either breaking some subclass due to change in parent class or very deep hierarchy of classes leading to confusion and no resuse of code. For example, if we want to create a student class and we already have person class, inheritance is not the right way to go. We can use delegation and create instance of Person class in Student class and utilize all the features of person class in Student class.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
==References==&lt;br /&gt;
==External Links==&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=26745</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=26745"/>
		<updated>2009-11-13T03:20:39Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Solution */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti pattern was used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system&lt;br /&gt;
*Inexperience on the part of the programmer&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
Anti-Patterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
===Software design Anti- Pattern===&lt;br /&gt;
====Abstraction Inversion====&lt;br /&gt;
=====Definition=====&lt;br /&gt;
Abstarction Inversion means implementing a lower level construct on top of high level constructs. A simple example would be suppose we have 2 constructs A and B. Let B be implemented on top of A but A is not exposed anywhere in the system and if we really require A then we end up building A on top of B and B was already implemented in terms of A.&lt;br /&gt;
A short Example of Abstraction Inversion is given below&lt;br /&gt;
=====Example=====&lt;br /&gt;
The below code implements a set of binary values in a String which decide if it is true or false. (e.g. 'T' or 'F'). They then use the indexer to find the bit.&lt;br /&gt;
    char[] bitString ...;&lt;br /&gt;
    if (bitString[i] == 'T') { // do stuff&lt;br /&gt;
&lt;br /&gt;
So in this case we have a character representing a bit value, but a character is nothing but a sequence of bits. Therefore we have a sequence made up of characters containing bits which are made up of a bit sequence.&lt;br /&gt;
=====Solution=====&lt;br /&gt;
*Choose the infrastructure carefully.&lt;br /&gt;
*If the system offers w=equivalent functions, use them.&lt;br /&gt;
*Do not inject any weak constructs into the system.&lt;br /&gt;
&lt;br /&gt;
===Object-oriented design anti-patterns===&lt;br /&gt;
&lt;br /&gt;
* Anaemic Domain Model&lt;br /&gt;
Separating the business logic from the Domain Model is termed as Anaemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's Entity beans and .Net's three layered service application. A short example for Anaemic Model is given below,&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
Although, the above code looks right by providing segregation of data and service, its in violation of OOP principle of data and behaviour encapsulation.It could run into problems when there are muliple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* BaseBean&lt;br /&gt;
In the practise of BaseBean, subclasses are derived from an utility class, even though delegation is possible. Inheritance can be evil sometimes, either breaking some subclass due to change in parent class or very deep hierarchy of classes leading to confusion and no resuse of code. For example, if we want to create a student class and we already have person class, inheritance is not the right way to go. We can use delegation and create instance of Person class in Student class and utilize all the features of person class in Student class.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
==References==&lt;br /&gt;
==External Links==&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=26744</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=26744"/>
		<updated>2009-11-13T03:20:21Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Abstraction Inversion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti pattern was used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system&lt;br /&gt;
*Inexperience on the part of the programmer&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
Anti-Patterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
===Software design Anti- Pattern===&lt;br /&gt;
====Abstraction Inversion====&lt;br /&gt;
=====Definition=====&lt;br /&gt;
Abstarction Inversion means implementing a lower level construct on top of high level constructs. A simple example would be suppose we have 2 constructs A and B. Let B be implemented on top of A but A is not exposed anywhere in the system and if we really require A then we end up building A on top of B and B was already implemented in terms of A.&lt;br /&gt;
A short Example of Abstraction Inversion is given below&lt;br /&gt;
=====Example=====&lt;br /&gt;
The below code implements a set of binary values in a String which decide if it is true or false. (e.g. 'T' or 'F'). They then use the indexer to find the bit.&lt;br /&gt;
    char[] bitString ...;&lt;br /&gt;
    if (bitString[i] == 'T') { // do stuff&lt;br /&gt;
&lt;br /&gt;
So in this case we have a character representing a bit value, but a character is nothing but a sequence of bits. Therefore we have a sequence made up of characters containing bits which are made up of a bit sequence.&lt;br /&gt;
=====Solution=====&lt;br /&gt;
Choose the infrastructure carefully.&lt;br /&gt;
If the system offers w=equivalent functions, use them.&lt;br /&gt;
Do not inject any weak constructs into the system.&lt;br /&gt;
&lt;br /&gt;
===Object-oriented design anti-patterns===&lt;br /&gt;
&lt;br /&gt;
* Anaemic Domain Model&lt;br /&gt;
Separating the business logic from the Domain Model is termed as Anaemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's Entity beans and .Net's three layered service application. A short example for Anaemic Model is given below,&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
Although, the above code looks right by providing segregation of data and service, its in violation of OOP principle of data and behaviour encapsulation.It could run into problems when there are muliple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
* BaseBean&lt;br /&gt;
In the practise of BaseBean, subclasses are derived from an utility class, even though delegation is possible. Inheritance can be evil sometimes, either breaking some subclass due to change in parent class or very deep hierarchy of classes leading to confusion and no resuse of code. For example, if we want to create a student class and we already have person class, inheritance is not the right way to go. We can use delegation and create instance of Person class in Student class and utilize all the features of person class in Student class.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
==References==&lt;br /&gt;
==External Links==&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=26741</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=26741"/>
		<updated>2009-11-13T03:12:28Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Object-oriented design anti-patterns */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti pattern was used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system&lt;br /&gt;
*Inexperience on the part of the programmer&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
Anti-Patterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
===Software design Anti- Pattern===&lt;br /&gt;
====Abstraction Inversion====&lt;br /&gt;
Abstarction Inversion means implementing a lower level construct on top of high level constructs. A simple example would be suppose we have 2 constructs A and B. Let B be implemented on top of A but A is not exposed anywhere in the system and if we really require A then we end up building A on top of B and B was already implemented in terms of A.&lt;br /&gt;
A short Example of Abstraction Inversion is given below&lt;br /&gt;
&lt;br /&gt;
The below code implements a set of binary values in a String which decide if it is true or false. (e.g. 'T' or 'F'). They then use the indexer to find the bit.&lt;br /&gt;
    char[] bitString ...;&lt;br /&gt;
    if (bitString[i] == 'T') { // do stuff&lt;br /&gt;
&lt;br /&gt;
So in this case we have a character representing a bit value, but a character is nothing but a sequence of bits. Therefore we have a sequence made up of characters containing bits which are made up of a bit sequence.&lt;br /&gt;
&lt;br /&gt;
===Object-oriented design anti-patterns===&lt;br /&gt;
&lt;br /&gt;
* Anaemic Domain Model&lt;br /&gt;
Separating the business logic from the Domain Model is termed as Anaemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's Entity beans and .Net's three layered service application. A short example for Anaemic Model is given below,&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
Although, the above code looks right by providing segregation of data and service, its in violation of OOP principle of data and behaviour encapsulation.It could run into problems when there are muliple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
==References==&lt;br /&gt;
==External Links==&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=26740</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=26740"/>
		<updated>2009-11-13T02:57:16Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti pattern was used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system&lt;br /&gt;
*Inexperience on the part of the programmer&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
Anti-Patterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
===Object-oriented design anti-patterns===&lt;br /&gt;
&lt;br /&gt;
* Anaemic Domain Model&lt;br /&gt;
Separating the business logic from the Domain Model is termed as Anaemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's Entity beans and .Net's three layered service application. A short example for Anaemic Model is given below,&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
Although, the above code looks right by providing segregation of data and service, its in violation of OOP principle of data and behaviour encapsulation.It could run into problems when there are muliple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
==References==&lt;br /&gt;
==External Links==&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=26739</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=26739"/>
		<updated>2009-11-13T02:57:05Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti pattern was used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system&lt;br /&gt;
*Inexperience on the part of the programmer&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
AntiPatterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.[http://en.wikipedia.org/wiki/Anti-pattern]&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
===Object-oriented design anti-patterns===&lt;br /&gt;
&lt;br /&gt;
* Anaemic Domain Model&lt;br /&gt;
Separating the business logic from the Domain Model is termed as Anaemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's Entity beans and .Net's three layered service application. A short example for Anaemic Model is given below,&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
Although, the above code looks right by providing segregation of data and service, its in violation of OOP principle of data and behaviour encapsulation.It could run into problems when there are muliple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
==References==&lt;br /&gt;
==External Links==&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=26738</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=26738"/>
		<updated>2009-11-13T02:56:34Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti pattern was used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system&lt;br /&gt;
*Inexperience on the part of the programmer&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
[ http://en.wikipedia.org/wiki/Anti-pattern AntiPatterns] highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
===Object-oriented design anti-patterns===&lt;br /&gt;
&lt;br /&gt;
* Anaemic Domain Model&lt;br /&gt;
Separating the business logic from the Domain Model is termed as Anaemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's Entity beans and .Net's three layered service application. A short example for Anaemic Model is given below,&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
Although, the above code looks right by providing segregation of data and service, its in violation of OOP principle of data and behaviour encapsulation.It could run into problems when there are muliple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
==References==&lt;br /&gt;
==External Links==&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=26737</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=26737"/>
		<updated>2009-11-13T02:56:19Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti pattern was used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system&lt;br /&gt;
*Inexperience on the part of the programmer&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
[ http://en.wikipedia.org/wiki/Anti-pattern|AntiPatterns] highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
===Object-oriented design anti-patterns===&lt;br /&gt;
&lt;br /&gt;
* Anaemic Domain Model&lt;br /&gt;
Separating the business logic from the Domain Model is termed as Anaemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's Entity beans and .Net's three layered service application. A short example for Anaemic Model is given below,&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
Although, the above code looks right by providing segregation of data and service, its in violation of OOP principle of data and behaviour encapsulation.It could run into problems when there are muliple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
==References==&lt;br /&gt;
==External Links==&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=26736</id>
		<title>CSC/ECE 517 Fall 2009/wiki3 1 kp</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki3_1_kp&amp;diff=26736"/>
		<updated>2009-11-13T02:55:32Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Anti-patterns= &lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
Anti-patterns is a type of design which when used may result in the code being unproductive and ineffective. It commonly describes a commonly occurring solution to a problem that may have negative consequences. There are many reasons as to why the anti pattern was used, &lt;br /&gt;
*Lack of knowledge by the programmer who coded the system&lt;br /&gt;
*Inexperience on the part of the programmer&lt;br /&gt;
*Lack of proper understanding of the functionality the system needed to provide.&lt;br /&gt;
AntiPatterns highlight the most common problems that face the software industry and provide the tools to enable you to recognize these problems and to determine their underlying causes.&lt;br /&gt;
&lt;br /&gt;
==Known classifications==&lt;br /&gt;
&lt;br /&gt;
==Software design anti-patterns==&lt;br /&gt;
===Object-oriented design anti-patterns===&lt;br /&gt;
&lt;br /&gt;
* Anaemic Domain Model&lt;br /&gt;
Separating the business logic from the Domain Model is termed as Anaemic Domain Model.One of the prime reason for it being  popular is, it provides separation of logic and data. To site few places this is used are Java's Entity beans and .Net's three layered service application. A short example for Anaemic Model is given below,&lt;br /&gt;
  class BankAccnt {&lt;br /&gt;
    private double balance;&lt;br /&gt;
    public void setBalance(double balance) {&lt;br /&gt;
    this.balance = balance;&lt;br /&gt;
  }  &lt;br /&gt;
  class AccntService {&lt;br /&gt;
    public void debit(Account account, double amount) {&lt;br /&gt;
    account.setBalance(account.getBalance() - amount);&lt;br /&gt;
   }&lt;br /&gt;
  } &lt;br /&gt;
&lt;br /&gt;
Although, the above code looks right by providing segregation of data and service, its in violation of OOP principle of data and behaviour encapsulation.It could run into problems when there are muliple type of accounts and some of them have overdraft protection, then debit method has to manually check for account type.This can be corrected by moving the behaviour (debit method) into BankAccnt Class.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
==References==&lt;br /&gt;
==External Links==&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=25617</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 11 zv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=25617"/>
		<updated>2009-10-11T01:10:29Z</updated>

		<summary type="html">&lt;p&gt;Naruto: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''What facilities does Ruby offer that makes it easier to realize other GoF (and other) patterns that we did not cover in class? The key idea here is to explore how Ruby can implement these patterns more efficiently or transparently than static (or other dynamic) o-o languages.''&lt;br /&gt;
&lt;br /&gt;
=Introduction= &lt;br /&gt;
change&lt;br /&gt;
Before starting off with design patterns for Ruby we need to define what a design pattern is, Design patterns can be described as &amp;quot;a general reusable solution to a commonly occurring problem in software design.&amp;quot; [http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29]&lt;br /&gt;
&amp;quot;The idea of design patterns is to not to reinvent the wheel but to solve the current problems by using solutions that have worked in the past&amp;quot; [http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf]. A design pattern names, abstracts, and identifies the key aspects of a common design structure that make it useful for creating a reusable object-oriented design. It helps to identify the classes and instances and the way they collaborate with each other to form a solution to a problem. Design patterns can be classified into 3 parts [http://en.wikipedia.org/wiki/Creational_pattern Creational], [http://en.wikipedia.org/wiki/Structural_pattern Structural], [http://en.wikipedia.org/wiki/Behavioral_pattern Behavioral] [http://www.patterndepot.com/put/8/JavaPatterns.htm].&lt;br /&gt;
&lt;br /&gt;
=Factory Design Pattern=&lt;br /&gt;
==What is Factory Design Pattern?==&lt;br /&gt;
The factory design pattern is an object oriented design pattern. It is a creational design pattern and deals with the issues faced in creating objects.&lt;br /&gt;
The main goal of this implementation is to isolate the code that creates the class form the concrete implementation of that class. Ruby example for the same is given below.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
The given code explains how to create a factory in Ruby. In this it initially creates a factory class called GearFactory and overrides the new function. When an object is instantiated the code does not need to know which kind of object it is. It is a collection (hence the word factory) of objects that are clubbed together.&lt;br /&gt;
    class GearFactory&lt;br /&gt;
      def new() &lt;br /&gt;
        if ( ... some condition )&lt;br /&gt;
           return Sprocket.new()&lt;br /&gt;
        else&lt;br /&gt;
           return Cog().new()&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Our client class now becomes:&lt;br /&gt;
    class GearUser &lt;br /&gt;
      def doSomething(factory )&lt;br /&gt;
        ...&lt;br /&gt;
      my_gear = factory.new()&lt;br /&gt;
        ...&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The above code does not have to distinguish between a factory and an ordinary class. We can call the class using the following code.&lt;br /&gt;
    client.doSomething(GearFactory.new)          #Use the factory&lt;br /&gt;
    client.doSomething(Cog)                      #Use the Cog class&lt;br /&gt;
    client.doSomething(Sprocket)                 #Use the Sprocket class&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
In java the Factory implementation is done using interfaces. Declaring them as interfaces helps to maintain a general overview and not depending on the type of factory object that needs to be used. All of these can be placed in a huge factory in a client application.&lt;br /&gt;
A well known example for Java Factory is the UI toolkits that are designed to run on different windowing systems.&lt;br /&gt;
    interface ScrollBar { ... }&lt;br /&gt;
    interface MenuBar   { ... }&lt;br /&gt;
    ...&lt;br /&gt;
And associated classes implementing them on different windowing systems:&lt;br /&gt;
&lt;br /&gt;
    class MotifScrollBar implements ScrollBar { ... }&lt;br /&gt;
    class Win95ScrollBar implements ScrollBar { ... }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
And a factory interface that also doesn't commit to representation:&lt;br /&gt;
&lt;br /&gt;
    interface Factory {&lt;br /&gt;
      public abstract ScrollBar newScrollBar();&lt;br /&gt;
      public abstract MenuBar   newMenuBar();&lt;br /&gt;
      ... &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
But implementation classes that do:&lt;br /&gt;
&lt;br /&gt;
    class MotifFactory implements Factory {&lt;br /&gt;
      public ScrollBar newScrollBar() { return new MotifScrollBar(...); }&lt;br /&gt;
      ...&lt;br /&gt;
    }&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
Both the languages implement the factory design pattern. Java implements the factory design pattern using the interfaces while Ruby uses classes to create a factory. An abstract base class can be defined in Java to hold all the interfaces needed or there could be a parameterised method which takes the kind of object as a parameter to instantiate the necessary object. &lt;br /&gt;
In Ruby 'new' is just a method on a class object, it's always free to return anything it likes.  The nice thing about this is that, in ruby, every call to new is, by definition, the factory pattern - it just so happens that there is a default implementation inherited by class 'Class'.&lt;br /&gt;
The factory implementation of Ruby is a lot simpler than the factory implementation of Java.&lt;br /&gt;
&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
=Abstract Factory Pattern=&lt;br /&gt;
==What is Abstract Factory Pattern?==&lt;br /&gt;
Abstract Factory Design Pattern encapsulates a group of objects that have common theme. It implements a generic interface to create these objects that are part of the theme. It does not care about the details of the implementation of these objects. The Abstract Factory pattern, a class delegates the responsibility of object instantiation to another object via composition. It is a type of Creational pattern [http://en.wikipedia.org/wiki/Abstract_factory_pattern] “Provide an interface for creating families of related or dependent objects without specifying their concrete classes” [http://sourcemaking.com/design_patterns/abstract_factory]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
Ruby automatically implements the Abstract Factory pattern as Class Objects. All Class objects have the same interface: the new method of each class object creates new instances of the class. Thus the code can pass references to class objects around and they can be used to call new method without knowing the exact type of object that the class creates.&lt;br /&gt;
&lt;br /&gt;
    Class Foo; end&lt;br /&gt;
    Class Bar, end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is the use of Abstract Factory Pattern&lt;br /&gt;
    &lt;br /&gt;
    def create_something(factory)&lt;br /&gt;
	new_object = factory.new&lt;br /&gt;
	puts &amp;quot;created a new #{new_object.class} with a factory&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Here we select a factory to use&lt;br /&gt;
    Create_something(Foo)&lt;br /&gt;
    Create_something(Bar)&lt;br /&gt;
&lt;br /&gt;
Output of the code:&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Foo with a factory&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Bar with a factory&lt;br /&gt;
&lt;br /&gt;
The create_something method is creating objects through an abstract interface. It does not have details about implementation used to create these objects. Thus the use of create_something() is used to shield the rest of the code from that knowledge.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
In Java, implementing  Abstract Factory design pattern we need to create a class which has method who defers creation of product objects to its concrete class. This class then needs to be ”extended” by the client class which uses only these interfaces to create objects of concrete class&lt;br /&gt;
[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf]. In Java, Abstract Factory defines a different method for the creation of each product it can produce. The following example shows an implementation of Abstract Factory design pattern in Java. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   public class FactoryFmProto {&lt;br /&gt;
  static class Expression {&lt;br /&gt;
   protected String str;&lt;br /&gt;
   public Expression( String s ) { str = s; }&lt;br /&gt;
   public Expression cloan()     { return null; }&lt;br /&gt;
   public String     toString()  { return str; }&lt;br /&gt;
  }&lt;br /&gt;
  static abstract class Factory {&lt;br /&gt;
   protected Expression prototype = null;&lt;br /&gt;
   public Expression makePhrase() { return prototype.cloan(); }&lt;br /&gt;
   public abstract Expression makeCompromise();&lt;br /&gt;
   public abstract Expression makeGrade();&lt;br /&gt;
  }&lt;br /&gt;
  static class PCFactory extends Factory {&lt;br /&gt;
   public PCFactory() { prototype = new PCPhrase(); }&lt;br /&gt;
   public Expression makeCompromise() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;do it your way, any way, or no way\&amp;quot;&amp;quot; ); }&lt;br /&gt;
   public Expression makeGrade() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;you pass, self-esteem intact\&amp;quot;&amp;quot; ); }&lt;br /&gt;
  }&lt;br /&gt;
   static class NotPCFactory extends Factory {&lt;br /&gt;
   public NotPCFactory() { prototype = new NotPCPhrase(); }&lt;br /&gt;
   public Expression makeCompromise() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;my way, or the highway\&amp;quot;&amp;quot; ); }&lt;br /&gt;
   public Expression makeGrade() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;take test, deal with the results\&amp;quot;&amp;quot; ); }&lt;br /&gt;
  }&lt;br /&gt;
   public static void main( String[] args ) {&lt;br /&gt;
   Factory factory;&lt;br /&gt;
   if (args.length &amp;gt; 0) factory = new PCFactory();&lt;br /&gt;
   else                 factory = new NotPCFactory();&lt;br /&gt;
   for (int i=0; i &amp;lt; 3; i++) System.out.print( factory.makePhrase() + &amp;quot;  &amp;quot; );&lt;br /&gt;
   System.out.println();&lt;br /&gt;
   System.out.println( factory.makeCompromise() );&lt;br /&gt;
   System.out.println( factory.makeGrade() );&lt;br /&gt;
  }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
Basically, Java and Ruby, both can implement Abstract Factory design pattern. But the more important point is the simplicity by which they can apply it. Ruby automatically implements the Abstract Factory pattern as Class Objects. But Java needs helps of interfaces and classes to do so. Thus Java implementation needs a well defined interface to do so but in Ruby it is directly implemented because of private class object property.&lt;br /&gt;
&lt;br /&gt;
Similarly, C# demonstrates the Abstract Factory pattern by creating parallel hierarchies of objects. Object creation has been abstracted and there is no need for hard-coded class names in the client code. This property helps C# to have better implementation than Java. In .NET, there are built in features such as, generics, reflection, object initializers, automatic properties, etc for implementation [http://www.dofactory.com/Patterns/PatternAbstract.aspx].&lt;br /&gt;
&lt;br /&gt;
=Iterator Design Pattern=&lt;br /&gt;
==What is Iterator Design Pattern?==&lt;br /&gt;
The Iterator design pattern allows an object to encapsulate the internal structure and allows the user to move through the collection of data using standard interface. It is one of the simplest and most frequently used design pattern. It is a type of Behavioral design pattern [http://en.wikipedia.org/wiki/Iterator_pattern]. “Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.” [http://sourcemaking.com/design_patterns/iterator]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
Ruby implements iterators with blocks and the ‘each’ method, and with ‘for..in’ statements. For example consider the following example;&lt;br /&gt;
&lt;br /&gt;
    def print_element(container)&lt;br /&gt;
    	Container.each {|o| puts o.inspect }&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    list = [1,2,2,3]&lt;br /&gt;
    hash = {“a”=&amp;gt;1, “b”=&amp;gt;2,”c”=&amp;gt;3, “d”=&amp;gt;4 }&lt;br /&gt;
    print_elements list&lt;br /&gt;
    print_elements hash&lt;br /&gt;
&lt;br /&gt;
The output of the code is,&lt;br /&gt;
    1&lt;br /&gt;
    2&lt;br /&gt;
    3&lt;br /&gt;
    4&lt;br /&gt;
    [“a”,1]&lt;br /&gt;
    [“b”,2]&lt;br /&gt;
    [“c”,3]&lt;br /&gt;
    [“d”,4]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
&lt;br /&gt;
In Java, we can implement Iterator design pattern by using java.util.Enumeration interface which returns a reference to an object. Furthermore, Hashes and Vector have limited capabilities which help simple traversing. Java JDK 1.2 introduced a new Collections package with more aggregate classes, including sets, lists, maps and an Iterator interface. If we wanted to start implementing Iterator design pattern from start, then it would again involve having an interface for accessing and traversing the elements which is further implemented by the concrete class.  Thus a class who needs to access the list will need to call the interface class [http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf]. For example, consider the following scenario where iterator.First() and iterator.Next(), has been implemented in the class ListIterator.&lt;br /&gt;
&lt;br /&gt;
    ...&lt;br /&gt;
    List list = new List();&lt;br /&gt;
    ...&lt;br /&gt;
    ListIterator iterator = new ListIterator(list);&lt;br /&gt;
    iterator.First();&lt;br /&gt;
    while (!iterator.IsDone()) {&lt;br /&gt;
    Object item = iterator.CurrentItem();&lt;br /&gt;
    // Code here to process item.&lt;br /&gt;
    iterator.Next();&lt;br /&gt;
    }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
&lt;br /&gt;
Overall implementation of Iterator design pattern in each object oriented language is simple as it is a basis feature of objects. But in general, the Ruby implementation is more concise. Ruby has built-in iterators which make it easier to implement Iterator pattern for any kind of object. It hides the structure and there is no need for having implementation for those methods in the class. But in Java, the built-in library function help to create easier and clear implementations. C# also has similar implementation as Java for this design pattern [http://www.dofactory.com/Patterns/PatternIterator.aspx]. &lt;br /&gt;
&lt;br /&gt;
In PHP, using an object in a foreach structure will traverse the public values. There are also many multiple Iterator classes available to allow us to iterate through common lists, such as directories, XML structures and recursive arrays. We can also implement our own interfaces depending on requirement [http://us3.php.net/manual/en/language.oop5.iterations.php].&lt;br /&gt;
&lt;br /&gt;
=Decorator Pattern=&lt;br /&gt;
&lt;br /&gt;
This pattern is used to increase the functionality of the existing object dynamically. Suppose we have a program that uses eight objects, but three of them need an additional feature. We could create derived class for these objects having the additional features but then we can create a Decorator class which will add any specific kind of feature required [http://www.patterndepot.com/put/8/Decorator.pdf]. It is a type of behavioral pattern.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
&lt;br /&gt;
Generic decorators can be implmented by using the method_missing method. This method is called when an object receives a message that it does not have a method fo. The method_missing method can forward the message on to other object and wrap additional behavior around the call. In this example we talk about how a coffee class can have many addtions to it like coffee with cream, sprinkles, milk etc and creating a class for each of them will not be the correct solution.In this example the cost can be calculated according to what is sent to it.Cost of the coffee is 2 and the cost of White coffee (coffee + milk) = 2.4. So what happens when we execute the Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost we get the result as 2.9 as the cost of the coffee is 2, the decorator object (now only coffee) is sent to the Milk and it becomes 2.4, which now is then sent to the Whip which is going to be 2.4 + 02 = 2.6 and finally to Sprinkles which becomes 2.6 + 0.3 = 2.9. The below code is an example of decorators where we just create a place holder and we can use this function to perform different functions depending on the parameters supplied to it. The need for this kind of pattern is so as to increase the functionality of a particular class [http://en.wikipedia.org/wiki/Decorator_pattern]. &lt;br /&gt;
&lt;br /&gt;
    module Decorator&lt;br /&gt;
      def initialize(decorated)&lt;br /&gt;
        @decorated = decorated&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    def method_missing(method, *args)&lt;br /&gt;
        args.empty? ? @decorated.send(method) : @decorated.send(method, args)&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
    class Whip&lt;br /&gt;
      include Decorator&lt;br /&gt;
      def cost &lt;br /&gt;
        @decorated.cost + 0.2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    class Sprinkles&lt;br /&gt;
      include Decorator&lt;br /&gt;
&lt;br /&gt;
      def cost&lt;br /&gt;
        @decorated.cost + 0.3&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    Whip.new(Coffee.new).cost&lt;br /&gt;
    #=&amp;gt; 2.2&lt;br /&gt;
    Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost &lt;br /&gt;
    #=&amp;gt; 2.9&lt;br /&gt;
&lt;br /&gt;
There are various other options to implement this design pattern. Other way to implememt the pattern is by using singleton methods and method aliases. Delegation can also be used, and it overcomes one of the most important disadvantage. We can remove add features if we are using delegation but this is not possible if we are using singleton methods and method aliases. Example for this can be found here [http://www.scribd.com/doc/2217773/Design-Patterns-in-Ruby].&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
&lt;br /&gt;
In Java, this pattern is easy to implement by dividing the various responsibilities into classes and interfaces. The below example consider all these responsibilities and have four components which are described below  &lt;br /&gt;
* Component: Defines the interface for objects that can have responsibilities added to them dynamically.&lt;br /&gt;
* ConcreteComponent: Defines an object to which additional responsibilities can be attached.&lt;br /&gt;
* Decorator: maintains a reference to a Component object and defines an interface that conforms to Component's interface.&lt;br /&gt;
* ConcreteDecorator: adds responsibilities to the component.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface IComponent {&lt;br /&gt;
    public void doStuff();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete component&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class Component implements IComponent{&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    System.out.println(&amp;quot;Do Suff&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Decorator&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface Decorator extends IComponent {&lt;br /&gt;
    public void addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete Decorator ('''Extends IComponent''')&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class ConcreteDecorator implements Decorator {&lt;br /&gt;
    IComponent component;&lt;br /&gt;
    public ConcreteDecorator(IComponent component) {&lt;br /&gt;
    super();&lt;br /&gt;
    this.component = component;&lt;br /&gt;
    }&lt;br /&gt;
    public void addedBehavior() {&lt;br /&gt;
    System.out.println(&amp;quot;Decorator does some stuff too&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    component.doStuff();&lt;br /&gt;
    addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
The Client&lt;br /&gt;
&lt;br /&gt;
    import decorator.*;&lt;br /&gt;
    public class Client {&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
    IComponent comp = new Component();&lt;br /&gt;
    Decorator decorator = new ConcreteDecorator(comp);&lt;br /&gt;
    decorator.doStuff();&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
==Comparison of implementations==&lt;br /&gt;
&lt;br /&gt;
Ruby provides different options to implement Decorator pattern like method_missing, delegation and alias methods. This provides flexibility to the user to implement any possible way depending on the requirements and features needed. But in Java, there is more clearer approach using the components provided in the example. It is a straight forward approach. But different options provided by Ruby make it much better than Java.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages like Javascript, decorator pattern can be implemented with no interfaces or traditional OOP inheritance. With simple overriding but this approach is difficult to implement [http://en.wikipedia.org/wiki/Decorator_pattern#JavaScript].&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
We have seen four design patterns Factory design pattern, Abstract Factory design pattern, Iterator design pattern and Decorator Design Pattern. We have chosen these patterns as they are widely used and Ruby has in-built implementations of these. We have mainly tried to compare Ruby and Java but also specified tips about other languages like PHP, C# and Javascript. In Ruby implementing these design patterns is simple and easy because of its main feature of private class objects, unbounded polymorphism and duck typing [http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf]. In Java all the features are mainly implemented through interfaces and classes. This has several disadvantages like increase in code complexity, size and is generally confusing and tedious to trace or understand the code.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf Design Patterns]&lt;br /&gt;
#[http://www.patterndepot.com/put/8/JavaPatterns.htm Design Patterns Java Companion James W Cooper]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 Wiki Design Patterns]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory Method]&lt;br /&gt;
#[http://sourcemaking.com/design_patterns/abstract_factory SourceMaking explains Abstract Factory]&lt;br /&gt;
#[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf Abstract Factory Example in Java]&lt;br /&gt;
#[http://www.dofactory.com/Patterns/PatternAbstract.aspx Abstract Factory explained]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Iterator_pattern Iterator Pattern]&lt;br /&gt;
#[http://sourcemaking.com/design_patterns/iterator Sourcemaking explains Iterator method]&lt;br /&gt;
#[http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf Iterator method explained]&lt;br /&gt;
#[http://www.dofactory.com/Patterns/PatternIterator.aspx DoFactory explains Iterator pattern]&lt;br /&gt;
#[http://us3.php.net/manual/en/language.oop5.iterations.php Iterator pattern for PHP]&lt;br /&gt;
#[http://www.patterndepot.com/put/8/Decorator.pdf Decorator Pattern]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Decorator_pattern Wiki Decorator Pattern]&lt;br /&gt;
#[http://www.scribd.com/doc/2217773/Design-Patterns-in-Ruby Design Patterns in Ruby]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Decorator_pattern#JavaScript Design Patterns Javascript]&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=23287</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 11 zv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=23287"/>
		<updated>2009-10-09T00:41:05Z</updated>

		<summary type="html">&lt;p&gt;Naruto: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''What facilities does Ruby offer that makes it easier to realize other GoF (and other) patterns that we did not cover in class? The key idea here is to explore how Ruby can implement these patterns more efficiently or transparently than static (or other dynamic) o-o languages.''&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Before starting off with design patterns for Ruby we need to define what a design pattern is, Design patterns can be described as &amp;quot;a general reusable solution to a commonly occurring problem in software design.&amp;quot; [http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29]&lt;br /&gt;
&amp;quot;The idea of design patterns is to not to reinvent the wheel but to solve the current problems by using solutions that have worked in the past&amp;quot; [http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf]. A design pattern names, abstracts, and identifies the key aspects of a common design structure that make it useful for creating a reusable object-oriented design. It helps to identify the classes and instances and the way they collaborate with each other to form a solution to a problem. Design patterns can be classified into 3 parts [http://en.wikipedia.org/wiki/Creational_pattern Creational], [http://en.wikipedia.org/wiki/Structural_pattern Structural], [http://en.wikipedia.org/wiki/Behavioral_pattern Behavioral] [http://www.patterndepot.com/put/8/JavaPatterns.htm].&lt;br /&gt;
&lt;br /&gt;
=Factory Design Pattern=&lt;br /&gt;
==What is Factory Design Pattern?==&lt;br /&gt;
The factory design pattern is an object oriented design pattern. It is a creational design pattern and deals with the issues faced in creating objects.&lt;br /&gt;
The main goal of this implementation is to isolate the code that creates the class form the concrete implementation of that class. Ruby example for the same is given below.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
The given code explains how to create a factory in Ruby. In this it initially creates a factory class called GearFactory and overrides the new function. When an object is instantiated the code does not need to know which kind of object it is. It is a collection (hence the word factory) of objects that are clubbed together.&lt;br /&gt;
    class GearFactory&lt;br /&gt;
      def new() &lt;br /&gt;
        if ( ... some condition )&lt;br /&gt;
           return Sprocket.new()&lt;br /&gt;
        else&lt;br /&gt;
           return Cog().new()&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Our client class now becomes:&lt;br /&gt;
    class GearUser &lt;br /&gt;
      def doSomething(factory )&lt;br /&gt;
        ...&lt;br /&gt;
      my_gear = factory.new()&lt;br /&gt;
        ...&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The above code does not have to distinguish between a factory and an ordinary class. We can call the class using the following code.&lt;br /&gt;
    client.doSomething(GearFactory.new)          #Use the factory&lt;br /&gt;
    client.doSomething(Cog)                      #Use the Cog class&lt;br /&gt;
    client.doSomething(Sprocket)                 #Use the Sprocket class&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
In java the Factory implementation is done using interfaces. Declaring them as interfaces helps to maintain a general overview and not depending on the type of factory object that needs to be used. All of these can be placed in a huge factory in a client application.&lt;br /&gt;
A well known example for Java Factory is the UI toolkits that are designed to run on different windowing systems.&lt;br /&gt;
    interface ScrollBar { ... }&lt;br /&gt;
    interface MenuBar   { ... }&lt;br /&gt;
    ...&lt;br /&gt;
And associated classes implementing them on different windowing systems:&lt;br /&gt;
&lt;br /&gt;
    class MotifScrollBar implements ScrollBar { ... }&lt;br /&gt;
    class Win95ScrollBar implements ScrollBar { ... }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
And a factory interface that also doesn't commit to representation:&lt;br /&gt;
&lt;br /&gt;
    interface Factory {&lt;br /&gt;
      public abstract ScrollBar newScrollBar();&lt;br /&gt;
      public abstract MenuBar   newMenuBar();&lt;br /&gt;
      ... &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
But implementation classes that do:&lt;br /&gt;
&lt;br /&gt;
    class MotifFactory implements Factory {&lt;br /&gt;
      public ScrollBar newScrollBar() { return new MotifScrollBar(...); }&lt;br /&gt;
      ...&lt;br /&gt;
    }&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
Both the languages implement the factory design pattern. Java implements the factory design pattern using the interfaces while Ruby uses classes to create a factory. An abstract base class can be defined in Java to hold all the interfaces needed or there could be a parameterised method which takes the kind of object as a parameter to instantiate the necessary object. &lt;br /&gt;
In Ruby 'new' is just a method on a class object, it's always free to return anything it likes.  The nice thing about this is that, in ruby, every call to new is, by definition, the factory pattern - it just so happens that there is a default implementation inherited by class 'Class'.&lt;br /&gt;
The factory implementation of Ruby is a lot simpler than the factory implementation of Java.&lt;br /&gt;
&lt;br /&gt;
  &lt;br /&gt;
&lt;br /&gt;
=Abstract Factory Pattern=&lt;br /&gt;
==What is Abstract Factory Pattern?==&lt;br /&gt;
Abstract Factory Design Pattern encapsulates a group of objects that have common theme. It implements a generic interface to create these objects that are part of the theme. It does not care about the details of the implementation of these objects. The Abstract Factory pattern, a class delegates the responsibility of object instantiation to another object via composition. It is a type of Creational pattern [http://en.wikipedia.org/wiki/Abstract_factory_pattern] “Provide an interface for creating families of related or dependent objects without specifying their concrete classes” [http://sourcemaking.com/design_patterns/abstract_factory]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
Ruby automatically implements the Abstract Factory pattern as Class Objects. All Class objects have the same interface: the new method of each class object creates new instances of the class. Thus the code can pass references to class objects around and they can be used to call new method without knowing the exact type of object that the class creates.&lt;br /&gt;
&lt;br /&gt;
    Class Foo; end&lt;br /&gt;
    Class Bar, end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is the use of Abstract Factory Pattern&lt;br /&gt;
    &lt;br /&gt;
    def create_something(factory)&lt;br /&gt;
	new_object = factory.new&lt;br /&gt;
	puts &amp;quot;created a new #{new_object.class} with a factory&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Here we select a factory to use&lt;br /&gt;
    Create_something(Foo)&lt;br /&gt;
    Create_something(Bar)&lt;br /&gt;
&lt;br /&gt;
Output of the code:&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Foo with a factory&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Bar with a factory&lt;br /&gt;
&lt;br /&gt;
The create_something method is creating objects through an abstract interface. It does not have details about implementation used to create these objects. Thus the use of create_something() is used to shield the rest of the code from that knowledge.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
In Java, implementing  Abstract Factory design pattern we need to create a class which has method who defers creation of product objects to its concrete class. This class then needs to be ”extended” by the client class which uses only these interfaces to create objects of concrete class&lt;br /&gt;
[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf]. In Java, Abstract Factory defines a different method for the creation of each product it can produce. The following example shows an implementation of Abstract Factory design pattern in Java. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   public class FactoryFmProto {&lt;br /&gt;
  static class Expression {&lt;br /&gt;
   protected String str;&lt;br /&gt;
   public Expression( String s ) { str = s; }&lt;br /&gt;
   public Expression cloan()     { return null; }&lt;br /&gt;
   public String     toString()  { return str; }&lt;br /&gt;
  }&lt;br /&gt;
  static abstract class Factory {&lt;br /&gt;
   protected Expression prototype = null;&lt;br /&gt;
   public Expression makePhrase() { return prototype.cloan(); }&lt;br /&gt;
   public abstract Expression makeCompromise();&lt;br /&gt;
   public abstract Expression makeGrade();&lt;br /&gt;
  }&lt;br /&gt;
  static class PCFactory extends Factory {&lt;br /&gt;
   public PCFactory() { prototype = new PCPhrase(); }&lt;br /&gt;
   public Expression makeCompromise() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;do it your way, any way, or no way\&amp;quot;&amp;quot; ); }&lt;br /&gt;
   public Expression makeGrade() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;you pass, self-esteem intact\&amp;quot;&amp;quot; ); }&lt;br /&gt;
  }&lt;br /&gt;
   static class NotPCFactory extends Factory {&lt;br /&gt;
   public NotPCFactory() { prototype = new NotPCPhrase(); }&lt;br /&gt;
   public Expression makeCompromise() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;my way, or the highway\&amp;quot;&amp;quot; ); }&lt;br /&gt;
   public Expression makeGrade() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;take test, deal with the results\&amp;quot;&amp;quot; ); }&lt;br /&gt;
  }&lt;br /&gt;
   public static void main( String[] args ) {&lt;br /&gt;
   Factory factory;&lt;br /&gt;
   if (args.length &amp;gt; 0) factory = new PCFactory();&lt;br /&gt;
   else                 factory = new NotPCFactory();&lt;br /&gt;
   for (int i=0; i &amp;lt; 3; i++) System.out.print( factory.makePhrase() + &amp;quot;  &amp;quot; );&lt;br /&gt;
   System.out.println();&lt;br /&gt;
   System.out.println( factory.makeCompromise() );&lt;br /&gt;
   System.out.println( factory.makeGrade() );&lt;br /&gt;
  }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
Basically, Java and Ruby, both can implement Abstract Factory design pattern. But the more important point is the simplicity by which they can apply it. Ruby automatically implements the Abstract Factory pattern as Class Objects. But Java needs helps of interfaces and classes to do so. Thus Java implementation needs a well defined interface to do so but in Ruby it is directly implemented because of private class object property.&lt;br /&gt;
&lt;br /&gt;
Similarly, C# demonstrates the Abstract Factory pattern by creating parallel hierarchies of objects. Object creation has been abstracted and there is no need for hard-coded class names in the client code. This property helps C# to have better implementation than Java. In .NET, there are built in features such as, generics, reflection, object initializers, automatic properties, etc for implementation [http://www.dofactory.com/Patterns/PatternAbstract.aspx].&lt;br /&gt;
&lt;br /&gt;
=Iterator Design Pattern=&lt;br /&gt;
==What is Iterator Design Pattern?==&lt;br /&gt;
The Iterator design pattern allows an object to encapsulate the internal structure and allows the user to move through the collection of data using standard interface. It is one of the simplest and most frequently used design pattern. It is a type of Behavioral design pattern [http://en.wikipedia.org/wiki/Iterator_pattern]. “Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.” [http://sourcemaking.com/design_patterns/iterator]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
Ruby implements iterators with blocks and the ‘each’ method, and with ‘for..in’ statements. For example consider the following example;&lt;br /&gt;
&lt;br /&gt;
    def print_element(container)&lt;br /&gt;
    	Container.each {|o| puts o.inspect }&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    list = [1,2,2,3]&lt;br /&gt;
    hash = {“a”=&amp;gt;1, “b”=&amp;gt;2,”c”=&amp;gt;3, “d”=&amp;gt;4 }&lt;br /&gt;
    print_elements list&lt;br /&gt;
    print_elements hash&lt;br /&gt;
&lt;br /&gt;
The output of the code is,&lt;br /&gt;
    1&lt;br /&gt;
    2&lt;br /&gt;
    3&lt;br /&gt;
    4&lt;br /&gt;
    [“a”,1]&lt;br /&gt;
    [“b”,2]&lt;br /&gt;
    [“c”,3]&lt;br /&gt;
    [“d”,4]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
&lt;br /&gt;
In Java, we can implement Iterator design pattern by using java.util.Enumeration interface which returns a reference to an object. Furthermore, Hashes and Vector have limited capabilities which help simple traversing. Java JDK 1.2 introduced a new Collections package with more aggregate classes, including sets, lists, maps and an Iterator interface. If we wanted to start implementing Iterator design pattern from start, then it would again involve having an interface for accessing and traversing the elements which is further implemented by the concrete class.  Thus a class who needs to access the list will need to call the interface class [http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf]. For example, consider the following scenario where iterator.First() and iterator.Next(), has been implemented in the class ListIterator.&lt;br /&gt;
&lt;br /&gt;
    ...&lt;br /&gt;
    List list = new List();&lt;br /&gt;
    ...&lt;br /&gt;
    ListIterator iterator = new ListIterator(list);&lt;br /&gt;
    iterator.First();&lt;br /&gt;
    while (!iterator.IsDone()) {&lt;br /&gt;
    Object item = iterator.CurrentItem();&lt;br /&gt;
    // Code here to process item.&lt;br /&gt;
    iterator.Next();&lt;br /&gt;
    }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
&lt;br /&gt;
Overall implementation of Iterator design pattern in each object oriented language is simple as it is a basis feature of objects. But in general, the Ruby implementation is more concise. Ruby has built-in iterators which make it easier to implement Iterator pattern for any kind of object. It hides the structure and there is no need for having implementation for those methods in the class. But in Java, the built-in library function help to create easier and clear implementations. C# also has similar implementation as Java for this design pattern [http://www.dofactory.com/Patterns/PatternIterator.aspx]. &lt;br /&gt;
&lt;br /&gt;
In PHP, using an object in a foreach structure will traverse the public values. There are also many multiple Iterator classes available to allow us to iterate through common lists, such as directories, XML structures and recursive arrays. We can also implement our own interfaces depending on requirement [http://us3.php.net/manual/en/language.oop5.iterations.php].&lt;br /&gt;
&lt;br /&gt;
=Decorator Pattern=&lt;br /&gt;
&lt;br /&gt;
This pattern is used to increase the functionality of the existing object dynamically. Suppose we have a program that uses eight objects, but three of them need an additional feature. We could create derived class for these objects having the additional features but then we can create a Decorator class which will add any specific kind of feature required [http://www.patterndepot.com/put/8/Decorator.pdf]. It is a type of behavioral pattern.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
&lt;br /&gt;
Generic decorators can be implmented by using the method_missing method. This method is called when an object receives a message that it does not have a method fo. The method_missing method can forward the message on to other object and wrap additional behavior around the call. In this example we talk about how a coffee class can have many addtions to it like coffee with cream, sprinkles, milk etc and creating a class for each of them will not be the correct solution.In this example the cost can be calculated according to what is sent to it.Cost of the coffee is 2 and the cost of White coffee (coffee + milk) = 2.4. So what happens when we execute the Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost we get the result as 2.9 as the cost of the coffee is 2, the decorator object (now only coffee) is sent to the Milk and it becomes 2.4, which now is then sent to the Whip which is going to be 2.4 + 02 = 2.6 and finally to Sprinkles which becomes 2.6 + 0.3 = 2.9. The below code is an example of decorators where we just create a place holder and we can use this function to perform different functions depending on the parameters supplied to it. The need for this kind of pattern is so as to increase the functionality of a particular class [http://en.wikipedia.org/wiki/Decorator_pattern]. &lt;br /&gt;
&lt;br /&gt;
    module Decorator&lt;br /&gt;
      def initialize(decorated)&lt;br /&gt;
        @decorated = decorated&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    def method_missing(method, *args)&lt;br /&gt;
        args.empty? ? @decorated.send(method) : @decorated.send(method, args)&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
    class Whip&lt;br /&gt;
      include Decorator&lt;br /&gt;
      def cost &lt;br /&gt;
        @decorated.cost + 0.2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    class Sprinkles&lt;br /&gt;
      include Decorator&lt;br /&gt;
&lt;br /&gt;
      def cost&lt;br /&gt;
        @decorated.cost + 0.3&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    Whip.new(Coffee.new).cost&lt;br /&gt;
    #=&amp;gt; 2.2&lt;br /&gt;
    Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost &lt;br /&gt;
    #=&amp;gt; 2.9&lt;br /&gt;
&lt;br /&gt;
There are various other options to implement this design pattern. Other way to implememt the pattern is by using singleton methods and method aliases. Delegation can also be used, and it overcomes one of the most important disadvantage. We can remove add features if we are using delegation but this is not possible if we are using singleton methods and method aliases. Example for this can be found here [http://www.scribd.com/doc/2217773/Design-Patterns-in-Ruby].&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
&lt;br /&gt;
In Java, this pattern is easy to implement by dividing the various responsibilities into classes and interfaces. The below example consider all these responsibilities and have four components which are described below  &lt;br /&gt;
* Component: Defines the interface for objects that can have responsibilities added to them dynamically.&lt;br /&gt;
* ConcreteComponent: Defines an object to which additional responsibilities can be attached.&lt;br /&gt;
* Decorator: maintains a reference to a Component object and defines an interface that conforms to Component's interface.&lt;br /&gt;
* ConcreteDecorator: adds responsibilities to the component.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface IComponent {&lt;br /&gt;
    public void doStuff();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete component&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class Component implements IComponent{&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    System.out.println(&amp;quot;Do Suff&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Decorator&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface Decorator extends IComponent {&lt;br /&gt;
    public void addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete Decorator ('''Extends IComponent''')&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class ConcreteDecorator implements Decorator {&lt;br /&gt;
    IComponent component;&lt;br /&gt;
    public ConcreteDecorator(IComponent component) {&lt;br /&gt;
    super();&lt;br /&gt;
    this.component = component;&lt;br /&gt;
    }&lt;br /&gt;
    public void addedBehavior() {&lt;br /&gt;
    System.out.println(&amp;quot;Decorator does some stuff too&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    component.doStuff();&lt;br /&gt;
    addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
The Client&lt;br /&gt;
&lt;br /&gt;
    import decorator.*;&lt;br /&gt;
    public class Client {&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
    IComponent comp = new Component();&lt;br /&gt;
    Decorator decorator = new ConcreteDecorator(comp);&lt;br /&gt;
    decorator.doStuff();&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
==Comparison of implementations==&lt;br /&gt;
&lt;br /&gt;
Ruby provides different options to implement Decorator pattern like method_missing, delegation and alias methods. This provides flexibility to the user to implement any possible way depending on the requirements and features needed. But in Java, there is more clearer approach using the components provided in the example. It is a straight forward approach. But different options provided by Ruby make it much better than Java.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages like Javascript, decorator pattern can be implemented with no interfaces or traditional OOP inheritance. With simple overriding but this approach is difficult to implement [http://en.wikipedia.org/wiki/Decorator_pattern#JavaScript].&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
We have seen four design patterns Factory design pattern, Abstract Factory design pattern, Iterator design pattern and Decorator Design Pattern. We have chosen these patterns as they are widely used and Ruby has in-built implementations of these. We have mainly tried to compare Ruby and Java but also specified tips about other languages like PHP, C# and Javascript. In Ruby implementing these design patterns is simple and easy because of its main feature of private class objects, unbounded polymorphism and duck typing [http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf]. In Java all the features are mainly implemented through interfaces and classes. This has several disadvantages like increase in code complexity, size and is generally confusing and tedious to trace or understand the code.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf Design Patterns]&lt;br /&gt;
#[http://www.patterndepot.com/put/8/JavaPatterns.htm Design Patterns Java Companion James W Cooper]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 Wiki Design Patterns]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory Method]&lt;br /&gt;
#[http://sourcemaking.com/design_patterns/abstract_factory SourceMaking explains Abstract Factory]&lt;br /&gt;
#[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf Abstract Factory Example in Java]&lt;br /&gt;
#[http://www.dofactory.com/Patterns/PatternAbstract.aspx Abstract Factory explained]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Iterator_pattern Iterator Pattern]&lt;br /&gt;
#[http://sourcemaking.com/design_patterns/iterator Sourcemaking explains Iterator method]&lt;br /&gt;
#[http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf Iterator method explained]&lt;br /&gt;
#[http://www.dofactory.com/Patterns/PatternIterator.aspx DoFactory explains Iterator pattern]&lt;br /&gt;
#[http://us3.php.net/manual/en/language.oop5.iterations.php Iterator pattern for PHP]&lt;br /&gt;
#[http://www.patterndepot.com/put/8/Decorator.pdf Decorator Pattern]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Decorator_pattern Wiki Decorator Pattern]&lt;br /&gt;
#[http://www.scribd.com/doc/2217773/Design-Patterns-in-Ruby Design Patterns in Ruby]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Decorator_pattern#JavaScript Design Patterns Javascript]&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=23283</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 11 zv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=23283"/>
		<updated>2009-10-09T00:29:57Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Implementation in Ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''What facilities does Ruby offer that makes it easier to realize other GoF (and other) patterns that we did not cover in class? The key idea here is to explore how Ruby can implement these patterns more efficiently or transparently than static (or other dynamic) o-o languages.''&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Before starting off with design patterns for Ruby we need to define what a design pattern is, Design patterns can be described as &amp;quot;a general reusable solution to a commonly occurring problem in software design.&amp;quot; [http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29]&lt;br /&gt;
&amp;quot;The idea of design patterns is to not to reinvent the wheel but to solve the current problems by using solutions that have worked in the past&amp;quot; [http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf]. A design pattern names, abstracts, and identifies the key aspects of a common design structure that make it useful for creating a reusable object-oriented design. It helps to identify the classes and instances and the way they collaborate with each other to form a solution to a problem. Design patterns can be classified into 3 parts [http://en.wikipedia.org/wiki/Creational_pattern Creational], [http://en.wikipedia.org/wiki/Structural_pattern Structural], [http://en.wikipedia.org/wiki/Behavioral_pattern Behavioral] [http://www.patterndepot.com/put/8/JavaPatterns.htm].&lt;br /&gt;
&lt;br /&gt;
=Factory Design Pattern=&lt;br /&gt;
==What is Factory Design Pattern?==&lt;br /&gt;
The factory design pattern is an object oriented design pattern. It is a creational design pattern and deals with the issues faced in creating objects.&lt;br /&gt;
The main goal of this implementation is to isolate the code that creates the class form the concrete implementation of that class. Ruby example for the same is given below.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
The given code explains how to create a factory in Ruby. In this it initially creates a factory class called GearFactory and overrides the new function. When an object is instantiated the code does not need to know which kind of object it is. It is a collection (hence the word factory) of objects that are clubbed together.&lt;br /&gt;
    class GearFactory&lt;br /&gt;
      def new() &lt;br /&gt;
        if ( ... some condition )&lt;br /&gt;
           return Sprocket.new()&lt;br /&gt;
        else&lt;br /&gt;
           return Cog().new()&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Our client class now becomes:&lt;br /&gt;
    class GearUser &lt;br /&gt;
      def doSomething(factory )&lt;br /&gt;
        ...&lt;br /&gt;
      my_gear = factory.new()&lt;br /&gt;
        ...&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The above code does not have to distinguish between a factory and an ordinary class. We can call the class using the following code.&lt;br /&gt;
    client.doSomething(GearFactory.new)          #Use the factory&lt;br /&gt;
    client.doSomething(Cog)                      #Use the Cog class&lt;br /&gt;
    client.doSomething(Sprocket)                 #Use the Sprocket class&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
In java the Factory implementation is done using interfaces. Declaring them as interfaces helps to maintain a general overview and not depending on the type of factory object that needs to be used. All of these can be placed in a huge factory in a client application.&lt;br /&gt;
A well known example for Java Factory is the UI toolkits that are designed to run on different windowing systems.&lt;br /&gt;
    interface ScrollBar { ... }&lt;br /&gt;
    interface MenuBar   { ... }&lt;br /&gt;
    ...&lt;br /&gt;
And associated classes implementing them on different windowing systems:&lt;br /&gt;
&lt;br /&gt;
    class MotifScrollBar implements ScrollBar { ... }&lt;br /&gt;
    class Win95ScrollBar implements ScrollBar { ... }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
And a factory interface that also doesn't commit to representation:&lt;br /&gt;
&lt;br /&gt;
    interface Factory {&lt;br /&gt;
      public abstract ScrollBar newScrollBar();&lt;br /&gt;
      public abstract MenuBar   newMenuBar();&lt;br /&gt;
      ... &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
But implementation classes that do:&lt;br /&gt;
&lt;br /&gt;
    class MotifFactory implements Factory {&lt;br /&gt;
      public ScrollBar newScrollBar() { return new MotifScrollBar(...); }&lt;br /&gt;
      ...&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory Pattern=&lt;br /&gt;
==What is Abstract Factory Pattern?==&lt;br /&gt;
Abstract Factory Design Pattern encapsulates a group of objects that have common theme. It implements a generic interface to create these objects that are part of the theme. It does not care about the details of the implementation of these objects. The Abstract Factory pattern, a class delegates the responsibility of object instantiation to another object via composition. It is a type of Creational pattern [http://en.wikipedia.org/wiki/Abstract_factory_pattern] “Provide an interface for creating families of related or dependent objects without specifying their concrete classes” [http://sourcemaking.com/design_patterns/abstract_factory]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
Ruby automatically implements the Abstract Factory pattern as Class Objects. All Class objects have the same interface: the new method of each class object creates new instances of the class. Thus the code can pass references to class objects around and they can be used to call new method without knowing the exact type of object that the class creates.&lt;br /&gt;
&lt;br /&gt;
    Class Foo; end&lt;br /&gt;
    Class Bar, end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is the use of Abstract Factory Pattern&lt;br /&gt;
    &lt;br /&gt;
    def create_something(factory)&lt;br /&gt;
	new_object = factory.new&lt;br /&gt;
	puts &amp;quot;created a new #{new_object.class} with a factory&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Here we select a factory to use&lt;br /&gt;
    Create_something(Foo)&lt;br /&gt;
    Create_something(Bar)&lt;br /&gt;
&lt;br /&gt;
Output of the code:&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Foo with a factory&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Bar with a factory&lt;br /&gt;
&lt;br /&gt;
The create_something method is creating objects through an abstract interface. It does not have details about implementation used to create these objects. Thus the use of create_something() is used to shield the rest of the code from that knowledge.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
In Java, implementing  Abstract Factory design pattern we need to create a class which has method who defers creation of product objects to its concrete class. This class then needs to be ”extended” by the client class which uses only these interfaces to create objects of concrete class&lt;br /&gt;
[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf]. In Java, Abstract Factory defines a different method for the creation of each product it can produce. The following example shows an implementation of Abstract Factory design pattern in Java. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   public class FactoryFmProto {&lt;br /&gt;
  static class Expression {&lt;br /&gt;
   protected String str;&lt;br /&gt;
   public Expression( String s ) { str = s; }&lt;br /&gt;
   public Expression cloan()     { return null; }&lt;br /&gt;
   public String     toString()  { return str; }&lt;br /&gt;
  }&lt;br /&gt;
  static abstract class Factory {&lt;br /&gt;
   protected Expression prototype = null;&lt;br /&gt;
   public Expression makePhrase() { return prototype.cloan(); }&lt;br /&gt;
   public abstract Expression makeCompromise();&lt;br /&gt;
   public abstract Expression makeGrade();&lt;br /&gt;
  }&lt;br /&gt;
  static class PCFactory extends Factory {&lt;br /&gt;
   public PCFactory() { prototype = new PCPhrase(); }&lt;br /&gt;
   public Expression makeCompromise() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;do it your way, any way, or no way\&amp;quot;&amp;quot; ); }&lt;br /&gt;
   public Expression makeGrade() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;you pass, self-esteem intact\&amp;quot;&amp;quot; ); }&lt;br /&gt;
  }&lt;br /&gt;
   static class NotPCFactory extends Factory {&lt;br /&gt;
   public NotPCFactory() { prototype = new NotPCPhrase(); }&lt;br /&gt;
   public Expression makeCompromise() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;my way, or the highway\&amp;quot;&amp;quot; ); }&lt;br /&gt;
   public Expression makeGrade() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;take test, deal with the results\&amp;quot;&amp;quot; ); }&lt;br /&gt;
  }&lt;br /&gt;
   public static void main( String[] args ) {&lt;br /&gt;
   Factory factory;&lt;br /&gt;
   if (args.length &amp;gt; 0) factory = new PCFactory();&lt;br /&gt;
   else                 factory = new NotPCFactory();&lt;br /&gt;
   for (int i=0; i &amp;lt; 3; i++) System.out.print( factory.makePhrase() + &amp;quot;  &amp;quot; );&lt;br /&gt;
   System.out.println();&lt;br /&gt;
   System.out.println( factory.makeCompromise() );&lt;br /&gt;
   System.out.println( factory.makeGrade() );&lt;br /&gt;
  }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
Basically, Java and Ruby, both can implement Abstract Factory design pattern. But the more important point is the simplicity by which they can apply it. Ruby automatically implements the Abstract Factory pattern as Class Objects. But Java needs helps of interfaces and classes to do so. Thus Java implementation needs a well defined interface to do so but in Ruby it is directly implemented because of private class object property.&lt;br /&gt;
&lt;br /&gt;
Similarly, C# demonstrates the Abstract Factory pattern by creating parallel hierarchies of objects. Object creation has been abstracted and there is no need for hard-coded class names in the client code. This property helps C# to have better implementation than Java. In .NET, there are built in features such as, generics, reflection, object initializers, automatic properties, etc for implementation [http://www.dofactory.com/Patterns/PatternAbstract.aspx].&lt;br /&gt;
&lt;br /&gt;
=Iterator Design Pattern=&lt;br /&gt;
==What is Iterator Design Pattern?==&lt;br /&gt;
The Iterator design pattern allows an object to encapsulate the internal structure and allows the user to move through the collection of data using standard interface. It is one of the simplest and most frequently used design pattern. It is a type of Behavioral design pattern [http://en.wikipedia.org/wiki/Iterator_pattern]. “Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.” [http://sourcemaking.com/design_patterns/iterator]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
Ruby implements iterators with blocks and the ‘each’ method, and with ‘for..in’ statements. For example consider the following example;&lt;br /&gt;
&lt;br /&gt;
    def print_element(container)&lt;br /&gt;
    	Container.each {|o| puts o.inspect }&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    list = [1,2,2,3]&lt;br /&gt;
    hash = {“a”=&amp;gt;1, “b”=&amp;gt;2,”c”=&amp;gt;3, “d”=&amp;gt;4 }&lt;br /&gt;
    print_elements list&lt;br /&gt;
    print_elements hash&lt;br /&gt;
&lt;br /&gt;
The output of the code is,&lt;br /&gt;
    1&lt;br /&gt;
    2&lt;br /&gt;
    3&lt;br /&gt;
    4&lt;br /&gt;
    [“a”,1]&lt;br /&gt;
    [“b”,2]&lt;br /&gt;
    [“c”,3]&lt;br /&gt;
    [“d”,4]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
&lt;br /&gt;
In Java, we can implement Iterator design pattern by using java.util.Enumeration interface which returns a reference to an object. Furthermore, Hashes and Vector have limited capabilities which help simple traversing. Java JDK 1.2 introduced a new Collections package with more aggregate classes, including sets, lists, maps and an Iterator interface. If we wanted to start implementing Iterator design pattern from start, then it would again involve having an interface for accessing and traversing the elements which is further implemented by the concrete class.  Thus a class who needs to access the list will need to call the interface class [http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf]. For example, consider the following scenario where iterator.First() and iterator.Next(), has been implemented in the class ListIterator.&lt;br /&gt;
&lt;br /&gt;
    ...&lt;br /&gt;
    List list = new List();&lt;br /&gt;
    ...&lt;br /&gt;
    ListIterator iterator = new ListIterator(list);&lt;br /&gt;
    iterator.First();&lt;br /&gt;
    while (!iterator.IsDone()) {&lt;br /&gt;
    Object item = iterator.CurrentItem();&lt;br /&gt;
    // Code here to process item.&lt;br /&gt;
    iterator.Next();&lt;br /&gt;
    }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
&lt;br /&gt;
Overall implementation of Iterator design pattern in each object oriented language is simple as it is a basis feature of objects. But in general, the Ruby implementation is more concise. Ruby has built-in iterators which make it easier to implement Iterator pattern for any kind of object. It hides the structure and there is no need for having implementation for those methods in the class. But in Java, the built-in library function help to create easier and clear implementations. C# also has similar implementation as Java for this design pattern [http://www.dofactory.com/Patterns/PatternIterator.aspx]. &lt;br /&gt;
&lt;br /&gt;
In PHP, using an object in a foreach structure will traverse the public values. There are also many multiple Iterator classes available to allow us to iterate through common lists, such as directories, XML structures and recursive arrays. We can also implement our own interfaces depending on requirement [http://us3.php.net/manual/en/language.oop5.iterations.php].&lt;br /&gt;
&lt;br /&gt;
=Decorator Pattern=&lt;br /&gt;
&lt;br /&gt;
This pattern is used to increase the functionality of the existing object dynamically. Suppose we have a program that uses eight objects, but three of them need an additional feature. We could create derived class for these objects having the additional features but then we can create a Decorator class which will add any specific kind of feature required [http://www.patterndepot.com/put/8/Decorator.pdf]. It is a type of behavioral pattern.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
&lt;br /&gt;
Generic decorators can be implmented by using the method_missing method. This method is called when an object receives a message that it does not have a method fo. The method_missing method can forward the message on to other object and wrap additional behavior around the call. In this example we talk about how a coffee class can have many addtions to it like coffee with cream, sprinkles, milk etc and creating a class for each of them will not be the correct solution.In this example the cost can be calculated according to what is sent to it.Cost of the coffee is 2 and the cost of White coffee (coffee + milk) = 2.4. So what happens when we execute the Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost we get the result as 2.9 as the cost of the coffee is 2, the decorator object (now only coffee) is sent to the Milk and it becomes 2.4, which now is then sent to the Whip which is going to be 2.4 + 02 = 2.6 and finally to Sprinkles which becomes 2.6 + 0.3 = 2.9. The below code is an example of decorators where we just create a place holder and we can use this function to perform different functions depending on the parameters supplied to it. The need for this kind of pattern is so as to increase the functionality of a particular class [http://en.wikipedia.org/wiki/Decorator_pattern]. &lt;br /&gt;
&lt;br /&gt;
    module Decorator&lt;br /&gt;
      def initialize(decorated)&lt;br /&gt;
        @decorated = decorated&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    def method_missing(method, *args)&lt;br /&gt;
        args.empty? ? @decorated.send(method) : @decorated.send(method, args)&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
    class Whip&lt;br /&gt;
      include Decorator&lt;br /&gt;
      def cost &lt;br /&gt;
        @decorated.cost + 0.2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    class Sprinkles&lt;br /&gt;
      include Decorator&lt;br /&gt;
&lt;br /&gt;
      def cost&lt;br /&gt;
        @decorated.cost + 0.3&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    Whip.new(Coffee.new).cost&lt;br /&gt;
    #=&amp;gt; 2.2&lt;br /&gt;
    Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost &lt;br /&gt;
    #=&amp;gt; 2.9&lt;br /&gt;
&lt;br /&gt;
There are various other options to implement this design pattern. Other way to implememt the pattern is by using singleton methods and method aliases. Delegation can also be used, and it overcomes one of the most important disadvantage. We can remove add features if we are using delegation but this is not possible if we are using singleton methods and method aliases. Example for this can be found here [http://www.scribd.com/doc/2217773/Design-Patterns-in-Ruby].&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
&lt;br /&gt;
In Java, this pattern is easy to implement by dividing the various responsibilities into classes and interfaces. The below example consider all these responsibilities and have four components which are described below  &lt;br /&gt;
* Component: Defines the interface for objects that can have responsibilities added to them dynamically.&lt;br /&gt;
* ConcreteComponent: Defines an object to which additional responsibilities can be attached.&lt;br /&gt;
* Decorator: maintains a reference to a Component object and defines an interface that conforms to Component's interface.&lt;br /&gt;
* ConcreteDecorator: adds responsibilities to the component.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface IComponent {&lt;br /&gt;
    public void doStuff();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete component&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class Component implements IComponent{&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    System.out.println(&amp;quot;Do Suff&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Decorator&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface Decorator extends IComponent {&lt;br /&gt;
    public void addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete Decorator ('''Extends IComponent''')&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class ConcreteDecorator implements Decorator {&lt;br /&gt;
    IComponent component;&lt;br /&gt;
    public ConcreteDecorator(IComponent component) {&lt;br /&gt;
    super();&lt;br /&gt;
    this.component = component;&lt;br /&gt;
    }&lt;br /&gt;
    public void addedBehavior() {&lt;br /&gt;
    System.out.println(&amp;quot;Decorator does some stuff too&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    component.doStuff();&lt;br /&gt;
    addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
The Client&lt;br /&gt;
&lt;br /&gt;
    import decorator.*;&lt;br /&gt;
    public class Client {&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
    IComponent comp = new Component();&lt;br /&gt;
    Decorator decorator = new ConcreteDecorator(comp);&lt;br /&gt;
    decorator.doStuff();&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
==Comparison of implementations==&lt;br /&gt;
&lt;br /&gt;
Ruby provides different options to implement Decorator pattern like method_missing, delegation and alias methods. This provides flexibility to the user to implement any possible way depending on the requirements and features needed. But in Java, there is more clearer approach using the components provided in the example. It is a straight forward approach. But different options provided by Ruby make it much better than Java.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages like Javascript, decorator pattern can be implemented with no interfaces or traditional OOP inheritance. With simple overriding but this approach is difficult to implement [http://en.wikipedia.org/wiki/Decorator_pattern#JavaScript].&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
We have seen four design patterns Factory design pattern, Abstract Factory design pattern, Iterator design pattern and Decorator Design Pattern. We have chosen these patterns as they are widely used and Ruby has in-built implementations of these. We have mainly tried to compare Ruby and Java but also specified tips about other languages like PHP, C# and Javascript. In Ruby implementing these design patterns is simple and easy because of its main feature of private class objects, unbounded polymorphism and duck typing [http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf]. In Java all the features are mainly implemented through interfaces and classes. This has several disadvantages like increase in code complexity, size and is generally confusing and tedious to trace or understand the code.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf Design Patterns]&lt;br /&gt;
#[http://www.patterndepot.com/put/8/JavaPatterns.htm Design Patterns Java Companion James W Cooper]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 Wiki Design Patterns]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory Method]&lt;br /&gt;
#[http://sourcemaking.com/design_patterns/abstract_factory SourceMaking explains Abstract Factory]&lt;br /&gt;
#[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf Abstract Factory Example in Java]&lt;br /&gt;
#[http://www.dofactory.com/Patterns/PatternAbstract.aspx Abstract Factory explained]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Iterator_pattern Iterator Pattern]&lt;br /&gt;
#[http://sourcemaking.com/design_patterns/iterator Sourcemaking explains Iterator method]&lt;br /&gt;
#[http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf Iterator method explained]&lt;br /&gt;
#[http://www.dofactory.com/Patterns/PatternIterator.aspx DoFactory explains Iterator pattern]&lt;br /&gt;
#[http://us3.php.net/manual/en/language.oop5.iterations.php Iterator pattern for PHP]&lt;br /&gt;
#[http://www.patterndepot.com/put/8/Decorator.pdf Decorator Pattern]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Decorator_pattern Wiki Decorator Pattern]&lt;br /&gt;
#[http://www.scribd.com/doc/2217773/Design-Patterns-in-Ruby Design Patterns in Ruby]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Decorator_pattern#JavaScript Design Patterns Javascript]&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=23281</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 11 zv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=23281"/>
		<updated>2009-10-09T00:25:47Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* What is Factory Design Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''What facilities does Ruby offer that makes it easier to realize other GoF (and other) patterns that we did not cover in class? The key idea here is to explore how Ruby can implement these patterns more efficiently or transparently than static (or other dynamic) o-o languages.''&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Before starting off with design patterns for Ruby we need to define what a design pattern is, Design patterns can be described as &amp;quot;a general reusable solution to a commonly occurring problem in software design.&amp;quot; [http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29]&lt;br /&gt;
&amp;quot;The idea of design patterns is to not to reinvent the wheel but to solve the current problems by using solutions that have worked in the past&amp;quot; [http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf]. A design pattern names, abstracts, and identifies the key aspects of a common design structure that make it useful for creating a reusable object-oriented design. It helps to identify the classes and instances and the way they collaborate with each other to form a solution to a problem. Design patterns can be classified into 3 parts [http://en.wikipedia.org/wiki/Creational_pattern Creational], [http://en.wikipedia.org/wiki/Structural_pattern Structural], [http://en.wikipedia.org/wiki/Behavioral_pattern Behavioral] [http://www.patterndepot.com/put/8/JavaPatterns.htm].&lt;br /&gt;
&lt;br /&gt;
=Factory Design Pattern=&lt;br /&gt;
==What is Factory Design Pattern?==&lt;br /&gt;
The factory design pattern is an object oriented design pattern. It is a creational design pattern and deals with the issues faced in creating objects.&lt;br /&gt;
The main goal of this implementation is to isolate the code that creates the class form the concrete implementation of that class. Ruby example for the same is given below.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
&lt;br /&gt;
    class GearFactory&lt;br /&gt;
      def new() &lt;br /&gt;
        if ( ... some condition )&lt;br /&gt;
           return Sprocket.new()&lt;br /&gt;
        else&lt;br /&gt;
           return Cog().new()&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Our client class now becomes:&lt;br /&gt;
    class GearUser &lt;br /&gt;
      def doSomething(factory )&lt;br /&gt;
        ...&lt;br /&gt;
      my_gear = factory.new()&lt;br /&gt;
        ...&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The above code does not have to distinguish between a factory and an ordinary class. We can call the class using the following code.&lt;br /&gt;
    client.doSomething(GearFactory.new)          #Use the factory&lt;br /&gt;
    client.doSomething(Cog)                      #Use the Cog class&lt;br /&gt;
    client.doSomething(Sprocket)                 #Use the Sprocket class&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
In java the Factory implementation is done using interfaces. Declaring them as interfaces helps to maintain a general overview and not depending on the type of factory object that needs to be used. All of these can be placed in a huge factory in a client application.&lt;br /&gt;
A well known example for Java Factory is the UI toolkits that are designed to run on different windowing systems.&lt;br /&gt;
    interface ScrollBar { ... }&lt;br /&gt;
    interface MenuBar   { ... }&lt;br /&gt;
    ...&lt;br /&gt;
And associated classes implementing them on different windowing systems:&lt;br /&gt;
&lt;br /&gt;
    class MotifScrollBar implements ScrollBar { ... }&lt;br /&gt;
    class Win95ScrollBar implements ScrollBar { ... }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
And a factory interface that also doesn't commit to representation:&lt;br /&gt;
&lt;br /&gt;
    interface Factory {&lt;br /&gt;
      public abstract ScrollBar newScrollBar();&lt;br /&gt;
      public abstract MenuBar   newMenuBar();&lt;br /&gt;
      ... &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
But implementation classes that do:&lt;br /&gt;
&lt;br /&gt;
    class MotifFactory implements Factory {&lt;br /&gt;
      public ScrollBar newScrollBar() { return new MotifScrollBar(...); }&lt;br /&gt;
      ...&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory Pattern=&lt;br /&gt;
==What is Abstract Factory Pattern?==&lt;br /&gt;
Abstract Factory Design Pattern encapsulates a group of objects that have common theme. It implements a generic interface to create these objects that are part of the theme. It does not care about the details of the implementation of these objects. The Abstract Factory pattern, a class delegates the responsibility of object instantiation to another object via composition. It is a type of Creational pattern [http://en.wikipedia.org/wiki/Abstract_factory_pattern] “Provide an interface for creating families of related or dependent objects without specifying their concrete classes” [http://sourcemaking.com/design_patterns/abstract_factory]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
Ruby automatically implements the Abstract Factory pattern as Class Objects. All Class objects have the same interface: the new method of each class object creates new instances of the class. Thus the code can pass references to class objects around and they can be used to call new method without knowing the exact type of object that the class creates.&lt;br /&gt;
&lt;br /&gt;
    Class Foo; end&lt;br /&gt;
    Class Bar, end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is the use of Abstract Factory Pattern&lt;br /&gt;
    &lt;br /&gt;
    def create_something(factory)&lt;br /&gt;
	new_object = factory.new&lt;br /&gt;
	puts &amp;quot;created a new #{new_object.class} with a factory&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Here we select a factory to use&lt;br /&gt;
    Create_something(Foo)&lt;br /&gt;
    Create_something(Bar)&lt;br /&gt;
&lt;br /&gt;
Output of the code:&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Foo with a factory&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Bar with a factory&lt;br /&gt;
&lt;br /&gt;
The create_something method is creating objects through an abstract interface. It does not have details about implementation used to create these objects. Thus the use of create_something() is used to shield the rest of the code from that knowledge.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
In Java, implementing  Abstract Factory design pattern we need to create a class which has method who defers creation of product objects to its concrete class. This class then needs to be ”extended” by the client class which uses only these interfaces to create objects of concrete class&lt;br /&gt;
[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf]. In Java, Abstract Factory defines a different method for the creation of each product it can produce. The following example shows an implementation of Abstract Factory design pattern in Java. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   public class FactoryFmProto {&lt;br /&gt;
  static class Expression {&lt;br /&gt;
   protected String str;&lt;br /&gt;
   public Expression( String s ) { str = s; }&lt;br /&gt;
   public Expression cloan()     { return null; }&lt;br /&gt;
   public String     toString()  { return str; }&lt;br /&gt;
  }&lt;br /&gt;
  static abstract class Factory {&lt;br /&gt;
   protected Expression prototype = null;&lt;br /&gt;
   public Expression makePhrase() { return prototype.cloan(); }&lt;br /&gt;
   public abstract Expression makeCompromise();&lt;br /&gt;
   public abstract Expression makeGrade();&lt;br /&gt;
  }&lt;br /&gt;
  static class PCFactory extends Factory {&lt;br /&gt;
   public PCFactory() { prototype = new PCPhrase(); }&lt;br /&gt;
   public Expression makeCompromise() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;do it your way, any way, or no way\&amp;quot;&amp;quot; ); }&lt;br /&gt;
   public Expression makeGrade() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;you pass, self-esteem intact\&amp;quot;&amp;quot; ); }&lt;br /&gt;
  }&lt;br /&gt;
   static class NotPCFactory extends Factory {&lt;br /&gt;
   public NotPCFactory() { prototype = new NotPCPhrase(); }&lt;br /&gt;
   public Expression makeCompromise() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;my way, or the highway\&amp;quot;&amp;quot; ); }&lt;br /&gt;
   public Expression makeGrade() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;take test, deal with the results\&amp;quot;&amp;quot; ); }&lt;br /&gt;
  }&lt;br /&gt;
   public static void main( String[] args ) {&lt;br /&gt;
   Factory factory;&lt;br /&gt;
   if (args.length &amp;gt; 0) factory = new PCFactory();&lt;br /&gt;
   else                 factory = new NotPCFactory();&lt;br /&gt;
   for (int i=0; i &amp;lt; 3; i++) System.out.print( factory.makePhrase() + &amp;quot;  &amp;quot; );&lt;br /&gt;
   System.out.println();&lt;br /&gt;
   System.out.println( factory.makeCompromise() );&lt;br /&gt;
   System.out.println( factory.makeGrade() );&lt;br /&gt;
  }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
Basically, Java and Ruby, both can implement Abstract Factory design pattern. But the more important point is the simplicity by which they can apply it. Ruby automatically implements the Abstract Factory pattern as Class Objects. But Java needs helps of interfaces and classes to do so. Thus Java implementation needs a well defined interface to do so but in Ruby it is directly implemented because of private class object property.&lt;br /&gt;
&lt;br /&gt;
Similarly, C# demonstrates the Abstract Factory pattern by creating parallel hierarchies of objects. Object creation has been abstracted and there is no need for hard-coded class names in the client code. This property helps C# to have better implementation than Java. In .NET, there are built in features such as, generics, reflection, object initializers, automatic properties, etc for implementation [http://www.dofactory.com/Patterns/PatternAbstract.aspx].&lt;br /&gt;
&lt;br /&gt;
=Iterator Design Pattern=&lt;br /&gt;
==What is Iterator Design Pattern?==&lt;br /&gt;
The Iterator design pattern allows an object to encapsulate the internal structure and allows the user to move through the collection of data using standard interface. It is one of the simplest and most frequently used design pattern. It is a type of Behavioral design pattern [http://en.wikipedia.org/wiki/Iterator_pattern]. “Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.” [http://sourcemaking.com/design_patterns/iterator]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
Ruby implements iterators with blocks and the ‘each’ method, and with ‘for..in’ statements. For example consider the following example;&lt;br /&gt;
&lt;br /&gt;
    def print_element(container)&lt;br /&gt;
    	Container.each {|o| puts o.inspect }&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    list = [1,2,2,3]&lt;br /&gt;
    hash = {“a”=&amp;gt;1, “b”=&amp;gt;2,”c”=&amp;gt;3, “d”=&amp;gt;4 }&lt;br /&gt;
    print_elements list&lt;br /&gt;
    print_elements hash&lt;br /&gt;
&lt;br /&gt;
The output of the code is,&lt;br /&gt;
    1&lt;br /&gt;
    2&lt;br /&gt;
    3&lt;br /&gt;
    4&lt;br /&gt;
    [“a”,1]&lt;br /&gt;
    [“b”,2]&lt;br /&gt;
    [“c”,3]&lt;br /&gt;
    [“d”,4]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
&lt;br /&gt;
In Java, we can implement Iterator design pattern by using java.util.Enumeration interface which returns a reference to an object. Furthermore, Hashes and Vector have limited capabilities which help simple traversing. Java JDK 1.2 introduced a new Collections package with more aggregate classes, including sets, lists, maps and an Iterator interface. If we wanted to start implementing Iterator design pattern from start, then it would again involve having an interface for accessing and traversing the elements which is further implemented by the concrete class.  Thus a class who needs to access the list will need to call the interface class [http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf]. For example, consider the following scenario where iterator.First() and iterator.Next(), has been implemented in the class ListIterator.&lt;br /&gt;
&lt;br /&gt;
    ...&lt;br /&gt;
    List list = new List();&lt;br /&gt;
    ...&lt;br /&gt;
    ListIterator iterator = new ListIterator(list);&lt;br /&gt;
    iterator.First();&lt;br /&gt;
    while (!iterator.IsDone()) {&lt;br /&gt;
    Object item = iterator.CurrentItem();&lt;br /&gt;
    // Code here to process item.&lt;br /&gt;
    iterator.Next();&lt;br /&gt;
    }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
&lt;br /&gt;
Overall implementation of Iterator design pattern in each object oriented language is simple as it is a basis feature of objects. But in general, the Ruby implementation is more concise. Ruby has built-in iterators which make it easier to implement Iterator pattern for any kind of object. It hides the structure and there is no need for having implementation for those methods in the class. But in Java, the built-in library function help to create easier and clear implementations. C# also has similar implementation as Java for this design pattern [http://www.dofactory.com/Patterns/PatternIterator.aspx]. &lt;br /&gt;
&lt;br /&gt;
In PHP, using an object in a foreach structure will traverse the public values. There are also many multiple Iterator classes available to allow us to iterate through common lists, such as directories, XML structures and recursive arrays. We can also implement our own interfaces depending on requirement [http://us3.php.net/manual/en/language.oop5.iterations.php].&lt;br /&gt;
&lt;br /&gt;
=Decorator Pattern=&lt;br /&gt;
&lt;br /&gt;
This pattern is used to increase the functionality of the existing object dynamically. Suppose we have a program that uses eight objects, but three of them need an additional feature. We could create derived class for these objects having the additional features but then we can create a Decorator class which will add any specific kind of feature required [http://www.patterndepot.com/put/8/Decorator.pdf]. It is a type of behavioral pattern.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
&lt;br /&gt;
Generic decorators can be implmented by using the method_missing method. This method is called when an object receives a message that it does not have a method fo. The method_missing method can forward the message on to other object and wrap additional behavior around the call. In this example we talk about how a coffee class can have many addtions to it like coffee with cream, sprinkles, milk etc and creating a class for each of them will not be the correct solution.In this example the cost can be calculated according to what is sent to it.Cost of the coffee is 2 and the cost of White coffee (coffee + milk) = 2.4. So what happens when we execute the Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost we get the result as 2.9 as the cost of the coffee is 2, the decorator object (now only coffee) is sent to the Milk and it becomes 2.4, which now is then sent to the Whip which is going to be 2.4 + 02 = 2.6 and finally to Sprinkles which becomes 2.6 + 0.3 = 2.9. The below code is an example of decorators where we just create a place holder and we can use this function to perform different functions depending on the parameters supplied to it. The need for this kind of pattern is so as to increase the functionality of a particular class [http://en.wikipedia.org/wiki/Decorator_pattern]. &lt;br /&gt;
&lt;br /&gt;
    module Decorator&lt;br /&gt;
      def initialize(decorated)&lt;br /&gt;
        @decorated = decorated&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    def method_missing(method, *args)&lt;br /&gt;
        args.empty? ? @decorated.send(method) : @decorated.send(method, args)&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
    class Whip&lt;br /&gt;
      include Decorator&lt;br /&gt;
      def cost &lt;br /&gt;
        @decorated.cost + 0.2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    class Sprinkles&lt;br /&gt;
      include Decorator&lt;br /&gt;
&lt;br /&gt;
      def cost&lt;br /&gt;
        @decorated.cost + 0.3&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    Whip.new(Coffee.new).cost&lt;br /&gt;
    #=&amp;gt; 2.2&lt;br /&gt;
    Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost &lt;br /&gt;
    #=&amp;gt; 2.9&lt;br /&gt;
&lt;br /&gt;
There are various other options to implement this design pattern. Other way to implememt the pattern is by using singleton methods and method aliases. Delegation can also be used, and it overcomes one of the most important disadvantage. We can remove add features if we are using delegation but this is not possible if we are using singleton methods and method aliases. Example for this can be found here [http://www.scribd.com/doc/2217773/Design-Patterns-in-Ruby].&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
&lt;br /&gt;
In Java, this pattern is easy to implement by dividing the various responsibilities into classes and interfaces. The below example consider all these responsibilities and have four components which are described below  &lt;br /&gt;
* Component: Defines the interface for objects that can have responsibilities added to them dynamically.&lt;br /&gt;
* ConcreteComponent: Defines an object to which additional responsibilities can be attached.&lt;br /&gt;
* Decorator: maintains a reference to a Component object and defines an interface that conforms to Component's interface.&lt;br /&gt;
* ConcreteDecorator: adds responsibilities to the component.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface IComponent {&lt;br /&gt;
    public void doStuff();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete component&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class Component implements IComponent{&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    System.out.println(&amp;quot;Do Suff&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Decorator&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface Decorator extends IComponent {&lt;br /&gt;
    public void addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete Decorator ('''Extends IComponent''')&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class ConcreteDecorator implements Decorator {&lt;br /&gt;
    IComponent component;&lt;br /&gt;
    public ConcreteDecorator(IComponent component) {&lt;br /&gt;
    super();&lt;br /&gt;
    this.component = component;&lt;br /&gt;
    }&lt;br /&gt;
    public void addedBehavior() {&lt;br /&gt;
    System.out.println(&amp;quot;Decorator does some stuff too&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    component.doStuff();&lt;br /&gt;
    addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
The Client&lt;br /&gt;
&lt;br /&gt;
    import decorator.*;&lt;br /&gt;
    public class Client {&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
    IComponent comp = new Component();&lt;br /&gt;
    Decorator decorator = new ConcreteDecorator(comp);&lt;br /&gt;
    decorator.doStuff();&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
==Comparison of implementations==&lt;br /&gt;
&lt;br /&gt;
Ruby provides different options to implement Decorator pattern like method_missing, delegation and alias methods. This provides flexibility to the user to implement any possible way depending on the requirements and features needed. But in Java, there is more clearer approach using the components provided in the example. It is a straight forward approach. But different options provided by Ruby make it much better than Java.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages like Javascript, decorator pattern can be implemented with no interfaces or traditional OOP inheritance. With simple overriding but this approach is difficult to implement [http://en.wikipedia.org/wiki/Decorator_pattern#JavaScript].&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
We have seen four design patterns Factory design pattern, Abstract Factory design pattern, Iterator design pattern and Decorator Design Pattern. We have chosen these patterns as they are widely used and Ruby has in-built implementations of these. We have mainly tried to compare Ruby and Java but also specified tips about other languages like PHP, C# and Javascript. In Ruby implementing these design patterns is simple and easy because of its main feature of private class objects, unbounded polymorphism and duck typing [http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf]. In Java all the features are mainly implemented through interfaces and classes. This has several disadvantages like increase in code complexity, size and is generally confusing and tedious to trace or understand the code.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf Design Patterns]&lt;br /&gt;
#[http://www.patterndepot.com/put/8/JavaPatterns.htm Design Patterns Java Companion James W Cooper]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 Wiki Design Patterns]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory Method]&lt;br /&gt;
#[http://sourcemaking.com/design_patterns/abstract_factory SourceMaking explains Abstract Factory]&lt;br /&gt;
#[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf Abstract Factory Example in Java]&lt;br /&gt;
#[http://www.dofactory.com/Patterns/PatternAbstract.aspx Abstract Factory explained]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Iterator_pattern Iterator Pattern]&lt;br /&gt;
#[http://sourcemaking.com/design_patterns/iterator Sourcemaking explains Iterator method]&lt;br /&gt;
#[http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf Iterator method explained]&lt;br /&gt;
#[http://www.dofactory.com/Patterns/PatternIterator.aspx DoFactory explains Iterator pattern]&lt;br /&gt;
#[http://us3.php.net/manual/en/language.oop5.iterations.php Iterator pattern for PHP]&lt;br /&gt;
#[http://www.patterndepot.com/put/8/Decorator.pdf Decorator Pattern]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Decorator_pattern Wiki Decorator Pattern]&lt;br /&gt;
#[http://www.scribd.com/doc/2217773/Design-Patterns-in-Ruby Design Patterns in Ruby]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Decorator_pattern#JavaScript Design Patterns Javascript]&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=23279</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 11 zv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=23279"/>
		<updated>2009-10-09T00:25:31Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Factory Example in Ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''What facilities does Ruby offer that makes it easier to realize other GoF (and other) patterns that we did not cover in class? The key idea here is to explore how Ruby can implement these patterns more efficiently or transparently than static (or other dynamic) o-o languages.''&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Before starting off with design patterns for Ruby we need to define what a design pattern is, Design patterns can be described as &amp;quot;a general reusable solution to a commonly occurring problem in software design.&amp;quot; [http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29]&lt;br /&gt;
&amp;quot;The idea of design patterns is to not to reinvent the wheel but to solve the current problems by using solutions that have worked in the past&amp;quot; [http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf]. A design pattern names, abstracts, and identifies the key aspects of a common design structure that make it useful for creating a reusable object-oriented design. It helps to identify the classes and instances and the way they collaborate with each other to form a solution to a problem. Design patterns can be classified into 3 parts [http://en.wikipedia.org/wiki/Creational_pattern Creational], [http://en.wikipedia.org/wiki/Structural_pattern Structural], [http://en.wikipedia.org/wiki/Behavioral_pattern Behavioral] [http://www.patterndepot.com/put/8/JavaPatterns.htm].&lt;br /&gt;
&lt;br /&gt;
=Factory Design Pattern=&lt;br /&gt;
==What is Factory Design Pattern==&lt;br /&gt;
The factory design pattern is an object oriented design pattern. It is a creational design pattern and deals with the issues faced in creating objects.&lt;br /&gt;
The main goal of this implementation is to isolate the code that creates the class form the concrete implementation of that class. Ruby example for the same is given below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
&lt;br /&gt;
    class GearFactory&lt;br /&gt;
      def new() &lt;br /&gt;
        if ( ... some condition )&lt;br /&gt;
           return Sprocket.new()&lt;br /&gt;
        else&lt;br /&gt;
           return Cog().new()&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Our client class now becomes:&lt;br /&gt;
    class GearUser &lt;br /&gt;
      def doSomething(factory )&lt;br /&gt;
        ...&lt;br /&gt;
      my_gear = factory.new()&lt;br /&gt;
        ...&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The above code does not have to distinguish between a factory and an ordinary class. We can call the class using the following code.&lt;br /&gt;
    client.doSomething(GearFactory.new)          #Use the factory&lt;br /&gt;
    client.doSomething(Cog)                      #Use the Cog class&lt;br /&gt;
    client.doSomething(Sprocket)                 #Use the Sprocket class&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
In java the Factory implementation is done using interfaces. Declaring them as interfaces helps to maintain a general overview and not depending on the type of factory object that needs to be used. All of these can be placed in a huge factory in a client application.&lt;br /&gt;
A well known example for Java Factory is the UI toolkits that are designed to run on different windowing systems.&lt;br /&gt;
    interface ScrollBar { ... }&lt;br /&gt;
    interface MenuBar   { ... }&lt;br /&gt;
    ...&lt;br /&gt;
And associated classes implementing them on different windowing systems:&lt;br /&gt;
&lt;br /&gt;
    class MotifScrollBar implements ScrollBar { ... }&lt;br /&gt;
    class Win95ScrollBar implements ScrollBar { ... }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
And a factory interface that also doesn't commit to representation:&lt;br /&gt;
&lt;br /&gt;
    interface Factory {&lt;br /&gt;
      public abstract ScrollBar newScrollBar();&lt;br /&gt;
      public abstract MenuBar   newMenuBar();&lt;br /&gt;
      ... &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
But implementation classes that do:&lt;br /&gt;
&lt;br /&gt;
    class MotifFactory implements Factory {&lt;br /&gt;
      public ScrollBar newScrollBar() { return new MotifScrollBar(...); }&lt;br /&gt;
      ...&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory Pattern=&lt;br /&gt;
==What is Abstract Factory Pattern?==&lt;br /&gt;
Abstract Factory Design Pattern encapsulates a group of objects that have common theme. It implements a generic interface to create these objects that are part of the theme. It does not care about the details of the implementation of these objects. The Abstract Factory pattern, a class delegates the responsibility of object instantiation to another object via composition. It is a type of Creational pattern [http://en.wikipedia.org/wiki/Abstract_factory_pattern] “Provide an interface for creating families of related or dependent objects without specifying their concrete classes” [http://sourcemaking.com/design_patterns/abstract_factory]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
Ruby automatically implements the Abstract Factory pattern as Class Objects. All Class objects have the same interface: the new method of each class object creates new instances of the class. Thus the code can pass references to class objects around and they can be used to call new method without knowing the exact type of object that the class creates.&lt;br /&gt;
&lt;br /&gt;
    Class Foo; end&lt;br /&gt;
    Class Bar, end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is the use of Abstract Factory Pattern&lt;br /&gt;
    &lt;br /&gt;
    def create_something(factory)&lt;br /&gt;
	new_object = factory.new&lt;br /&gt;
	puts &amp;quot;created a new #{new_object.class} with a factory&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Here we select a factory to use&lt;br /&gt;
    Create_something(Foo)&lt;br /&gt;
    Create_something(Bar)&lt;br /&gt;
&lt;br /&gt;
Output of the code:&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Foo with a factory&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Bar with a factory&lt;br /&gt;
&lt;br /&gt;
The create_something method is creating objects through an abstract interface. It does not have details about implementation used to create these objects. Thus the use of create_something() is used to shield the rest of the code from that knowledge.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
In Java, implementing  Abstract Factory design pattern we need to create a class which has method who defers creation of product objects to its concrete class. This class then needs to be ”extended” by the client class which uses only these interfaces to create objects of concrete class&lt;br /&gt;
[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf]. In Java, Abstract Factory defines a different method for the creation of each product it can produce. The following example shows an implementation of Abstract Factory design pattern in Java. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   public class FactoryFmProto {&lt;br /&gt;
  static class Expression {&lt;br /&gt;
   protected String str;&lt;br /&gt;
   public Expression( String s ) { str = s; }&lt;br /&gt;
   public Expression cloan()     { return null; }&lt;br /&gt;
   public String     toString()  { return str; }&lt;br /&gt;
  }&lt;br /&gt;
  static abstract class Factory {&lt;br /&gt;
   protected Expression prototype = null;&lt;br /&gt;
   public Expression makePhrase() { return prototype.cloan(); }&lt;br /&gt;
   public abstract Expression makeCompromise();&lt;br /&gt;
   public abstract Expression makeGrade();&lt;br /&gt;
  }&lt;br /&gt;
  static class PCFactory extends Factory {&lt;br /&gt;
   public PCFactory() { prototype = new PCPhrase(); }&lt;br /&gt;
   public Expression makeCompromise() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;do it your way, any way, or no way\&amp;quot;&amp;quot; ); }&lt;br /&gt;
   public Expression makeGrade() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;you pass, self-esteem intact\&amp;quot;&amp;quot; ); }&lt;br /&gt;
  }&lt;br /&gt;
   static class NotPCFactory extends Factory {&lt;br /&gt;
   public NotPCFactory() { prototype = new NotPCPhrase(); }&lt;br /&gt;
   public Expression makeCompromise() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;my way, or the highway\&amp;quot;&amp;quot; ); }&lt;br /&gt;
   public Expression makeGrade() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;take test, deal with the results\&amp;quot;&amp;quot; ); }&lt;br /&gt;
  }&lt;br /&gt;
   public static void main( String[] args ) {&lt;br /&gt;
   Factory factory;&lt;br /&gt;
   if (args.length &amp;gt; 0) factory = new PCFactory();&lt;br /&gt;
   else                 factory = new NotPCFactory();&lt;br /&gt;
   for (int i=0; i &amp;lt; 3; i++) System.out.print( factory.makePhrase() + &amp;quot;  &amp;quot; );&lt;br /&gt;
   System.out.println();&lt;br /&gt;
   System.out.println( factory.makeCompromise() );&lt;br /&gt;
   System.out.println( factory.makeGrade() );&lt;br /&gt;
  }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
Basically, Java and Ruby, both can implement Abstract Factory design pattern. But the more important point is the simplicity by which they can apply it. Ruby automatically implements the Abstract Factory pattern as Class Objects. But Java needs helps of interfaces and classes to do so. Thus Java implementation needs a well defined interface to do so but in Ruby it is directly implemented because of private class object property.&lt;br /&gt;
&lt;br /&gt;
Similarly, C# demonstrates the Abstract Factory pattern by creating parallel hierarchies of objects. Object creation has been abstracted and there is no need for hard-coded class names in the client code. This property helps C# to have better implementation than Java. In .NET, there are built in features such as, generics, reflection, object initializers, automatic properties, etc for implementation [http://www.dofactory.com/Patterns/PatternAbstract.aspx].&lt;br /&gt;
&lt;br /&gt;
=Iterator Design Pattern=&lt;br /&gt;
==What is Iterator Design Pattern?==&lt;br /&gt;
The Iterator design pattern allows an object to encapsulate the internal structure and allows the user to move through the collection of data using standard interface. It is one of the simplest and most frequently used design pattern. It is a type of Behavioral design pattern [http://en.wikipedia.org/wiki/Iterator_pattern]. “Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.” [http://sourcemaking.com/design_patterns/iterator]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
Ruby implements iterators with blocks and the ‘each’ method, and with ‘for..in’ statements. For example consider the following example;&lt;br /&gt;
&lt;br /&gt;
    def print_element(container)&lt;br /&gt;
    	Container.each {|o| puts o.inspect }&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    list = [1,2,2,3]&lt;br /&gt;
    hash = {“a”=&amp;gt;1, “b”=&amp;gt;2,”c”=&amp;gt;3, “d”=&amp;gt;4 }&lt;br /&gt;
    print_elements list&lt;br /&gt;
    print_elements hash&lt;br /&gt;
&lt;br /&gt;
The output of the code is,&lt;br /&gt;
    1&lt;br /&gt;
    2&lt;br /&gt;
    3&lt;br /&gt;
    4&lt;br /&gt;
    [“a”,1]&lt;br /&gt;
    [“b”,2]&lt;br /&gt;
    [“c”,3]&lt;br /&gt;
    [“d”,4]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
&lt;br /&gt;
In Java, we can implement Iterator design pattern by using java.util.Enumeration interface which returns a reference to an object. Furthermore, Hashes and Vector have limited capabilities which help simple traversing. Java JDK 1.2 introduced a new Collections package with more aggregate classes, including sets, lists, maps and an Iterator interface. If we wanted to start implementing Iterator design pattern from start, then it would again involve having an interface for accessing and traversing the elements which is further implemented by the concrete class.  Thus a class who needs to access the list will need to call the interface class [http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf]. For example, consider the following scenario where iterator.First() and iterator.Next(), has been implemented in the class ListIterator.&lt;br /&gt;
&lt;br /&gt;
    ...&lt;br /&gt;
    List list = new List();&lt;br /&gt;
    ...&lt;br /&gt;
    ListIterator iterator = new ListIterator(list);&lt;br /&gt;
    iterator.First();&lt;br /&gt;
    while (!iterator.IsDone()) {&lt;br /&gt;
    Object item = iterator.CurrentItem();&lt;br /&gt;
    // Code here to process item.&lt;br /&gt;
    iterator.Next();&lt;br /&gt;
    }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
&lt;br /&gt;
Overall implementation of Iterator design pattern in each object oriented language is simple as it is a basis feature of objects. But in general, the Ruby implementation is more concise. Ruby has built-in iterators which make it easier to implement Iterator pattern for any kind of object. It hides the structure and there is no need for having implementation for those methods in the class. But in Java, the built-in library function help to create easier and clear implementations. C# also has similar implementation as Java for this design pattern [http://www.dofactory.com/Patterns/PatternIterator.aspx]. &lt;br /&gt;
&lt;br /&gt;
In PHP, using an object in a foreach structure will traverse the public values. There are also many multiple Iterator classes available to allow us to iterate through common lists, such as directories, XML structures and recursive arrays. We can also implement our own interfaces depending on requirement [http://us3.php.net/manual/en/language.oop5.iterations.php].&lt;br /&gt;
&lt;br /&gt;
=Decorator Pattern=&lt;br /&gt;
&lt;br /&gt;
This pattern is used to increase the functionality of the existing object dynamically. Suppose we have a program that uses eight objects, but three of them need an additional feature. We could create derived class for these objects having the additional features but then we can create a Decorator class which will add any specific kind of feature required [http://www.patterndepot.com/put/8/Decorator.pdf]. It is a type of behavioral pattern.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
&lt;br /&gt;
Generic decorators can be implmented by using the method_missing method. This method is called when an object receives a message that it does not have a method fo. The method_missing method can forward the message on to other object and wrap additional behavior around the call. In this example we talk about how a coffee class can have many addtions to it like coffee with cream, sprinkles, milk etc and creating a class for each of them will not be the correct solution.In this example the cost can be calculated according to what is sent to it.Cost of the coffee is 2 and the cost of White coffee (coffee + milk) = 2.4. So what happens when we execute the Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost we get the result as 2.9 as the cost of the coffee is 2, the decorator object (now only coffee) is sent to the Milk and it becomes 2.4, which now is then sent to the Whip which is going to be 2.4 + 02 = 2.6 and finally to Sprinkles which becomes 2.6 + 0.3 = 2.9. The below code is an example of decorators where we just create a place holder and we can use this function to perform different functions depending on the parameters supplied to it. The need for this kind of pattern is so as to increase the functionality of a particular class [http://en.wikipedia.org/wiki/Decorator_pattern]. &lt;br /&gt;
&lt;br /&gt;
    module Decorator&lt;br /&gt;
      def initialize(decorated)&lt;br /&gt;
        @decorated = decorated&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    def method_missing(method, *args)&lt;br /&gt;
        args.empty? ? @decorated.send(method) : @decorated.send(method, args)&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
    class Whip&lt;br /&gt;
      include Decorator&lt;br /&gt;
      def cost &lt;br /&gt;
        @decorated.cost + 0.2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    class Sprinkles&lt;br /&gt;
      include Decorator&lt;br /&gt;
&lt;br /&gt;
      def cost&lt;br /&gt;
        @decorated.cost + 0.3&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    Whip.new(Coffee.new).cost&lt;br /&gt;
    #=&amp;gt; 2.2&lt;br /&gt;
    Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost &lt;br /&gt;
    #=&amp;gt; 2.9&lt;br /&gt;
&lt;br /&gt;
There are various other options to implement this design pattern. Other way to implememt the pattern is by using singleton methods and method aliases. Delegation can also be used, and it overcomes one of the most important disadvantage. We can remove add features if we are using delegation but this is not possible if we are using singleton methods and method aliases. Example for this can be found here [http://www.scribd.com/doc/2217773/Design-Patterns-in-Ruby].&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
&lt;br /&gt;
In Java, this pattern is easy to implement by dividing the various responsibilities into classes and interfaces. The below example consider all these responsibilities and have four components which are described below  &lt;br /&gt;
* Component: Defines the interface for objects that can have responsibilities added to them dynamically.&lt;br /&gt;
* ConcreteComponent: Defines an object to which additional responsibilities can be attached.&lt;br /&gt;
* Decorator: maintains a reference to a Component object and defines an interface that conforms to Component's interface.&lt;br /&gt;
* ConcreteDecorator: adds responsibilities to the component.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface IComponent {&lt;br /&gt;
    public void doStuff();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete component&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class Component implements IComponent{&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    System.out.println(&amp;quot;Do Suff&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Decorator&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface Decorator extends IComponent {&lt;br /&gt;
    public void addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete Decorator ('''Extends IComponent''')&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class ConcreteDecorator implements Decorator {&lt;br /&gt;
    IComponent component;&lt;br /&gt;
    public ConcreteDecorator(IComponent component) {&lt;br /&gt;
    super();&lt;br /&gt;
    this.component = component;&lt;br /&gt;
    }&lt;br /&gt;
    public void addedBehavior() {&lt;br /&gt;
    System.out.println(&amp;quot;Decorator does some stuff too&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    component.doStuff();&lt;br /&gt;
    addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
The Client&lt;br /&gt;
&lt;br /&gt;
    import decorator.*;&lt;br /&gt;
    public class Client {&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
    IComponent comp = new Component();&lt;br /&gt;
    Decorator decorator = new ConcreteDecorator(comp);&lt;br /&gt;
    decorator.doStuff();&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
==Comparison of implementations==&lt;br /&gt;
&lt;br /&gt;
Ruby provides different options to implement Decorator pattern like method_missing, delegation and alias methods. This provides flexibility to the user to implement any possible way depending on the requirements and features needed. But in Java, there is more clearer approach using the components provided in the example. It is a straight forward approach. But different options provided by Ruby make it much better than Java.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages like Javascript, decorator pattern can be implemented with no interfaces or traditional OOP inheritance. With simple overriding but this approach is difficult to implement [http://en.wikipedia.org/wiki/Decorator_pattern#JavaScript].&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
We have seen four design patterns Factory design pattern, Abstract Factory design pattern, Iterator design pattern and Decorator Design Pattern. We have chosen these patterns as they are widely used and Ruby has in-built implementations of these. We have mainly tried to compare Ruby and Java but also specified tips about other languages like PHP, C# and Javascript. In Ruby implementing these design patterns is simple and easy because of its main feature of private class objects, unbounded polymorphism and duck typing [http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf]. In Java all the features are mainly implemented through interfaces and classes. This has several disadvantages like increase in code complexity, size and is generally confusing and tedious to trace or understand the code.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf Design Patterns]&lt;br /&gt;
#[http://www.patterndepot.com/put/8/JavaPatterns.htm Design Patterns Java Companion James W Cooper]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 Wiki Design Patterns]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory Method]&lt;br /&gt;
#[http://sourcemaking.com/design_patterns/abstract_factory SourceMaking explains Abstract Factory]&lt;br /&gt;
#[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf Abstract Factory Example in Java]&lt;br /&gt;
#[http://www.dofactory.com/Patterns/PatternAbstract.aspx Abstract Factory explained]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Iterator_pattern Iterator Pattern]&lt;br /&gt;
#[http://sourcemaking.com/design_patterns/iterator Sourcemaking explains Iterator method]&lt;br /&gt;
#[http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf Iterator method explained]&lt;br /&gt;
#[http://www.dofactory.com/Patterns/PatternIterator.aspx DoFactory explains Iterator pattern]&lt;br /&gt;
#[http://us3.php.net/manual/en/language.oop5.iterations.php Iterator pattern for PHP]&lt;br /&gt;
#[http://www.patterndepot.com/put/8/Decorator.pdf Decorator Pattern]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Decorator_pattern Wiki Decorator Pattern]&lt;br /&gt;
#[http://www.scribd.com/doc/2217773/Design-Patterns-in-Ruby Design Patterns in Ruby]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Decorator_pattern#JavaScript Design Patterns Javascript]&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=23277</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 11 zv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=23277"/>
		<updated>2009-10-09T00:25:13Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Factory Example in Java */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''What facilities does Ruby offer that makes it easier to realize other GoF (and other) patterns that we did not cover in class? The key idea here is to explore how Ruby can implement these patterns more efficiently or transparently than static (or other dynamic) o-o languages.''&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Before starting off with design patterns for Ruby we need to define what a design pattern is, Design patterns can be described as &amp;quot;a general reusable solution to a commonly occurring problem in software design.&amp;quot; [http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29]&lt;br /&gt;
&amp;quot;The idea of design patterns is to not to reinvent the wheel but to solve the current problems by using solutions that have worked in the past&amp;quot; [http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf]. A design pattern names, abstracts, and identifies the key aspects of a common design structure that make it useful for creating a reusable object-oriented design. It helps to identify the classes and instances and the way they collaborate with each other to form a solution to a problem. Design patterns can be classified into 3 parts [http://en.wikipedia.org/wiki/Creational_pattern Creational], [http://en.wikipedia.org/wiki/Structural_pattern Structural], [http://en.wikipedia.org/wiki/Behavioral_pattern Behavioral] [http://www.patterndepot.com/put/8/JavaPatterns.htm].&lt;br /&gt;
&lt;br /&gt;
=Factory Design Pattern=&lt;br /&gt;
==What is Factory Design Pattern==&lt;br /&gt;
The factory design pattern is an object oriented design pattern. It is a creational design pattern and deals with the issues faced in creating objects.&lt;br /&gt;
The main goal of this implementation is to isolate the code that creates the class form the concrete implementation of that class. Ruby example for the same is given below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Factory Example in Ruby==&lt;br /&gt;
&lt;br /&gt;
    class GearFactory&lt;br /&gt;
      def new() &lt;br /&gt;
        if ( ... some condition )&lt;br /&gt;
           return Sprocket.new()&lt;br /&gt;
        else&lt;br /&gt;
           return Cog().new()&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Our client class now becomes:&lt;br /&gt;
    class GearUser &lt;br /&gt;
      def doSomething(factory )&lt;br /&gt;
        ...&lt;br /&gt;
      my_gear = factory.new()&lt;br /&gt;
        ...&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The above code does not have to distinguish between a factory and an ordinary class. We can call the class using the following code.&lt;br /&gt;
    client.doSomething(GearFactory.new)          #Use the factory&lt;br /&gt;
    client.doSomething(Cog)                      #Use the Cog class&lt;br /&gt;
    client.doSomething(Sprocket)                 #Use the Sprocket class&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
In java the Factory implementation is done using interfaces. Declaring them as interfaces helps to maintain a general overview and not depending on the type of factory object that needs to be used. All of these can be placed in a huge factory in a client application.&lt;br /&gt;
A well known example for Java Factory is the UI toolkits that are designed to run on different windowing systems.&lt;br /&gt;
    interface ScrollBar { ... }&lt;br /&gt;
    interface MenuBar   { ... }&lt;br /&gt;
    ...&lt;br /&gt;
And associated classes implementing them on different windowing systems:&lt;br /&gt;
&lt;br /&gt;
    class MotifScrollBar implements ScrollBar { ... }&lt;br /&gt;
    class Win95ScrollBar implements ScrollBar { ... }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
And a factory interface that also doesn't commit to representation:&lt;br /&gt;
&lt;br /&gt;
    interface Factory {&lt;br /&gt;
      public abstract ScrollBar newScrollBar();&lt;br /&gt;
      public abstract MenuBar   newMenuBar();&lt;br /&gt;
      ... &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
But implementation classes that do:&lt;br /&gt;
&lt;br /&gt;
    class MotifFactory implements Factory {&lt;br /&gt;
      public ScrollBar newScrollBar() { return new MotifScrollBar(...); }&lt;br /&gt;
      ...&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory Pattern=&lt;br /&gt;
==What is Abstract Factory Pattern?==&lt;br /&gt;
Abstract Factory Design Pattern encapsulates a group of objects that have common theme. It implements a generic interface to create these objects that are part of the theme. It does not care about the details of the implementation of these objects. The Abstract Factory pattern, a class delegates the responsibility of object instantiation to another object via composition. It is a type of Creational pattern [http://en.wikipedia.org/wiki/Abstract_factory_pattern] “Provide an interface for creating families of related or dependent objects without specifying their concrete classes” [http://sourcemaking.com/design_patterns/abstract_factory]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
Ruby automatically implements the Abstract Factory pattern as Class Objects. All Class objects have the same interface: the new method of each class object creates new instances of the class. Thus the code can pass references to class objects around and they can be used to call new method without knowing the exact type of object that the class creates.&lt;br /&gt;
&lt;br /&gt;
    Class Foo; end&lt;br /&gt;
    Class Bar, end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is the use of Abstract Factory Pattern&lt;br /&gt;
    &lt;br /&gt;
    def create_something(factory)&lt;br /&gt;
	new_object = factory.new&lt;br /&gt;
	puts &amp;quot;created a new #{new_object.class} with a factory&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Here we select a factory to use&lt;br /&gt;
    Create_something(Foo)&lt;br /&gt;
    Create_something(Bar)&lt;br /&gt;
&lt;br /&gt;
Output of the code:&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Foo with a factory&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Bar with a factory&lt;br /&gt;
&lt;br /&gt;
The create_something method is creating objects through an abstract interface. It does not have details about implementation used to create these objects. Thus the use of create_something() is used to shield the rest of the code from that knowledge.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
In Java, implementing  Abstract Factory design pattern we need to create a class which has method who defers creation of product objects to its concrete class. This class then needs to be ”extended” by the client class which uses only these interfaces to create objects of concrete class&lt;br /&gt;
[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf]. In Java, Abstract Factory defines a different method for the creation of each product it can produce. The following example shows an implementation of Abstract Factory design pattern in Java. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   public class FactoryFmProto {&lt;br /&gt;
  static class Expression {&lt;br /&gt;
   protected String str;&lt;br /&gt;
   public Expression( String s ) { str = s; }&lt;br /&gt;
   public Expression cloan()     { return null; }&lt;br /&gt;
   public String     toString()  { return str; }&lt;br /&gt;
  }&lt;br /&gt;
  static abstract class Factory {&lt;br /&gt;
   protected Expression prototype = null;&lt;br /&gt;
   public Expression makePhrase() { return prototype.cloan(); }&lt;br /&gt;
   public abstract Expression makeCompromise();&lt;br /&gt;
   public abstract Expression makeGrade();&lt;br /&gt;
  }&lt;br /&gt;
  static class PCFactory extends Factory {&lt;br /&gt;
   public PCFactory() { prototype = new PCPhrase(); }&lt;br /&gt;
   public Expression makeCompromise() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;do it your way, any way, or no way\&amp;quot;&amp;quot; ); }&lt;br /&gt;
   public Expression makeGrade() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;you pass, self-esteem intact\&amp;quot;&amp;quot; ); }&lt;br /&gt;
  }&lt;br /&gt;
   static class NotPCFactory extends Factory {&lt;br /&gt;
   public NotPCFactory() { prototype = new NotPCPhrase(); }&lt;br /&gt;
   public Expression makeCompromise() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;my way, or the highway\&amp;quot;&amp;quot; ); }&lt;br /&gt;
   public Expression makeGrade() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;take test, deal with the results\&amp;quot;&amp;quot; ); }&lt;br /&gt;
  }&lt;br /&gt;
   public static void main( String[] args ) {&lt;br /&gt;
   Factory factory;&lt;br /&gt;
   if (args.length &amp;gt; 0) factory = new PCFactory();&lt;br /&gt;
   else                 factory = new NotPCFactory();&lt;br /&gt;
   for (int i=0; i &amp;lt; 3; i++) System.out.print( factory.makePhrase() + &amp;quot;  &amp;quot; );&lt;br /&gt;
   System.out.println();&lt;br /&gt;
   System.out.println( factory.makeCompromise() );&lt;br /&gt;
   System.out.println( factory.makeGrade() );&lt;br /&gt;
  }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
Basically, Java and Ruby, both can implement Abstract Factory design pattern. But the more important point is the simplicity by which they can apply it. Ruby automatically implements the Abstract Factory pattern as Class Objects. But Java needs helps of interfaces and classes to do so. Thus Java implementation needs a well defined interface to do so but in Ruby it is directly implemented because of private class object property.&lt;br /&gt;
&lt;br /&gt;
Similarly, C# demonstrates the Abstract Factory pattern by creating parallel hierarchies of objects. Object creation has been abstracted and there is no need for hard-coded class names in the client code. This property helps C# to have better implementation than Java. In .NET, there are built in features such as, generics, reflection, object initializers, automatic properties, etc for implementation [http://www.dofactory.com/Patterns/PatternAbstract.aspx].&lt;br /&gt;
&lt;br /&gt;
=Iterator Design Pattern=&lt;br /&gt;
==What is Iterator Design Pattern?==&lt;br /&gt;
The Iterator design pattern allows an object to encapsulate the internal structure and allows the user to move through the collection of data using standard interface. It is one of the simplest and most frequently used design pattern. It is a type of Behavioral design pattern [http://en.wikipedia.org/wiki/Iterator_pattern]. “Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.” [http://sourcemaking.com/design_patterns/iterator]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
Ruby implements iterators with blocks and the ‘each’ method, and with ‘for..in’ statements. For example consider the following example;&lt;br /&gt;
&lt;br /&gt;
    def print_element(container)&lt;br /&gt;
    	Container.each {|o| puts o.inspect }&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    list = [1,2,2,3]&lt;br /&gt;
    hash = {“a”=&amp;gt;1, “b”=&amp;gt;2,”c”=&amp;gt;3, “d”=&amp;gt;4 }&lt;br /&gt;
    print_elements list&lt;br /&gt;
    print_elements hash&lt;br /&gt;
&lt;br /&gt;
The output of the code is,&lt;br /&gt;
    1&lt;br /&gt;
    2&lt;br /&gt;
    3&lt;br /&gt;
    4&lt;br /&gt;
    [“a”,1]&lt;br /&gt;
    [“b”,2]&lt;br /&gt;
    [“c”,3]&lt;br /&gt;
    [“d”,4]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
&lt;br /&gt;
In Java, we can implement Iterator design pattern by using java.util.Enumeration interface which returns a reference to an object. Furthermore, Hashes and Vector have limited capabilities which help simple traversing. Java JDK 1.2 introduced a new Collections package with more aggregate classes, including sets, lists, maps and an Iterator interface. If we wanted to start implementing Iterator design pattern from start, then it would again involve having an interface for accessing and traversing the elements which is further implemented by the concrete class.  Thus a class who needs to access the list will need to call the interface class [http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf]. For example, consider the following scenario where iterator.First() and iterator.Next(), has been implemented in the class ListIterator.&lt;br /&gt;
&lt;br /&gt;
    ...&lt;br /&gt;
    List list = new List();&lt;br /&gt;
    ...&lt;br /&gt;
    ListIterator iterator = new ListIterator(list);&lt;br /&gt;
    iterator.First();&lt;br /&gt;
    while (!iterator.IsDone()) {&lt;br /&gt;
    Object item = iterator.CurrentItem();&lt;br /&gt;
    // Code here to process item.&lt;br /&gt;
    iterator.Next();&lt;br /&gt;
    }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
&lt;br /&gt;
Overall implementation of Iterator design pattern in each object oriented language is simple as it is a basis feature of objects. But in general, the Ruby implementation is more concise. Ruby has built-in iterators which make it easier to implement Iterator pattern for any kind of object. It hides the structure and there is no need for having implementation for those methods in the class. But in Java, the built-in library function help to create easier and clear implementations. C# also has similar implementation as Java for this design pattern [http://www.dofactory.com/Patterns/PatternIterator.aspx]. &lt;br /&gt;
&lt;br /&gt;
In PHP, using an object in a foreach structure will traverse the public values. There are also many multiple Iterator classes available to allow us to iterate through common lists, such as directories, XML structures and recursive arrays. We can also implement our own interfaces depending on requirement [http://us3.php.net/manual/en/language.oop5.iterations.php].&lt;br /&gt;
&lt;br /&gt;
=Decorator Pattern=&lt;br /&gt;
&lt;br /&gt;
This pattern is used to increase the functionality of the existing object dynamically. Suppose we have a program that uses eight objects, but three of them need an additional feature. We could create derived class for these objects having the additional features but then we can create a Decorator class which will add any specific kind of feature required [http://www.patterndepot.com/put/8/Decorator.pdf]. It is a type of behavioral pattern.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
&lt;br /&gt;
Generic decorators can be implmented by using the method_missing method. This method is called when an object receives a message that it does not have a method fo. The method_missing method can forward the message on to other object and wrap additional behavior around the call. In this example we talk about how a coffee class can have many addtions to it like coffee with cream, sprinkles, milk etc and creating a class for each of them will not be the correct solution.In this example the cost can be calculated according to what is sent to it.Cost of the coffee is 2 and the cost of White coffee (coffee + milk) = 2.4. So what happens when we execute the Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost we get the result as 2.9 as the cost of the coffee is 2, the decorator object (now only coffee) is sent to the Milk and it becomes 2.4, which now is then sent to the Whip which is going to be 2.4 + 02 = 2.6 and finally to Sprinkles which becomes 2.6 + 0.3 = 2.9. The below code is an example of decorators where we just create a place holder and we can use this function to perform different functions depending on the parameters supplied to it. The need for this kind of pattern is so as to increase the functionality of a particular class [http://en.wikipedia.org/wiki/Decorator_pattern]. &lt;br /&gt;
&lt;br /&gt;
    module Decorator&lt;br /&gt;
      def initialize(decorated)&lt;br /&gt;
        @decorated = decorated&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    def method_missing(method, *args)&lt;br /&gt;
        args.empty? ? @decorated.send(method) : @decorated.send(method, args)&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
    class Whip&lt;br /&gt;
      include Decorator&lt;br /&gt;
      def cost &lt;br /&gt;
        @decorated.cost + 0.2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    class Sprinkles&lt;br /&gt;
      include Decorator&lt;br /&gt;
&lt;br /&gt;
      def cost&lt;br /&gt;
        @decorated.cost + 0.3&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    Whip.new(Coffee.new).cost&lt;br /&gt;
    #=&amp;gt; 2.2&lt;br /&gt;
    Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost &lt;br /&gt;
    #=&amp;gt; 2.9&lt;br /&gt;
&lt;br /&gt;
There are various other options to implement this design pattern. Other way to implememt the pattern is by using singleton methods and method aliases. Delegation can also be used, and it overcomes one of the most important disadvantage. We can remove add features if we are using delegation but this is not possible if we are using singleton methods and method aliases. Example for this can be found here [http://www.scribd.com/doc/2217773/Design-Patterns-in-Ruby].&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
&lt;br /&gt;
In Java, this pattern is easy to implement by dividing the various responsibilities into classes and interfaces. The below example consider all these responsibilities and have four components which are described below  &lt;br /&gt;
* Component: Defines the interface for objects that can have responsibilities added to them dynamically.&lt;br /&gt;
* ConcreteComponent: Defines an object to which additional responsibilities can be attached.&lt;br /&gt;
* Decorator: maintains a reference to a Component object and defines an interface that conforms to Component's interface.&lt;br /&gt;
* ConcreteDecorator: adds responsibilities to the component.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface IComponent {&lt;br /&gt;
    public void doStuff();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete component&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class Component implements IComponent{&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    System.out.println(&amp;quot;Do Suff&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Decorator&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface Decorator extends IComponent {&lt;br /&gt;
    public void addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete Decorator ('''Extends IComponent''')&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class ConcreteDecorator implements Decorator {&lt;br /&gt;
    IComponent component;&lt;br /&gt;
    public ConcreteDecorator(IComponent component) {&lt;br /&gt;
    super();&lt;br /&gt;
    this.component = component;&lt;br /&gt;
    }&lt;br /&gt;
    public void addedBehavior() {&lt;br /&gt;
    System.out.println(&amp;quot;Decorator does some stuff too&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    component.doStuff();&lt;br /&gt;
    addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
The Client&lt;br /&gt;
&lt;br /&gt;
    import decorator.*;&lt;br /&gt;
    public class Client {&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
    IComponent comp = new Component();&lt;br /&gt;
    Decorator decorator = new ConcreteDecorator(comp);&lt;br /&gt;
    decorator.doStuff();&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
==Comparison of implementations==&lt;br /&gt;
&lt;br /&gt;
Ruby provides different options to implement Decorator pattern like method_missing, delegation and alias methods. This provides flexibility to the user to implement any possible way depending on the requirements and features needed. But in Java, there is more clearer approach using the components provided in the example. It is a straight forward approach. But different options provided by Ruby make it much better than Java.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages like Javascript, decorator pattern can be implemented with no interfaces or traditional OOP inheritance. With simple overriding but this approach is difficult to implement [http://en.wikipedia.org/wiki/Decorator_pattern#JavaScript].&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
We have seen four design patterns Factory design pattern, Abstract Factory design pattern, Iterator design pattern and Decorator Design Pattern. We have chosen these patterns as they are widely used and Ruby has in-built implementations of these. We have mainly tried to compare Ruby and Java but also specified tips about other languages like PHP, C# and Javascript. In Ruby implementing these design patterns is simple and easy because of its main feature of private class objects, unbounded polymorphism and duck typing [http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf]. In Java all the features are mainly implemented through interfaces and classes. This has several disadvantages like increase in code complexity, size and is generally confusing and tedious to trace or understand the code.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf Design Patterns]&lt;br /&gt;
#[http://www.patterndepot.com/put/8/JavaPatterns.htm Design Patterns Java Companion James W Cooper]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 Wiki Design Patterns]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory Method]&lt;br /&gt;
#[http://sourcemaking.com/design_patterns/abstract_factory SourceMaking explains Abstract Factory]&lt;br /&gt;
#[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf Abstract Factory Example in Java]&lt;br /&gt;
#[http://www.dofactory.com/Patterns/PatternAbstract.aspx Abstract Factory explained]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Iterator_pattern Iterator Pattern]&lt;br /&gt;
#[http://sourcemaking.com/design_patterns/iterator Sourcemaking explains Iterator method]&lt;br /&gt;
#[http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf Iterator method explained]&lt;br /&gt;
#[http://www.dofactory.com/Patterns/PatternIterator.aspx DoFactory explains Iterator pattern]&lt;br /&gt;
#[http://us3.php.net/manual/en/language.oop5.iterations.php Iterator pattern for PHP]&lt;br /&gt;
#[http://www.patterndepot.com/put/8/Decorator.pdf Decorator Pattern]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Decorator_pattern Wiki Decorator Pattern]&lt;br /&gt;
#[http://www.scribd.com/doc/2217773/Design-Patterns-in-Ruby Design Patterns in Ruby]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Decorator_pattern#JavaScript Design Patterns Javascript]&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=23276</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 11 zv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=23276"/>
		<updated>2009-10-09T00:24:46Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Factory */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''What facilities does Ruby offer that makes it easier to realize other GoF (and other) patterns that we did not cover in class? The key idea here is to explore how Ruby can implement these patterns more efficiently or transparently than static (or other dynamic) o-o languages.''&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Before starting off with design patterns for Ruby we need to define what a design pattern is, Design patterns can be described as &amp;quot;a general reusable solution to a commonly occurring problem in software design.&amp;quot; [http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29]&lt;br /&gt;
&amp;quot;The idea of design patterns is to not to reinvent the wheel but to solve the current problems by using solutions that have worked in the past&amp;quot; [http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf]. A design pattern names, abstracts, and identifies the key aspects of a common design structure that make it useful for creating a reusable object-oriented design. It helps to identify the classes and instances and the way they collaborate with each other to form a solution to a problem. Design patterns can be classified into 3 parts [http://en.wikipedia.org/wiki/Creational_pattern Creational], [http://en.wikipedia.org/wiki/Structural_pattern Structural], [http://en.wikipedia.org/wiki/Behavioral_pattern Behavioral] [http://www.patterndepot.com/put/8/JavaPatterns.htm].&lt;br /&gt;
&lt;br /&gt;
=Factory Design Pattern=&lt;br /&gt;
==What is Factory Design Pattern==&lt;br /&gt;
The factory design pattern is an object oriented design pattern. It is a creational design pattern and deals with the issues faced in creating objects.&lt;br /&gt;
The main goal of this implementation is to isolate the code that creates the class form the concrete implementation of that class. Ruby example for the same is given below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Factory Example in Ruby==&lt;br /&gt;
&lt;br /&gt;
    class GearFactory&lt;br /&gt;
      def new() &lt;br /&gt;
        if ( ... some condition )&lt;br /&gt;
           return Sprocket.new()&lt;br /&gt;
        else&lt;br /&gt;
           return Cog().new()&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Our client class now becomes:&lt;br /&gt;
    class GearUser &lt;br /&gt;
      def doSomething(factory )&lt;br /&gt;
        ...&lt;br /&gt;
      my_gear = factory.new()&lt;br /&gt;
        ...&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The above code does not have to distinguish between a factory and an ordinary class. We can call the class using the following code.&lt;br /&gt;
    client.doSomething(GearFactory.new)          #Use the factory&lt;br /&gt;
    client.doSomething(Cog)                      #Use the Cog class&lt;br /&gt;
    client.doSomething(Sprocket)                 #Use the Sprocket class&lt;br /&gt;
&lt;br /&gt;
==Factory Example in Java==&lt;br /&gt;
In java the Factory implementation is done using interfaces. Declaring them as interfaces helps to maintain a general overview and not depending on the type of factory object that needs to be used. All of these can be placed in a huge factory in a client application.&lt;br /&gt;
A well known example for Java Factory is the UI toolkits that are designed to run on different windowing systems.&lt;br /&gt;
    interface ScrollBar { ... }&lt;br /&gt;
    interface MenuBar   { ... }&lt;br /&gt;
    ...&lt;br /&gt;
And associated classes implementing them on different windowing systems:&lt;br /&gt;
&lt;br /&gt;
    class MotifScrollBar implements ScrollBar { ... }&lt;br /&gt;
    class Win95ScrollBar implements ScrollBar { ... }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
And a factory interface that also doesn't commit to representation:&lt;br /&gt;
&lt;br /&gt;
    interface Factory {&lt;br /&gt;
      public abstract ScrollBar newScrollBar();&lt;br /&gt;
      public abstract MenuBar   newMenuBar();&lt;br /&gt;
      ... &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
But implementation classes that do:&lt;br /&gt;
&lt;br /&gt;
    class MotifFactory implements Factory {&lt;br /&gt;
      public ScrollBar newScrollBar() { return new MotifScrollBar(...); }&lt;br /&gt;
      ...&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory Pattern=&lt;br /&gt;
==What is Abstract Factory Pattern?==&lt;br /&gt;
Abstract Factory Design Pattern encapsulates a group of objects that have common theme. It implements a generic interface to create these objects that are part of the theme. It does not care about the details of the implementation of these objects. The Abstract Factory pattern, a class delegates the responsibility of object instantiation to another object via composition. It is a type of Creational pattern [http://en.wikipedia.org/wiki/Abstract_factory_pattern] “Provide an interface for creating families of related or dependent objects without specifying their concrete classes” [http://sourcemaking.com/design_patterns/abstract_factory]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
Ruby automatically implements the Abstract Factory pattern as Class Objects. All Class objects have the same interface: the new method of each class object creates new instances of the class. Thus the code can pass references to class objects around and they can be used to call new method without knowing the exact type of object that the class creates.&lt;br /&gt;
&lt;br /&gt;
    Class Foo; end&lt;br /&gt;
    Class Bar, end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is the use of Abstract Factory Pattern&lt;br /&gt;
    &lt;br /&gt;
    def create_something(factory)&lt;br /&gt;
	new_object = factory.new&lt;br /&gt;
	puts &amp;quot;created a new #{new_object.class} with a factory&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Here we select a factory to use&lt;br /&gt;
    Create_something(Foo)&lt;br /&gt;
    Create_something(Bar)&lt;br /&gt;
&lt;br /&gt;
Output of the code:&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Foo with a factory&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Bar with a factory&lt;br /&gt;
&lt;br /&gt;
The create_something method is creating objects through an abstract interface. It does not have details about implementation used to create these objects. Thus the use of create_something() is used to shield the rest of the code from that knowledge.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
In Java, implementing  Abstract Factory design pattern we need to create a class which has method who defers creation of product objects to its concrete class. This class then needs to be ”extended” by the client class which uses only these interfaces to create objects of concrete class&lt;br /&gt;
[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf]. In Java, Abstract Factory defines a different method for the creation of each product it can produce. The following example shows an implementation of Abstract Factory design pattern in Java. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   public class FactoryFmProto {&lt;br /&gt;
  static class Expression {&lt;br /&gt;
   protected String str;&lt;br /&gt;
   public Expression( String s ) { str = s; }&lt;br /&gt;
   public Expression cloan()     { return null; }&lt;br /&gt;
   public String     toString()  { return str; }&lt;br /&gt;
  }&lt;br /&gt;
  static abstract class Factory {&lt;br /&gt;
   protected Expression prototype = null;&lt;br /&gt;
   public Expression makePhrase() { return prototype.cloan(); }&lt;br /&gt;
   public abstract Expression makeCompromise();&lt;br /&gt;
   public abstract Expression makeGrade();&lt;br /&gt;
  }&lt;br /&gt;
  static class PCFactory extends Factory {&lt;br /&gt;
   public PCFactory() { prototype = new PCPhrase(); }&lt;br /&gt;
   public Expression makeCompromise() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;do it your way, any way, or no way\&amp;quot;&amp;quot; ); }&lt;br /&gt;
   public Expression makeGrade() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;you pass, self-esteem intact\&amp;quot;&amp;quot; ); }&lt;br /&gt;
  }&lt;br /&gt;
   static class NotPCFactory extends Factory {&lt;br /&gt;
   public NotPCFactory() { prototype = new NotPCPhrase(); }&lt;br /&gt;
   public Expression makeCompromise() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;my way, or the highway\&amp;quot;&amp;quot; ); }&lt;br /&gt;
   public Expression makeGrade() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;take test, deal with the results\&amp;quot;&amp;quot; ); }&lt;br /&gt;
  }&lt;br /&gt;
   public static void main( String[] args ) {&lt;br /&gt;
   Factory factory;&lt;br /&gt;
   if (args.length &amp;gt; 0) factory = new PCFactory();&lt;br /&gt;
   else                 factory = new NotPCFactory();&lt;br /&gt;
   for (int i=0; i &amp;lt; 3; i++) System.out.print( factory.makePhrase() + &amp;quot;  &amp;quot; );&lt;br /&gt;
   System.out.println();&lt;br /&gt;
   System.out.println( factory.makeCompromise() );&lt;br /&gt;
   System.out.println( factory.makeGrade() );&lt;br /&gt;
  }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
Basically, Java and Ruby, both can implement Abstract Factory design pattern. But the more important point is the simplicity by which they can apply it. Ruby automatically implements the Abstract Factory pattern as Class Objects. But Java needs helps of interfaces and classes to do so. Thus Java implementation needs a well defined interface to do so but in Ruby it is directly implemented because of private class object property.&lt;br /&gt;
&lt;br /&gt;
Similarly, C# demonstrates the Abstract Factory pattern by creating parallel hierarchies of objects. Object creation has been abstracted and there is no need for hard-coded class names in the client code. This property helps C# to have better implementation than Java. In .NET, there are built in features such as, generics, reflection, object initializers, automatic properties, etc for implementation [http://www.dofactory.com/Patterns/PatternAbstract.aspx].&lt;br /&gt;
&lt;br /&gt;
=Iterator Design Pattern=&lt;br /&gt;
==What is Iterator Design Pattern?==&lt;br /&gt;
The Iterator design pattern allows an object to encapsulate the internal structure and allows the user to move through the collection of data using standard interface. It is one of the simplest and most frequently used design pattern. It is a type of Behavioral design pattern [http://en.wikipedia.org/wiki/Iterator_pattern]. “Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.” [http://sourcemaking.com/design_patterns/iterator]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
Ruby implements iterators with blocks and the ‘each’ method, and with ‘for..in’ statements. For example consider the following example;&lt;br /&gt;
&lt;br /&gt;
    def print_element(container)&lt;br /&gt;
    	Container.each {|o| puts o.inspect }&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    list = [1,2,2,3]&lt;br /&gt;
    hash = {“a”=&amp;gt;1, “b”=&amp;gt;2,”c”=&amp;gt;3, “d”=&amp;gt;4 }&lt;br /&gt;
    print_elements list&lt;br /&gt;
    print_elements hash&lt;br /&gt;
&lt;br /&gt;
The output of the code is,&lt;br /&gt;
    1&lt;br /&gt;
    2&lt;br /&gt;
    3&lt;br /&gt;
    4&lt;br /&gt;
    [“a”,1]&lt;br /&gt;
    [“b”,2]&lt;br /&gt;
    [“c”,3]&lt;br /&gt;
    [“d”,4]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
&lt;br /&gt;
In Java, we can implement Iterator design pattern by using java.util.Enumeration interface which returns a reference to an object. Furthermore, Hashes and Vector have limited capabilities which help simple traversing. Java JDK 1.2 introduced a new Collections package with more aggregate classes, including sets, lists, maps and an Iterator interface. If we wanted to start implementing Iterator design pattern from start, then it would again involve having an interface for accessing and traversing the elements which is further implemented by the concrete class.  Thus a class who needs to access the list will need to call the interface class [http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf]. For example, consider the following scenario where iterator.First() and iterator.Next(), has been implemented in the class ListIterator.&lt;br /&gt;
&lt;br /&gt;
    ...&lt;br /&gt;
    List list = new List();&lt;br /&gt;
    ...&lt;br /&gt;
    ListIterator iterator = new ListIterator(list);&lt;br /&gt;
    iterator.First();&lt;br /&gt;
    while (!iterator.IsDone()) {&lt;br /&gt;
    Object item = iterator.CurrentItem();&lt;br /&gt;
    // Code here to process item.&lt;br /&gt;
    iterator.Next();&lt;br /&gt;
    }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
&lt;br /&gt;
Overall implementation of Iterator design pattern in each object oriented language is simple as it is a basis feature of objects. But in general, the Ruby implementation is more concise. Ruby has built-in iterators which make it easier to implement Iterator pattern for any kind of object. It hides the structure and there is no need for having implementation for those methods in the class. But in Java, the built-in library function help to create easier and clear implementations. C# also has similar implementation as Java for this design pattern [http://www.dofactory.com/Patterns/PatternIterator.aspx]. &lt;br /&gt;
&lt;br /&gt;
In PHP, using an object in a foreach structure will traverse the public values. There are also many multiple Iterator classes available to allow us to iterate through common lists, such as directories, XML structures and recursive arrays. We can also implement our own interfaces depending on requirement [http://us3.php.net/manual/en/language.oop5.iterations.php].&lt;br /&gt;
&lt;br /&gt;
=Decorator Pattern=&lt;br /&gt;
&lt;br /&gt;
This pattern is used to increase the functionality of the existing object dynamically. Suppose we have a program that uses eight objects, but three of them need an additional feature. We could create derived class for these objects having the additional features but then we can create a Decorator class which will add any specific kind of feature required [http://www.patterndepot.com/put/8/Decorator.pdf]. It is a type of behavioral pattern.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
&lt;br /&gt;
Generic decorators can be implmented by using the method_missing method. This method is called when an object receives a message that it does not have a method fo. The method_missing method can forward the message on to other object and wrap additional behavior around the call. In this example we talk about how a coffee class can have many addtions to it like coffee with cream, sprinkles, milk etc and creating a class for each of them will not be the correct solution.In this example the cost can be calculated according to what is sent to it.Cost of the coffee is 2 and the cost of White coffee (coffee + milk) = 2.4. So what happens when we execute the Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost we get the result as 2.9 as the cost of the coffee is 2, the decorator object (now only coffee) is sent to the Milk and it becomes 2.4, which now is then sent to the Whip which is going to be 2.4 + 02 = 2.6 and finally to Sprinkles which becomes 2.6 + 0.3 = 2.9. The below code is an example of decorators where we just create a place holder and we can use this function to perform different functions depending on the parameters supplied to it. The need for this kind of pattern is so as to increase the functionality of a particular class [http://en.wikipedia.org/wiki/Decorator_pattern]. &lt;br /&gt;
&lt;br /&gt;
    module Decorator&lt;br /&gt;
      def initialize(decorated)&lt;br /&gt;
        @decorated = decorated&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    def method_missing(method, *args)&lt;br /&gt;
        args.empty? ? @decorated.send(method) : @decorated.send(method, args)&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
    class Whip&lt;br /&gt;
      include Decorator&lt;br /&gt;
      def cost &lt;br /&gt;
        @decorated.cost + 0.2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    class Sprinkles&lt;br /&gt;
      include Decorator&lt;br /&gt;
&lt;br /&gt;
      def cost&lt;br /&gt;
        @decorated.cost + 0.3&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    Whip.new(Coffee.new).cost&lt;br /&gt;
    #=&amp;gt; 2.2&lt;br /&gt;
    Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost &lt;br /&gt;
    #=&amp;gt; 2.9&lt;br /&gt;
&lt;br /&gt;
There are various other options to implement this design pattern. Other way to implememt the pattern is by using singleton methods and method aliases. Delegation can also be used, and it overcomes one of the most important disadvantage. We can remove add features if we are using delegation but this is not possible if we are using singleton methods and method aliases. Example for this can be found here [http://www.scribd.com/doc/2217773/Design-Patterns-in-Ruby].&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
&lt;br /&gt;
In Java, this pattern is easy to implement by dividing the various responsibilities into classes and interfaces. The below example consider all these responsibilities and have four components which are described below  &lt;br /&gt;
* Component: Defines the interface for objects that can have responsibilities added to them dynamically.&lt;br /&gt;
* ConcreteComponent: Defines an object to which additional responsibilities can be attached.&lt;br /&gt;
* Decorator: maintains a reference to a Component object and defines an interface that conforms to Component's interface.&lt;br /&gt;
* ConcreteDecorator: adds responsibilities to the component.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface IComponent {&lt;br /&gt;
    public void doStuff();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete component&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class Component implements IComponent{&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    System.out.println(&amp;quot;Do Suff&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Decorator&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface Decorator extends IComponent {&lt;br /&gt;
    public void addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete Decorator ('''Extends IComponent''')&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class ConcreteDecorator implements Decorator {&lt;br /&gt;
    IComponent component;&lt;br /&gt;
    public ConcreteDecorator(IComponent component) {&lt;br /&gt;
    super();&lt;br /&gt;
    this.component = component;&lt;br /&gt;
    }&lt;br /&gt;
    public void addedBehavior() {&lt;br /&gt;
    System.out.println(&amp;quot;Decorator does some stuff too&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    component.doStuff();&lt;br /&gt;
    addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
The Client&lt;br /&gt;
&lt;br /&gt;
    import decorator.*;&lt;br /&gt;
    public class Client {&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
    IComponent comp = new Component();&lt;br /&gt;
    Decorator decorator = new ConcreteDecorator(comp);&lt;br /&gt;
    decorator.doStuff();&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
==Comparison of implementations==&lt;br /&gt;
&lt;br /&gt;
Ruby provides different options to implement Decorator pattern like method_missing, delegation and alias methods. This provides flexibility to the user to implement any possible way depending on the requirements and features needed. But in Java, there is more clearer approach using the components provided in the example. It is a straight forward approach. But different options provided by Ruby make it much better than Java.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages like Javascript, decorator pattern can be implemented with no interfaces or traditional OOP inheritance. With simple overriding but this approach is difficult to implement [http://en.wikipedia.org/wiki/Decorator_pattern#JavaScript].&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
We have seen four design patterns Factory design pattern, Abstract Factory design pattern, Iterator design pattern and Decorator Design Pattern. We have chosen these patterns as they are widely used and Ruby has in-built implementations of these. We have mainly tried to compare Ruby and Java but also specified tips about other languages like PHP, C# and Javascript. In Ruby implementing these design patterns is simple and easy because of its main feature of private class objects, unbounded polymorphism and duck typing [http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf]. In Java all the features are mainly implemented through interfaces and classes. This has several disadvantages like increase in code complexity, size and is generally confusing and tedious to trace or understand the code.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf Design Patterns]&lt;br /&gt;
#[http://www.patterndepot.com/put/8/JavaPatterns.htm Design Patterns Java Companion James W Cooper]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 Wiki Design Patterns]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory Method]&lt;br /&gt;
#[http://sourcemaking.com/design_patterns/abstract_factory SourceMaking explains Abstract Factory]&lt;br /&gt;
#[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf Abstract Factory Example in Java]&lt;br /&gt;
#[http://www.dofactory.com/Patterns/PatternAbstract.aspx Abstract Factory explained]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Iterator_pattern Iterator Pattern]&lt;br /&gt;
#[http://sourcemaking.com/design_patterns/iterator Sourcemaking explains Iterator method]&lt;br /&gt;
#[http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf Iterator method explained]&lt;br /&gt;
#[http://www.dofactory.com/Patterns/PatternIterator.aspx DoFactory explains Iterator pattern]&lt;br /&gt;
#[http://us3.php.net/manual/en/language.oop5.iterations.php Iterator pattern for PHP]&lt;br /&gt;
#[http://www.patterndepot.com/put/8/Decorator.pdf Decorator Pattern]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Decorator_pattern Wiki Decorator Pattern]&lt;br /&gt;
#[http://www.scribd.com/doc/2217773/Design-Patterns-in-Ruby Design Patterns in Ruby]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Decorator_pattern#JavaScript Design Patterns Javascript]&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=23275</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 11 zv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=23275"/>
		<updated>2009-10-09T00:22:52Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Factory Example in Ruby */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''What facilities does Ruby offer that makes it easier to realize other GoF (and other) patterns that we did not cover in class? The key idea here is to explore how Ruby can implement these patterns more efficiently or transparently than static (or other dynamic) o-o languages.''&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Before starting off with design patterns for Ruby we need to define what a design pattern is, Design patterns can be described as &amp;quot;a general reusable solution to a commonly occurring problem in software design.&amp;quot; [http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29]&lt;br /&gt;
&amp;quot;The idea of design patterns is to not to reinvent the wheel but to solve the current problems by using solutions that have worked in the past&amp;quot; [http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf]. A design pattern names, abstracts, and identifies the key aspects of a common design structure that make it useful for creating a reusable object-oriented design. It helps to identify the classes and instances and the way they collaborate with each other to form a solution to a problem. Design patterns can be classified into 3 parts [http://en.wikipedia.org/wiki/Creational_pattern Creational], [http://en.wikipedia.org/wiki/Structural_pattern Structural], [http://en.wikipedia.org/wiki/Behavioral_pattern Behavioral] [http://www.patterndepot.com/put/8/JavaPatterns.htm].&lt;br /&gt;
&lt;br /&gt;
=Factory=&lt;br /&gt;
The factory design pattern is an object oriented design pattern. It is a creational design pattern and deals with the issues faced in creating objects.&lt;br /&gt;
The main goal of this implementation is to isolate the code that creates the class form the concrete implementation of that class. Ruby example for the same is given below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Factory Example in Ruby==&lt;br /&gt;
&lt;br /&gt;
    class GearFactory&lt;br /&gt;
      def new() &lt;br /&gt;
        if ( ... some condition )&lt;br /&gt;
           return Sprocket.new()&lt;br /&gt;
        else&lt;br /&gt;
           return Cog().new()&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Our client class now becomes:&lt;br /&gt;
    class GearUser &lt;br /&gt;
      def doSomething(factory )&lt;br /&gt;
        ...&lt;br /&gt;
      my_gear = factory.new()&lt;br /&gt;
        ...&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The above code does not have to distinguish between a factory and an ordinary class. We can call the class using the following code.&lt;br /&gt;
    client.doSomething(GearFactory.new)          #Use the factory&lt;br /&gt;
    client.doSomething(Cog)                      #Use the Cog class&lt;br /&gt;
    client.doSomething(Sprocket)                 #Use the Sprocket class&lt;br /&gt;
&lt;br /&gt;
==Factory Example in Java==&lt;br /&gt;
In java the Factory implementation is done using interfaces. Declaring them as interfaces helps to maintain a general overview and not depending on the type of factory object that needs to be used. All of these can be placed in a huge factory in a client application.&lt;br /&gt;
A well known example for Java Factory is the UI toolkits that are designed to run on different windowing systems.&lt;br /&gt;
    interface ScrollBar { ... }&lt;br /&gt;
    interface MenuBar   { ... }&lt;br /&gt;
    ...&lt;br /&gt;
And associated classes implementing them on different windowing systems:&lt;br /&gt;
&lt;br /&gt;
    class MotifScrollBar implements ScrollBar { ... }&lt;br /&gt;
    class Win95ScrollBar implements ScrollBar { ... }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
And a factory interface that also doesn't commit to representation:&lt;br /&gt;
&lt;br /&gt;
    interface Factory {&lt;br /&gt;
      public abstract ScrollBar newScrollBar();&lt;br /&gt;
      public abstract MenuBar   newMenuBar();&lt;br /&gt;
      ... &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
But implementation classes that do:&lt;br /&gt;
&lt;br /&gt;
    class MotifFactory implements Factory {&lt;br /&gt;
      public ScrollBar newScrollBar() { return new MotifScrollBar(...); }&lt;br /&gt;
      ...&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory Pattern=&lt;br /&gt;
==What is Abstract Factory Pattern?==&lt;br /&gt;
Abstract Factory Design Pattern encapsulates a group of objects that have common theme. It implements a generic interface to create these objects that are part of the theme. It does not care about the details of the implementation of these objects. The Abstract Factory pattern, a class delegates the responsibility of object instantiation to another object via composition. It is a type of Creational pattern [http://en.wikipedia.org/wiki/Abstract_factory_pattern] “Provide an interface for creating families of related or dependent objects without specifying their concrete classes” [http://sourcemaking.com/design_patterns/abstract_factory]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
Ruby automatically implements the Abstract Factory pattern as Class Objects. All Class objects have the same interface: the new method of each class object creates new instances of the class. Thus the code can pass references to class objects around and they can be used to call new method without knowing the exact type of object that the class creates.&lt;br /&gt;
&lt;br /&gt;
    Class Foo; end&lt;br /&gt;
    Class Bar, end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is the use of Abstract Factory Pattern&lt;br /&gt;
    &lt;br /&gt;
    def create_something(factory)&lt;br /&gt;
	new_object = factory.new&lt;br /&gt;
	puts &amp;quot;created a new #{new_object.class} with a factory&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Here we select a factory to use&lt;br /&gt;
    Create_something(Foo)&lt;br /&gt;
    Create_something(Bar)&lt;br /&gt;
&lt;br /&gt;
Output of the code:&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Foo with a factory&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Bar with a factory&lt;br /&gt;
&lt;br /&gt;
The create_something method is creating objects through an abstract interface. It does not have details about implementation used to create these objects. Thus the use of create_something() is used to shield the rest of the code from that knowledge.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
In Java, implementing  Abstract Factory design pattern we need to create a class which has method who defers creation of product objects to its concrete class. This class then needs to be ”extended” by the client class which uses only these interfaces to create objects of concrete class&lt;br /&gt;
[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf]. In Java, Abstract Factory defines a different method for the creation of each product it can produce. The following example shows an implementation of Abstract Factory design pattern in Java. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   public class FactoryFmProto {&lt;br /&gt;
  static class Expression {&lt;br /&gt;
   protected String str;&lt;br /&gt;
   public Expression( String s ) { str = s; }&lt;br /&gt;
   public Expression cloan()     { return null; }&lt;br /&gt;
   public String     toString()  { return str; }&lt;br /&gt;
  }&lt;br /&gt;
  static abstract class Factory {&lt;br /&gt;
   protected Expression prototype = null;&lt;br /&gt;
   public Expression makePhrase() { return prototype.cloan(); }&lt;br /&gt;
   public abstract Expression makeCompromise();&lt;br /&gt;
   public abstract Expression makeGrade();&lt;br /&gt;
  }&lt;br /&gt;
  static class PCFactory extends Factory {&lt;br /&gt;
   public PCFactory() { prototype = new PCPhrase(); }&lt;br /&gt;
   public Expression makeCompromise() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;do it your way, any way, or no way\&amp;quot;&amp;quot; ); }&lt;br /&gt;
   public Expression makeGrade() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;you pass, self-esteem intact\&amp;quot;&amp;quot; ); }&lt;br /&gt;
  }&lt;br /&gt;
   static class NotPCFactory extends Factory {&lt;br /&gt;
   public NotPCFactory() { prototype = new NotPCPhrase(); }&lt;br /&gt;
   public Expression makeCompromise() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;my way, or the highway\&amp;quot;&amp;quot; ); }&lt;br /&gt;
   public Expression makeGrade() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;take test, deal with the results\&amp;quot;&amp;quot; ); }&lt;br /&gt;
  }&lt;br /&gt;
   public static void main( String[] args ) {&lt;br /&gt;
   Factory factory;&lt;br /&gt;
   if (args.length &amp;gt; 0) factory = new PCFactory();&lt;br /&gt;
   else                 factory = new NotPCFactory();&lt;br /&gt;
   for (int i=0; i &amp;lt; 3; i++) System.out.print( factory.makePhrase() + &amp;quot;  &amp;quot; );&lt;br /&gt;
   System.out.println();&lt;br /&gt;
   System.out.println( factory.makeCompromise() );&lt;br /&gt;
   System.out.println( factory.makeGrade() );&lt;br /&gt;
  }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
Basically, Java and Ruby, both can implement Abstract Factory design pattern. But the more important point is the simplicity by which they can apply it. Ruby automatically implements the Abstract Factory pattern as Class Objects. But Java needs helps of interfaces and classes to do so. Thus Java implementation needs a well defined interface to do so but in Ruby it is directly implemented because of private class object property.&lt;br /&gt;
&lt;br /&gt;
Similarly, C# demonstrates the Abstract Factory pattern by creating parallel hierarchies of objects. Object creation has been abstracted and there is no need for hard-coded class names in the client code. This property helps C# to have better implementation than Java. In .NET, there are built in features such as, generics, reflection, object initializers, automatic properties, etc for implementation [http://www.dofactory.com/Patterns/PatternAbstract.aspx].&lt;br /&gt;
&lt;br /&gt;
=Iterator Design Pattern=&lt;br /&gt;
==What is Iterator Design Pattern?==&lt;br /&gt;
The Iterator design pattern allows an object to encapsulate the internal structure and allows the user to move through the collection of data using standard interface. It is one of the simplest and most frequently used design pattern. It is a type of Behavioral design pattern [http://en.wikipedia.org/wiki/Iterator_pattern]. “Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.” [http://sourcemaking.com/design_patterns/iterator]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
Ruby implements iterators with blocks and the ‘each’ method, and with ‘for..in’ statements. For example consider the following example;&lt;br /&gt;
&lt;br /&gt;
    def print_element(container)&lt;br /&gt;
    	Container.each {|o| puts o.inspect }&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    list = [1,2,2,3]&lt;br /&gt;
    hash = {“a”=&amp;gt;1, “b”=&amp;gt;2,”c”=&amp;gt;3, “d”=&amp;gt;4 }&lt;br /&gt;
    print_elements list&lt;br /&gt;
    print_elements hash&lt;br /&gt;
&lt;br /&gt;
The output of the code is,&lt;br /&gt;
    1&lt;br /&gt;
    2&lt;br /&gt;
    3&lt;br /&gt;
    4&lt;br /&gt;
    [“a”,1]&lt;br /&gt;
    [“b”,2]&lt;br /&gt;
    [“c”,3]&lt;br /&gt;
    [“d”,4]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
&lt;br /&gt;
In Java, we can implement Iterator design pattern by using java.util.Enumeration interface which returns a reference to an object. Furthermore, Hashes and Vector have limited capabilities which help simple traversing. Java JDK 1.2 introduced a new Collections package with more aggregate classes, including sets, lists, maps and an Iterator interface. If we wanted to start implementing Iterator design pattern from start, then it would again involve having an interface for accessing and traversing the elements which is further implemented by the concrete class.  Thus a class who needs to access the list will need to call the interface class [http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf]. For example, consider the following scenario where iterator.First() and iterator.Next(), has been implemented in the class ListIterator.&lt;br /&gt;
&lt;br /&gt;
    ...&lt;br /&gt;
    List list = new List();&lt;br /&gt;
    ...&lt;br /&gt;
    ListIterator iterator = new ListIterator(list);&lt;br /&gt;
    iterator.First();&lt;br /&gt;
    while (!iterator.IsDone()) {&lt;br /&gt;
    Object item = iterator.CurrentItem();&lt;br /&gt;
    // Code here to process item.&lt;br /&gt;
    iterator.Next();&lt;br /&gt;
    }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
&lt;br /&gt;
Overall implementation of Iterator design pattern in each object oriented language is simple as it is a basis feature of objects. But in general, the Ruby implementation is more concise. Ruby has built-in iterators which make it easier to implement Iterator pattern for any kind of object. It hides the structure and there is no need for having implementation for those methods in the class. But in Java, the built-in library function help to create easier and clear implementations. C# also has similar implementation as Java for this design pattern [http://www.dofactory.com/Patterns/PatternIterator.aspx]. &lt;br /&gt;
&lt;br /&gt;
In PHP, using an object in a foreach structure will traverse the public values. There are also many multiple Iterator classes available to allow us to iterate through common lists, such as directories, XML structures and recursive arrays. We can also implement our own interfaces depending on requirement [http://us3.php.net/manual/en/language.oop5.iterations.php].&lt;br /&gt;
&lt;br /&gt;
=Decorator Pattern=&lt;br /&gt;
&lt;br /&gt;
This pattern is used to increase the functionality of the existing object dynamically. Suppose we have a program that uses eight objects, but three of them need an additional feature. We could create derived class for these objects having the additional features but then we can create a Decorator class which will add any specific kind of feature required [http://www.patterndepot.com/put/8/Decorator.pdf]. It is a type of behavioral pattern.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
&lt;br /&gt;
Generic decorators can be implmented by using the method_missing method. This method is called when an object receives a message that it does not have a method fo. The method_missing method can forward the message on to other object and wrap additional behavior around the call. In this example we talk about how a coffee class can have many addtions to it like coffee with cream, sprinkles, milk etc and creating a class for each of them will not be the correct solution.In this example the cost can be calculated according to what is sent to it.Cost of the coffee is 2 and the cost of White coffee (coffee + milk) = 2.4. So what happens when we execute the Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost we get the result as 2.9 as the cost of the coffee is 2, the decorator object (now only coffee) is sent to the Milk and it becomes 2.4, which now is then sent to the Whip which is going to be 2.4 + 02 = 2.6 and finally to Sprinkles which becomes 2.6 + 0.3 = 2.9. The below code is an example of decorators where we just create a place holder and we can use this function to perform different functions depending on the parameters supplied to it. The need for this kind of pattern is so as to increase the functionality of a particular class [http://en.wikipedia.org/wiki/Decorator_pattern]. &lt;br /&gt;
&lt;br /&gt;
    module Decorator&lt;br /&gt;
      def initialize(decorated)&lt;br /&gt;
        @decorated = decorated&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    def method_missing(method, *args)&lt;br /&gt;
        args.empty? ? @decorated.send(method) : @decorated.send(method, args)&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
    class Whip&lt;br /&gt;
      include Decorator&lt;br /&gt;
      def cost &lt;br /&gt;
        @decorated.cost + 0.2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    class Sprinkles&lt;br /&gt;
      include Decorator&lt;br /&gt;
&lt;br /&gt;
      def cost&lt;br /&gt;
        @decorated.cost + 0.3&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    Whip.new(Coffee.new).cost&lt;br /&gt;
    #=&amp;gt; 2.2&lt;br /&gt;
    Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost &lt;br /&gt;
    #=&amp;gt; 2.9&lt;br /&gt;
&lt;br /&gt;
There are various other options to implement this design pattern. Other way to implememt the pattern is by using singleton methods and method aliases. Delegation can also be used, and it overcomes one of the most important disadvantage. We can remove add features if we are using delegation but this is not possible if we are using singleton methods and method aliases. Example for this can be found here [http://www.scribd.com/doc/2217773/Design-Patterns-in-Ruby].&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
&lt;br /&gt;
In Java, this pattern is easy to implement by dividing the various responsibilities into classes and interfaces. The below example consider all these responsibilities and have four components which are described below  &lt;br /&gt;
* Component: Defines the interface for objects that can have responsibilities added to them dynamically.&lt;br /&gt;
* ConcreteComponent: Defines an object to which additional responsibilities can be attached.&lt;br /&gt;
* Decorator: maintains a reference to a Component object and defines an interface that conforms to Component's interface.&lt;br /&gt;
* ConcreteDecorator: adds responsibilities to the component.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface IComponent {&lt;br /&gt;
    public void doStuff();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete component&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class Component implements IComponent{&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    System.out.println(&amp;quot;Do Suff&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Decorator&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface Decorator extends IComponent {&lt;br /&gt;
    public void addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete Decorator ('''Extends IComponent''')&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class ConcreteDecorator implements Decorator {&lt;br /&gt;
    IComponent component;&lt;br /&gt;
    public ConcreteDecorator(IComponent component) {&lt;br /&gt;
    super();&lt;br /&gt;
    this.component = component;&lt;br /&gt;
    }&lt;br /&gt;
    public void addedBehavior() {&lt;br /&gt;
    System.out.println(&amp;quot;Decorator does some stuff too&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    component.doStuff();&lt;br /&gt;
    addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
The Client&lt;br /&gt;
&lt;br /&gt;
    import decorator.*;&lt;br /&gt;
    public class Client {&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
    IComponent comp = new Component();&lt;br /&gt;
    Decorator decorator = new ConcreteDecorator(comp);&lt;br /&gt;
    decorator.doStuff();&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
==Comparison of implementations==&lt;br /&gt;
&lt;br /&gt;
Ruby provides different options to implement Decorator pattern like method_missing, delegation and alias methods. This provides flexibility to the user to implement any possible way depending on the requirements and features needed. But in Java, there is more clearer approach using the components provided in the example. It is a straight forward approach. But different options provided by Ruby make it much better than Java.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages like Javascript, decorator pattern can be implemented with no interfaces or traditional OOP inheritance. With simple overriding but this approach is difficult to implement [http://en.wikipedia.org/wiki/Decorator_pattern#JavaScript].&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
We have seen four design patterns Factory design pattern, Abstract Factory design pattern, Iterator design pattern and Decorator Design Pattern. We have chosen these patterns as they are widely used and Ruby has in-built implementations of these. We have mainly tried to compare Ruby and Java but also specified tips about other languages like PHP, C# and Javascript. In Ruby implementing these design patterns is simple and easy because of its main feature of private class objects, unbounded polymorphism and duck typing [http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf]. In Java all the features are mainly implemented through interfaces and classes. This has several disadvantages like increase in code complexity, size and is generally confusing and tedious to trace or understand the code.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf Design Patterns]&lt;br /&gt;
#[http://www.patterndepot.com/put/8/JavaPatterns.htm Design Patterns Java Companion James W Cooper]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 Wiki Design Patterns]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory Method]&lt;br /&gt;
#[http://sourcemaking.com/design_patterns/abstract_factory SourceMaking explains Abstract Factory]&lt;br /&gt;
#[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf Abstract Factory Example in Java]&lt;br /&gt;
#[http://www.dofactory.com/Patterns/PatternAbstract.aspx Abstract Factory explained]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Iterator_pattern Iterator Pattern]&lt;br /&gt;
#[http://sourcemaking.com/design_patterns/iterator Sourcemaking explains Iterator method]&lt;br /&gt;
#[http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf Iterator method explained]&lt;br /&gt;
#[http://www.dofactory.com/Patterns/PatternIterator.aspx DoFactory explains Iterator pattern]&lt;br /&gt;
#[http://us3.php.net/manual/en/language.oop5.iterations.php Iterator pattern for PHP]&lt;br /&gt;
#[http://www.patterndepot.com/put/8/Decorator.pdf Decorator Pattern]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Decorator_pattern Wiki Decorator Pattern]&lt;br /&gt;
#[http://www.scribd.com/doc/2217773/Design-Patterns-in-Ruby Design Patterns in Ruby]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Decorator_pattern#JavaScript Design Patterns Javascript]&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=23273</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 11 zv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=23273"/>
		<updated>2009-10-09T00:22:21Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Factory */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''What facilities does Ruby offer that makes it easier to realize other GoF (and other) patterns that we did not cover in class? The key idea here is to explore how Ruby can implement these patterns more efficiently or transparently than static (or other dynamic) o-o languages.''&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Before starting off with design patterns for Ruby we need to define what a design pattern is, Design patterns can be described as &amp;quot;a general reusable solution to a commonly occurring problem in software design.&amp;quot; [http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29]&lt;br /&gt;
&amp;quot;The idea of design patterns is to not to reinvent the wheel but to solve the current problems by using solutions that have worked in the past&amp;quot; [http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf]. A design pattern names, abstracts, and identifies the key aspects of a common design structure that make it useful for creating a reusable object-oriented design. It helps to identify the classes and instances and the way they collaborate with each other to form a solution to a problem. Design patterns can be classified into 3 parts [http://en.wikipedia.org/wiki/Creational_pattern Creational], [http://en.wikipedia.org/wiki/Structural_pattern Structural], [http://en.wikipedia.org/wiki/Behavioral_pattern Behavioral] [http://www.patterndepot.com/put/8/JavaPatterns.htm].&lt;br /&gt;
&lt;br /&gt;
=Factory=&lt;br /&gt;
The factory design pattern is an object oriented design pattern. It is a creational design pattern and deals with the issues faced in creating objects.&lt;br /&gt;
The main goal of this implementation is to isolate the code that creates the class form the concrete implementation of that class. Ruby example for the same is given below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Factory Example in Ruby==&lt;br /&gt;
&lt;br /&gt;
    class GearFactory&lt;br /&gt;
      def new() &lt;br /&gt;
        if ( ... some condition )&lt;br /&gt;
           return Sprocket.new()&lt;br /&gt;
        else&lt;br /&gt;
           return Cog().new()&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Our client class now becomes:&lt;br /&gt;
    class GearUser &lt;br /&gt;
      def doSomething(factory )&lt;br /&gt;
        ...&lt;br /&gt;
      my_gear = factory.new()&lt;br /&gt;
        ...&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The above code does not have to distinguish between a factory and an ordinary class. We can call the class using the followijng code.&lt;br /&gt;
    client.doSomething(GearFactory.new)          #Use the factory&lt;br /&gt;
    client.doSomething(Cog)                      #Use the Cog class&lt;br /&gt;
    client.doSomething(Sprocket)                 #Use the Sprocket class&lt;br /&gt;
&lt;br /&gt;
==Factory Example in Java==&lt;br /&gt;
In java the Factory implementation is done using interfaces. Declaring them as interfaces helps to maintain a general overview and not depending on the type of factory object that needs to be used. All of these can be placed in a huge factory in a client application.&lt;br /&gt;
A well known example for Java Factory is the UI toolkits that are designed to run on different windowing systems.&lt;br /&gt;
    interface ScrollBar { ... }&lt;br /&gt;
    interface MenuBar   { ... }&lt;br /&gt;
    ...&lt;br /&gt;
And associated classes implementing them on different windowing systems:&lt;br /&gt;
&lt;br /&gt;
    class MotifScrollBar implements ScrollBar { ... }&lt;br /&gt;
    class Win95ScrollBar implements ScrollBar { ... }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
And a factory interface that also doesn't commit to representation:&lt;br /&gt;
&lt;br /&gt;
    interface Factory {&lt;br /&gt;
      public abstract ScrollBar newScrollBar();&lt;br /&gt;
      public abstract MenuBar   newMenuBar();&lt;br /&gt;
      ... &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
But implementation classes that do:&lt;br /&gt;
&lt;br /&gt;
    class MotifFactory implements Factory {&lt;br /&gt;
      public ScrollBar newScrollBar() { return new MotifScrollBar(...); }&lt;br /&gt;
      ...&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory Pattern=&lt;br /&gt;
==What is Abstract Factory Pattern?==&lt;br /&gt;
Abstract Factory Design Pattern encapsulates a group of objects that have common theme. It implements a generic interface to create these objects that are part of the theme. It does not care about the details of the implementation of these objects. The Abstract Factory pattern, a class delegates the responsibility of object instantiation to another object via composition. It is a type of Creational pattern [http://en.wikipedia.org/wiki/Abstract_factory_pattern] “Provide an interface for creating families of related or dependent objects without specifying their concrete classes” [http://sourcemaking.com/design_patterns/abstract_factory]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
Ruby automatically implements the Abstract Factory pattern as Class Objects. All Class objects have the same interface: the new method of each class object creates new instances of the class. Thus the code can pass references to class objects around and they can be used to call new method without knowing the exact type of object that the class creates.&lt;br /&gt;
&lt;br /&gt;
    Class Foo; end&lt;br /&gt;
    Class Bar, end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is the use of Abstract Factory Pattern&lt;br /&gt;
    &lt;br /&gt;
    def create_something(factory)&lt;br /&gt;
	new_object = factory.new&lt;br /&gt;
	puts &amp;quot;created a new #{new_object.class} with a factory&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Here we select a factory to use&lt;br /&gt;
    Create_something(Foo)&lt;br /&gt;
    Create_something(Bar)&lt;br /&gt;
&lt;br /&gt;
Output of the code:&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Foo with a factory&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Bar with a factory&lt;br /&gt;
&lt;br /&gt;
The create_something method is creating objects through an abstract interface. It does not have details about implementation used to create these objects. Thus the use of create_something() is used to shield the rest of the code from that knowledge.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
In Java, implementing  Abstract Factory design pattern we need to create a class which has method who defers creation of product objects to its concrete class. This class then needs to be ”extended” by the client class which uses only these interfaces to create objects of concrete class&lt;br /&gt;
[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf]. In Java, Abstract Factory defines a different method for the creation of each product it can produce. The following example shows an implementation of Abstract Factory design pattern in Java. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   public class FactoryFmProto {&lt;br /&gt;
  static class Expression {&lt;br /&gt;
   protected String str;&lt;br /&gt;
   public Expression( String s ) { str = s; }&lt;br /&gt;
   public Expression cloan()     { return null; }&lt;br /&gt;
   public String     toString()  { return str; }&lt;br /&gt;
  }&lt;br /&gt;
  static abstract class Factory {&lt;br /&gt;
   protected Expression prototype = null;&lt;br /&gt;
   public Expression makePhrase() { return prototype.cloan(); }&lt;br /&gt;
   public abstract Expression makeCompromise();&lt;br /&gt;
   public abstract Expression makeGrade();&lt;br /&gt;
  }&lt;br /&gt;
  static class PCFactory extends Factory {&lt;br /&gt;
   public PCFactory() { prototype = new PCPhrase(); }&lt;br /&gt;
   public Expression makeCompromise() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;do it your way, any way, or no way\&amp;quot;&amp;quot; ); }&lt;br /&gt;
   public Expression makeGrade() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;you pass, self-esteem intact\&amp;quot;&amp;quot; ); }&lt;br /&gt;
  }&lt;br /&gt;
   static class NotPCFactory extends Factory {&lt;br /&gt;
   public NotPCFactory() { prototype = new NotPCPhrase(); }&lt;br /&gt;
   public Expression makeCompromise() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;my way, or the highway\&amp;quot;&amp;quot; ); }&lt;br /&gt;
   public Expression makeGrade() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;take test, deal with the results\&amp;quot;&amp;quot; ); }&lt;br /&gt;
  }&lt;br /&gt;
   public static void main( String[] args ) {&lt;br /&gt;
   Factory factory;&lt;br /&gt;
   if (args.length &amp;gt; 0) factory = new PCFactory();&lt;br /&gt;
   else                 factory = new NotPCFactory();&lt;br /&gt;
   for (int i=0; i &amp;lt; 3; i++) System.out.print( factory.makePhrase() + &amp;quot;  &amp;quot; );&lt;br /&gt;
   System.out.println();&lt;br /&gt;
   System.out.println( factory.makeCompromise() );&lt;br /&gt;
   System.out.println( factory.makeGrade() );&lt;br /&gt;
  }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
Basically, Java and Ruby, both can implement Abstract Factory design pattern. But the more important point is the simplicity by which they can apply it. Ruby automatically implements the Abstract Factory pattern as Class Objects. But Java needs helps of interfaces and classes to do so. Thus Java implementation needs a well defined interface to do so but in Ruby it is directly implemented because of private class object property.&lt;br /&gt;
&lt;br /&gt;
Similarly, C# demonstrates the Abstract Factory pattern by creating parallel hierarchies of objects. Object creation has been abstracted and there is no need for hard-coded class names in the client code. This property helps C# to have better implementation than Java. In .NET, there are built in features such as, generics, reflection, object initializers, automatic properties, etc for implementation [http://www.dofactory.com/Patterns/PatternAbstract.aspx].&lt;br /&gt;
&lt;br /&gt;
=Iterator Design Pattern=&lt;br /&gt;
==What is Iterator Design Pattern?==&lt;br /&gt;
The Iterator design pattern allows an object to encapsulate the internal structure and allows the user to move through the collection of data using standard interface. It is one of the simplest and most frequently used design pattern. It is a type of Behavioral design pattern [http://en.wikipedia.org/wiki/Iterator_pattern]. “Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.” [http://sourcemaking.com/design_patterns/iterator]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
Ruby implements iterators with blocks and the ‘each’ method, and with ‘for..in’ statements. For example consider the following example;&lt;br /&gt;
&lt;br /&gt;
    def print_element(container)&lt;br /&gt;
    	Container.each {|o| puts o.inspect }&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    list = [1,2,2,3]&lt;br /&gt;
    hash = {“a”=&amp;gt;1, “b”=&amp;gt;2,”c”=&amp;gt;3, “d”=&amp;gt;4 }&lt;br /&gt;
    print_elements list&lt;br /&gt;
    print_elements hash&lt;br /&gt;
&lt;br /&gt;
The output of the code is,&lt;br /&gt;
    1&lt;br /&gt;
    2&lt;br /&gt;
    3&lt;br /&gt;
    4&lt;br /&gt;
    [“a”,1]&lt;br /&gt;
    [“b”,2]&lt;br /&gt;
    [“c”,3]&lt;br /&gt;
    [“d”,4]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
&lt;br /&gt;
In Java, we can implement Iterator design pattern by using java.util.Enumeration interface which returns a reference to an object. Furthermore, Hashes and Vector have limited capabilities which help simple traversing. Java JDK 1.2 introduced a new Collections package with more aggregate classes, including sets, lists, maps and an Iterator interface. If we wanted to start implementing Iterator design pattern from start, then it would again involve having an interface for accessing and traversing the elements which is further implemented by the concrete class.  Thus a class who needs to access the list will need to call the interface class [http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf]. For example, consider the following scenario where iterator.First() and iterator.Next(), has been implemented in the class ListIterator.&lt;br /&gt;
&lt;br /&gt;
    ...&lt;br /&gt;
    List list = new List();&lt;br /&gt;
    ...&lt;br /&gt;
    ListIterator iterator = new ListIterator(list);&lt;br /&gt;
    iterator.First();&lt;br /&gt;
    while (!iterator.IsDone()) {&lt;br /&gt;
    Object item = iterator.CurrentItem();&lt;br /&gt;
    // Code here to process item.&lt;br /&gt;
    iterator.Next();&lt;br /&gt;
    }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
&lt;br /&gt;
Overall implementation of Iterator design pattern in each object oriented language is simple as it is a basis feature of objects. But in general, the Ruby implementation is more concise. Ruby has built-in iterators which make it easier to implement Iterator pattern for any kind of object. It hides the structure and there is no need for having implementation for those methods in the class. But in Java, the built-in library function help to create easier and clear implementations. C# also has similar implementation as Java for this design pattern [http://www.dofactory.com/Patterns/PatternIterator.aspx]. &lt;br /&gt;
&lt;br /&gt;
In PHP, using an object in a foreach structure will traverse the public values. There are also many multiple Iterator classes available to allow us to iterate through common lists, such as directories, XML structures and recursive arrays. We can also implement our own interfaces depending on requirement [http://us3.php.net/manual/en/language.oop5.iterations.php].&lt;br /&gt;
&lt;br /&gt;
=Decorator Pattern=&lt;br /&gt;
&lt;br /&gt;
This pattern is used to increase the functionality of the existing object dynamically. Suppose we have a program that uses eight objects, but three of them need an additional feature. We could create derived class for these objects having the additional features but then we can create a Decorator class which will add any specific kind of feature required [http://www.patterndepot.com/put/8/Decorator.pdf]. It is a type of behavioral pattern.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
&lt;br /&gt;
Generic decorators can be implmented by using the method_missing method. This method is called when an object receives a message that it does not have a method fo. The method_missing method can forward the message on to other object and wrap additional behavior around the call. In this example we talk about how a coffee class can have many addtions to it like coffee with cream, sprinkles, milk etc and creating a class for each of them will not be the correct solution.In this example the cost can be calculated according to what is sent to it.Cost of the coffee is 2 and the cost of White coffee (coffee + milk) = 2.4. So what happens when we execute the Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost we get the result as 2.9 as the cost of the coffee is 2, the decorator object (now only coffee) is sent to the Milk and it becomes 2.4, which now is then sent to the Whip which is going to be 2.4 + 02 = 2.6 and finally to Sprinkles which becomes 2.6 + 0.3 = 2.9. The below code is an example of decorators where we just create a place holder and we can use this function to perform different functions depending on the parameters supplied to it. The need for this kind of pattern is so as to increase the functionality of a particular class [http://en.wikipedia.org/wiki/Decorator_pattern]. &lt;br /&gt;
&lt;br /&gt;
    module Decorator&lt;br /&gt;
      def initialize(decorated)&lt;br /&gt;
        @decorated = decorated&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    def method_missing(method, *args)&lt;br /&gt;
        args.empty? ? @decorated.send(method) : @decorated.send(method, args)&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
    class Whip&lt;br /&gt;
      include Decorator&lt;br /&gt;
      def cost &lt;br /&gt;
        @decorated.cost + 0.2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    class Sprinkles&lt;br /&gt;
      include Decorator&lt;br /&gt;
&lt;br /&gt;
      def cost&lt;br /&gt;
        @decorated.cost + 0.3&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    Whip.new(Coffee.new).cost&lt;br /&gt;
    #=&amp;gt; 2.2&lt;br /&gt;
    Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost &lt;br /&gt;
    #=&amp;gt; 2.9&lt;br /&gt;
&lt;br /&gt;
There are various other options to implement this design pattern. Other way to implememt the pattern is by using singleton methods and method aliases. Delegation can also be used, and it overcomes one of the most important disadvantage. We can remove add features if we are using delegation but this is not possible if we are using singleton methods and method aliases. Example for this can be found here [http://www.scribd.com/doc/2217773/Design-Patterns-in-Ruby].&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
&lt;br /&gt;
In Java, this pattern is easy to implement by dividing the various responsibilities into classes and interfaces. The below example consider all these responsibilities and have four components which are described below  &lt;br /&gt;
* Component: Defines the interface for objects that can have responsibilities added to them dynamically.&lt;br /&gt;
* ConcreteComponent: Defines an object to which additional responsibilities can be attached.&lt;br /&gt;
* Decorator: maintains a reference to a Component object and defines an interface that conforms to Component's interface.&lt;br /&gt;
* ConcreteDecorator: adds responsibilities to the component.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface IComponent {&lt;br /&gt;
    public void doStuff();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete component&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class Component implements IComponent{&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    System.out.println(&amp;quot;Do Suff&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Decorator&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface Decorator extends IComponent {&lt;br /&gt;
    public void addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete Decorator ('''Extends IComponent''')&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class ConcreteDecorator implements Decorator {&lt;br /&gt;
    IComponent component;&lt;br /&gt;
    public ConcreteDecorator(IComponent component) {&lt;br /&gt;
    super();&lt;br /&gt;
    this.component = component;&lt;br /&gt;
    }&lt;br /&gt;
    public void addedBehavior() {&lt;br /&gt;
    System.out.println(&amp;quot;Decorator does some stuff too&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    component.doStuff();&lt;br /&gt;
    addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
The Client&lt;br /&gt;
&lt;br /&gt;
    import decorator.*;&lt;br /&gt;
    public class Client {&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
    IComponent comp = new Component();&lt;br /&gt;
    Decorator decorator = new ConcreteDecorator(comp);&lt;br /&gt;
    decorator.doStuff();&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
==Comparison of implementations==&lt;br /&gt;
&lt;br /&gt;
Ruby provides different options to implement Decorator pattern like method_missing, delegation and alias methods. This provides flexibility to the user to implement any possible way depending on the requirements and features needed. But in Java, there is more clearer approach using the components provided in the example. It is a straight forward approach. But different options provided by Ruby make it much better than Java.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages like Javascript, decorator pattern can be implemented with no interfaces or traditional OOP inheritance. With simple overriding but this approach is difficult to implement [http://en.wikipedia.org/wiki/Decorator_pattern#JavaScript].&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
We have seen four design patterns Factory design pattern, Abstract Factory design pattern, Iterator design pattern and Decorator Design Pattern. We have chosen these patterns as they are widely used and Ruby has in-built implementations of these. We have mainly tried to compare Ruby and Java but also specified tips about other languages like PHP, C# and Javascript. In Ruby implementing these design patterns is simple and easy because of its main feature of private class objects, unbounded polymorphism and duck typing [http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf]. In Java all the features are mainly implemented through interfaces and classes. This has several disadvantages like increase in code complexity, size and is generally confusing and tedious to trace or understand the code.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf Design Patterns]&lt;br /&gt;
#[http://www.patterndepot.com/put/8/JavaPatterns.htm Design Patterns Java Companion James W Cooper]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 Wiki Design Patterns]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory Method]&lt;br /&gt;
#[http://sourcemaking.com/design_patterns/abstract_factory SourceMaking explains Abstract Factory]&lt;br /&gt;
#[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf Abstract Factory Example in Java]&lt;br /&gt;
#[http://www.dofactory.com/Patterns/PatternAbstract.aspx Abstract Factory explained]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Iterator_pattern Iterator Pattern]&lt;br /&gt;
#[http://sourcemaking.com/design_patterns/iterator Sourcemaking explains Iterator method]&lt;br /&gt;
#[http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf Iterator method explained]&lt;br /&gt;
#[http://www.dofactory.com/Patterns/PatternIterator.aspx DoFactory explains Iterator pattern]&lt;br /&gt;
#[http://us3.php.net/manual/en/language.oop5.iterations.php Iterator pattern for PHP]&lt;br /&gt;
#[http://www.patterndepot.com/put/8/Decorator.pdf Decorator Pattern]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Decorator_pattern Wiki Decorator Pattern]&lt;br /&gt;
#[http://www.scribd.com/doc/2217773/Design-Patterns-in-Ruby Design Patterns in Ruby]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Decorator_pattern#JavaScript Design Patterns Javascript]&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=23272</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 11 zv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=23272"/>
		<updated>2009-10-09T00:21:39Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Factory */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''What facilities does Ruby offer that makes it easier to realize other GoF (and other) patterns that we did not cover in class? The key idea here is to explore how Ruby can implement these patterns more efficiently or transparently than static (or other dynamic) o-o languages.''&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Before starting off with design patterns for Ruby we need to define what a design pattern is, Design patterns can be described as &amp;quot;a general reusable solution to a commonly occurring problem in software design.&amp;quot; [http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29]&lt;br /&gt;
&amp;quot;The idea of design patterns is to not to reinvent the wheel but to solve the current problems by using solutions that have worked in the past&amp;quot; [http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf]. A design pattern names, abstracts, and identifies the key aspects of a common design structure that make it useful for creating a reusable object-oriented design. It helps to identify the classes and instances and the way they collaborate with each other to form a solution to a problem. Design patterns can be classified into 3 parts [http://en.wikipedia.org/wiki/Creational_pattern Creational], [http://en.wikipedia.org/wiki/Structural_pattern Structural], [http://en.wikipedia.org/wiki/Behavioral_pattern Behavioral] [http://www.patterndepot.com/put/8/JavaPatterns.htm].&lt;br /&gt;
&lt;br /&gt;
=Factory=&lt;br /&gt;
The factory design pattern is an object oriented design pattern. It is a creational design pattern and deals with the issues faced in creating objects.&lt;br /&gt;
The main goal of this implementation is to isolate teh code that creates the class form the concete implementation of that class. Ruby example for the same is given below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Factory Example in Ruby==&lt;br /&gt;
&lt;br /&gt;
    class GearFactory&lt;br /&gt;
      def new() &lt;br /&gt;
        if ( ... some condition )&lt;br /&gt;
           return Sprocket.new()&lt;br /&gt;
        else&lt;br /&gt;
           return Cog().new()&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Our client class now becomes:&lt;br /&gt;
    class GearUser &lt;br /&gt;
      def doSomething(factory )&lt;br /&gt;
        ...&lt;br /&gt;
      my_gear = factory.new()&lt;br /&gt;
        ...&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The above code does not have to distinguish between a factory and an ordinary class. We can call the class using the followijng code.&lt;br /&gt;
    client.doSomething(GearFactory.new)          #Use the factory&lt;br /&gt;
    client.doSomething(Cog)                      #Use the Cog class&lt;br /&gt;
    client.doSomething(Sprocket)                 #Use the Sprocket class&lt;br /&gt;
&lt;br /&gt;
==Factory Example in Java==&lt;br /&gt;
In java the Factory implementation is done using interfaces. Declaring them as interfaces helps to maintain a general overview and not depending on the type of factory object that needs to be used. All of these can be placed in a huge factory in a client application.&lt;br /&gt;
A well known example for Java Factory is the UI toolkits that are designed to run on different windowing systems.&lt;br /&gt;
    interface ScrollBar { ... }&lt;br /&gt;
    interface MenuBar   { ... }&lt;br /&gt;
    ...&lt;br /&gt;
And associated classes implementing them on different windowing systems:&lt;br /&gt;
&lt;br /&gt;
    class MotifScrollBar implements ScrollBar { ... }&lt;br /&gt;
    class Win95ScrollBar implements ScrollBar { ... }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
And a factory interface that also doesn't commit to representation:&lt;br /&gt;
&lt;br /&gt;
    interface Factory {&lt;br /&gt;
      public abstract ScrollBar newScrollBar();&lt;br /&gt;
      public abstract MenuBar   newMenuBar();&lt;br /&gt;
      ... &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
But implementation classes that do:&lt;br /&gt;
&lt;br /&gt;
    class MotifFactory implements Factory {&lt;br /&gt;
      public ScrollBar newScrollBar() { return new MotifScrollBar(...); }&lt;br /&gt;
      ...&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory Pattern=&lt;br /&gt;
==What is Abstract Factory Pattern?==&lt;br /&gt;
Abstract Factory Design Pattern encapsulates a group of objects that have common theme. It implements a generic interface to create these objects that are part of the theme. It does not care about the details of the implementation of these objects. The Abstract Factory pattern, a class delegates the responsibility of object instantiation to another object via composition. It is a type of Creational pattern [http://en.wikipedia.org/wiki/Abstract_factory_pattern] “Provide an interface for creating families of related or dependent objects without specifying their concrete classes” [http://sourcemaking.com/design_patterns/abstract_factory]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
Ruby automatically implements the Abstract Factory pattern as Class Objects. All Class objects have the same interface: the new method of each class object creates new instances of the class. Thus the code can pass references to class objects around and they can be used to call new method without knowing the exact type of object that the class creates.&lt;br /&gt;
&lt;br /&gt;
    Class Foo; end&lt;br /&gt;
    Class Bar, end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is the use of Abstract Factory Pattern&lt;br /&gt;
    &lt;br /&gt;
    def create_something(factory)&lt;br /&gt;
	new_object = factory.new&lt;br /&gt;
	puts &amp;quot;created a new #{new_object.class} with a factory&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Here we select a factory to use&lt;br /&gt;
    Create_something(Foo)&lt;br /&gt;
    Create_something(Bar)&lt;br /&gt;
&lt;br /&gt;
Output of the code:&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Foo with a factory&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Bar with a factory&lt;br /&gt;
&lt;br /&gt;
The create_something method is creating objects through an abstract interface. It does not have details about implementation used to create these objects. Thus the use of create_something() is used to shield the rest of the code from that knowledge.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
In Java, implementing  Abstract Factory design pattern we need to create a class which has method who defers creation of product objects to its concrete class. This class then needs to be ”extended” by the client class which uses only these interfaces to create objects of concrete class&lt;br /&gt;
[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf]. In Java, Abstract Factory defines a different method for the creation of each product it can produce. The following example shows an implementation of Abstract Factory design pattern in Java. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   public class FactoryFmProto {&lt;br /&gt;
  static class Expression {&lt;br /&gt;
   protected String str;&lt;br /&gt;
   public Expression( String s ) { str = s; }&lt;br /&gt;
   public Expression cloan()     { return null; }&lt;br /&gt;
   public String     toString()  { return str; }&lt;br /&gt;
  }&lt;br /&gt;
  static abstract class Factory {&lt;br /&gt;
   protected Expression prototype = null;&lt;br /&gt;
   public Expression makePhrase() { return prototype.cloan(); }&lt;br /&gt;
   public abstract Expression makeCompromise();&lt;br /&gt;
   public abstract Expression makeGrade();&lt;br /&gt;
  }&lt;br /&gt;
  static class PCFactory extends Factory {&lt;br /&gt;
   public PCFactory() { prototype = new PCPhrase(); }&lt;br /&gt;
   public Expression makeCompromise() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;do it your way, any way, or no way\&amp;quot;&amp;quot; ); }&lt;br /&gt;
   public Expression makeGrade() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;you pass, self-esteem intact\&amp;quot;&amp;quot; ); }&lt;br /&gt;
  }&lt;br /&gt;
   static class NotPCFactory extends Factory {&lt;br /&gt;
   public NotPCFactory() { prototype = new NotPCPhrase(); }&lt;br /&gt;
   public Expression makeCompromise() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;my way, or the highway\&amp;quot;&amp;quot; ); }&lt;br /&gt;
   public Expression makeGrade() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;take test, deal with the results\&amp;quot;&amp;quot; ); }&lt;br /&gt;
  }&lt;br /&gt;
   public static void main( String[] args ) {&lt;br /&gt;
   Factory factory;&lt;br /&gt;
   if (args.length &amp;gt; 0) factory = new PCFactory();&lt;br /&gt;
   else                 factory = new NotPCFactory();&lt;br /&gt;
   for (int i=0; i &amp;lt; 3; i++) System.out.print( factory.makePhrase() + &amp;quot;  &amp;quot; );&lt;br /&gt;
   System.out.println();&lt;br /&gt;
   System.out.println( factory.makeCompromise() );&lt;br /&gt;
   System.out.println( factory.makeGrade() );&lt;br /&gt;
  }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
Basically, Java and Ruby, both can implement Abstract Factory design pattern. But the more important point is the simplicity by which they can apply it. Ruby automatically implements the Abstract Factory pattern as Class Objects. But Java needs helps of interfaces and classes to do so. Thus Java implementation needs a well defined interface to do so but in Ruby it is directly implemented because of private class object property.&lt;br /&gt;
&lt;br /&gt;
Similarly, C# demonstrates the Abstract Factory pattern by creating parallel hierarchies of objects. Object creation has been abstracted and there is no need for hard-coded class names in the client code. This property helps C# to have better implementation than Java. In .NET, there are built in features such as, generics, reflection, object initializers, automatic properties, etc for implementation [http://www.dofactory.com/Patterns/PatternAbstract.aspx].&lt;br /&gt;
&lt;br /&gt;
=Iterator Design Pattern=&lt;br /&gt;
==What is Iterator Design Pattern?==&lt;br /&gt;
The Iterator design pattern allows an object to encapsulate the internal structure and allows the user to move through the collection of data using standard interface. It is one of the simplest and most frequently used design pattern. It is a type of Behavioral design pattern [http://en.wikipedia.org/wiki/Iterator_pattern]. “Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.” [http://sourcemaking.com/design_patterns/iterator]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
Ruby implements iterators with blocks and the ‘each’ method, and with ‘for..in’ statements. For example consider the following example;&lt;br /&gt;
&lt;br /&gt;
    def print_element(container)&lt;br /&gt;
    	Container.each {|o| puts o.inspect }&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    list = [1,2,2,3]&lt;br /&gt;
    hash = {“a”=&amp;gt;1, “b”=&amp;gt;2,”c”=&amp;gt;3, “d”=&amp;gt;4 }&lt;br /&gt;
    print_elements list&lt;br /&gt;
    print_elements hash&lt;br /&gt;
&lt;br /&gt;
The output of the code is,&lt;br /&gt;
    1&lt;br /&gt;
    2&lt;br /&gt;
    3&lt;br /&gt;
    4&lt;br /&gt;
    [“a”,1]&lt;br /&gt;
    [“b”,2]&lt;br /&gt;
    [“c”,3]&lt;br /&gt;
    [“d”,4]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
&lt;br /&gt;
In Java, we can implement Iterator design pattern by using java.util.Enumeration interface which returns a reference to an object. Furthermore, Hashes and Vector have limited capabilities which help simple traversing. Java JDK 1.2 introduced a new Collections package with more aggregate classes, including sets, lists, maps and an Iterator interface. If we wanted to start implementing Iterator design pattern from start, then it would again involve having an interface for accessing and traversing the elements which is further implemented by the concrete class.  Thus a class who needs to access the list will need to call the interface class [http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf]. For example, consider the following scenario where iterator.First() and iterator.Next(), has been implemented in the class ListIterator.&lt;br /&gt;
&lt;br /&gt;
    ...&lt;br /&gt;
    List list = new List();&lt;br /&gt;
    ...&lt;br /&gt;
    ListIterator iterator = new ListIterator(list);&lt;br /&gt;
    iterator.First();&lt;br /&gt;
    while (!iterator.IsDone()) {&lt;br /&gt;
    Object item = iterator.CurrentItem();&lt;br /&gt;
    // Code here to process item.&lt;br /&gt;
    iterator.Next();&lt;br /&gt;
    }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
&lt;br /&gt;
Overall implementation of Iterator design pattern in each object oriented language is simple as it is a basis feature of objects. But in general, the Ruby implementation is more concise. Ruby has built-in iterators which make it easier to implement Iterator pattern for any kind of object. It hides the structure and there is no need for having implementation for those methods in the class. But in Java, the built-in library function help to create easier and clear implementations. C# also has similar implementation as Java for this design pattern [http://www.dofactory.com/Patterns/PatternIterator.aspx]. &lt;br /&gt;
&lt;br /&gt;
In PHP, using an object in a foreach structure will traverse the public values. There are also many multiple Iterator classes available to allow us to iterate through common lists, such as directories, XML structures and recursive arrays. We can also implement our own interfaces depending on requirement [http://us3.php.net/manual/en/language.oop5.iterations.php].&lt;br /&gt;
&lt;br /&gt;
=Decorator Pattern=&lt;br /&gt;
&lt;br /&gt;
This pattern is used to increase the functionality of the existing object dynamically. Suppose we have a program that uses eight objects, but three of them need an additional feature. We could create derived class for these objects having the additional features but then we can create a Decorator class which will add any specific kind of feature required [http://www.patterndepot.com/put/8/Decorator.pdf]. It is a type of behavioral pattern.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
&lt;br /&gt;
Generic decorators can be implmented by using the method_missing method. This method is called when an object receives a message that it does not have a method fo. The method_missing method can forward the message on to other object and wrap additional behavior around the call. In this example we talk about how a coffee class can have many addtions to it like coffee with cream, sprinkles, milk etc and creating a class for each of them will not be the correct solution.In this example the cost can be calculated according to what is sent to it.Cost of the coffee is 2 and the cost of White coffee (coffee + milk) = 2.4. So what happens when we execute the Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost we get the result as 2.9 as the cost of the coffee is 2, the decorator object (now only coffee) is sent to the Milk and it becomes 2.4, which now is then sent to the Whip which is going to be 2.4 + 02 = 2.6 and finally to Sprinkles which becomes 2.6 + 0.3 = 2.9. The below code is an example of decorators where we just create a place holder and we can use this function to perform different functions depending on the parameters supplied to it. The need for this kind of pattern is so as to increase the functionality of a particular class [http://en.wikipedia.org/wiki/Decorator_pattern]. &lt;br /&gt;
&lt;br /&gt;
    module Decorator&lt;br /&gt;
      def initialize(decorated)&lt;br /&gt;
        @decorated = decorated&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    def method_missing(method, *args)&lt;br /&gt;
        args.empty? ? @decorated.send(method) : @decorated.send(method, args)&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
    class Whip&lt;br /&gt;
      include Decorator&lt;br /&gt;
      def cost &lt;br /&gt;
        @decorated.cost + 0.2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    class Sprinkles&lt;br /&gt;
      include Decorator&lt;br /&gt;
&lt;br /&gt;
      def cost&lt;br /&gt;
        @decorated.cost + 0.3&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    Whip.new(Coffee.new).cost&lt;br /&gt;
    #=&amp;gt; 2.2&lt;br /&gt;
    Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost &lt;br /&gt;
    #=&amp;gt; 2.9&lt;br /&gt;
&lt;br /&gt;
There are various other options to implement this design pattern. Other way to implememt the pattern is by using singleton methods and method aliases. Delegation can also be used, and it overcomes one of the most important disadvantage. We can remove add features if we are using delegation but this is not possible if we are using singleton methods and method aliases. Example for this can be found here [http://www.scribd.com/doc/2217773/Design-Patterns-in-Ruby].&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
&lt;br /&gt;
In Java, this pattern is easy to implement by dividing the various responsibilities into classes and interfaces. The below example consider all these responsibilities and have four components which are described below  &lt;br /&gt;
* Component: Defines the interface for objects that can have responsibilities added to them dynamically.&lt;br /&gt;
* ConcreteComponent: Defines an object to which additional responsibilities can be attached.&lt;br /&gt;
* Decorator: maintains a reference to a Component object and defines an interface that conforms to Component's interface.&lt;br /&gt;
* ConcreteDecorator: adds responsibilities to the component.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface IComponent {&lt;br /&gt;
    public void doStuff();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete component&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class Component implements IComponent{&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    System.out.println(&amp;quot;Do Suff&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Decorator&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface Decorator extends IComponent {&lt;br /&gt;
    public void addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete Decorator ('''Extends IComponent''')&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class ConcreteDecorator implements Decorator {&lt;br /&gt;
    IComponent component;&lt;br /&gt;
    public ConcreteDecorator(IComponent component) {&lt;br /&gt;
    super();&lt;br /&gt;
    this.component = component;&lt;br /&gt;
    }&lt;br /&gt;
    public void addedBehavior() {&lt;br /&gt;
    System.out.println(&amp;quot;Decorator does some stuff too&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    component.doStuff();&lt;br /&gt;
    addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
The Client&lt;br /&gt;
&lt;br /&gt;
    import decorator.*;&lt;br /&gt;
    public class Client {&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
    IComponent comp = new Component();&lt;br /&gt;
    Decorator decorator = new ConcreteDecorator(comp);&lt;br /&gt;
    decorator.doStuff();&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
==Comparison of implementations==&lt;br /&gt;
&lt;br /&gt;
Ruby provides different options to implement Decorator pattern like method_missing, delegation and alias methods. This provides flexibility to the user to implement any possible way depending on the requirements and features needed. But in Java, there is more clearer approach using the components provided in the example. It is a straight forward approach. But different options provided by Ruby make it much better than Java.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages like Javascript, decorator pattern can be implemented with no interfaces or traditional OOP inheritance. With simple overriding but this approach is difficult to implement [http://en.wikipedia.org/wiki/Decorator_pattern#JavaScript].&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
We have seen four design patterns Factory design pattern, Abstract Factory design pattern, Iterator design pattern and Decorator Design Pattern. We have chosen these patterns as they are widely used and Ruby has in-built implementations of these. We have mainly tried to compare Ruby and Java but also specified tips about other languages like PHP, C# and Javascript. In Ruby implementing these design patterns is simple and easy because of its main feature of private class objects, unbounded polymorphism and duck typing [http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf]. In Java all the features are mainly implemented through interfaces and classes. This has several disadvantages like increase in code complexity, size and is generally confusing and tedious to trace or understand the code.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf Design Patterns]&lt;br /&gt;
#[http://www.patterndepot.com/put/8/JavaPatterns.htm Design Patterns Java Companion James W Cooper]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 Wiki Design Patterns]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory Method]&lt;br /&gt;
#[http://sourcemaking.com/design_patterns/abstract_factory SourceMaking explains Abstract Factory]&lt;br /&gt;
#[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf Abstract Factory Example in Java]&lt;br /&gt;
#[http://www.dofactory.com/Patterns/PatternAbstract.aspx Abstract Factory explained]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Iterator_pattern Iterator Pattern]&lt;br /&gt;
#[http://sourcemaking.com/design_patterns/iterator Sourcemaking explains Iterator method]&lt;br /&gt;
#[http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf Iterator method explained]&lt;br /&gt;
#[http://www.dofactory.com/Patterns/PatternIterator.aspx DoFactory explains Iterator pattern]&lt;br /&gt;
#[http://us3.php.net/manual/en/language.oop5.iterations.php Iterator pattern for PHP]&lt;br /&gt;
#[http://www.patterndepot.com/put/8/Decorator.pdf Decorator Pattern]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Decorator_pattern Wiki Decorator Pattern]&lt;br /&gt;
#[http://www.scribd.com/doc/2217773/Design-Patterns-in-Ruby Design Patterns in Ruby]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Decorator_pattern#JavaScript Design Patterns Javascript]&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=23268</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 11 zv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=23268"/>
		<updated>2009-10-09T00:19:48Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''What facilities does Ruby offer that makes it easier to realize other GoF (and other) patterns that we did not cover in class? The key idea here is to explore how Ruby can implement these patterns more efficiently or transparently than static (or other dynamic) o-o languages.''&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Before starting off with design patterns for Ruby we need to define what a design pattern is, Design patterns can be described as &amp;quot;a general reusable solution to a commonly occurring problem in software design.&amp;quot; [http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29]&lt;br /&gt;
&amp;quot;The idea of design patterns is to not to reinvent the wheel but to solve the current problems by using solutions that have worked in the past&amp;quot; [http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf]. A design pattern names, abstracts, and identifies the key aspects of a common design structure that make it useful for creating a reusable object-oriented design. It helps to identify the classes and instances and the way they collaborate with each other to form a solution to a problem. Design patterns can be classified into 3 parts [http://en.wikipedia.org/wiki/Creational_pattern Creational], [http://en.wikipedia.org/wiki/Structural_pattern Structural], [http://en.wikipedia.org/wiki/Behavioral_pattern Behavioral] [http://www.patterndepot.com/put/8/JavaPatterns.htm].&lt;br /&gt;
&lt;br /&gt;
=Factory=&lt;br /&gt;
Factories&lt;br /&gt;
The factory design pattern is an object oriented design pattern. It is a creational design pattern and deals with the issues faced in creating objects.&lt;br /&gt;
The main goal of this implementation is to isolate teh code that creates the class form the concete implementation of that class. Ruby example for the same is given below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Factory Example in Ruby==&lt;br /&gt;
&lt;br /&gt;
    class GearFactory&lt;br /&gt;
      def new() &lt;br /&gt;
        if ( ... some condition )&lt;br /&gt;
           return Sprocket.new()&lt;br /&gt;
        else&lt;br /&gt;
           return Cog().new()&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Our client class now becomes:&lt;br /&gt;
    class GearUser &lt;br /&gt;
      def doSomething(factory )&lt;br /&gt;
        ...&lt;br /&gt;
      my_gear = factory.new()&lt;br /&gt;
        ...&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The above code does not have to distinguish between a factory and an ordinary class. We can call the class using the followijng code.&lt;br /&gt;
    client.doSomething(GearFactory.new)          #Use the factory&lt;br /&gt;
    client.doSomething(Cog)                      #Use the Cog class&lt;br /&gt;
    client.doSomething(Sprocket)                 #Use the Sprocket class&lt;br /&gt;
&lt;br /&gt;
==Factory Example in Java==&lt;br /&gt;
In java the Factory implementation is done using interfaces. Declaring them as interfaces helps to maintain a general overview and not depending on the type of factory object that needs to be used. All of these can be placed in a huge factory in a client application.&lt;br /&gt;
A well known example for Java Factory is the UI toolkits that are designed to run on different windowing systems.&lt;br /&gt;
    interface ScrollBar { ... }&lt;br /&gt;
    interface MenuBar   { ... }&lt;br /&gt;
    ...&lt;br /&gt;
And associated classes implementing them on different windowing systems:&lt;br /&gt;
&lt;br /&gt;
    class MotifScrollBar implements ScrollBar { ... }&lt;br /&gt;
    class Win95ScrollBar implements ScrollBar { ... }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
And a factory interface that also doesn't commit to representation:&lt;br /&gt;
&lt;br /&gt;
    interface Factory {&lt;br /&gt;
      public abstract ScrollBar newScrollBar();&lt;br /&gt;
      public abstract MenuBar   newMenuBar();&lt;br /&gt;
      ... &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
But implementation classes that do:&lt;br /&gt;
&lt;br /&gt;
    class MotifFactory implements Factory {&lt;br /&gt;
      public ScrollBar newScrollBar() { return new MotifScrollBar(...); }&lt;br /&gt;
      ...&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory Pattern=&lt;br /&gt;
==What is Abstract Factory Pattern?==&lt;br /&gt;
Abstract Factory Design Pattern encapsulates a group of objects that have common theme. It implements a generic interface to create these objects that are part of the theme. It does not care about the details of the implementation of these objects. The Abstract Factory pattern, a class delegates the responsibility of object instantiation to another object via composition. It is a type of Creational pattern [http://en.wikipedia.org/wiki/Abstract_factory_pattern] “Provide an interface for creating families of related or dependent objects without specifying their concrete classes” [http://sourcemaking.com/design_patterns/abstract_factory]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
Ruby automatically implements the Abstract Factory pattern as Class Objects. All Class objects have the same interface: the new method of each class object creates new instances of the class. Thus the code can pass references to class objects around and they can be used to call new method without knowing the exact type of object that the class creates.&lt;br /&gt;
&lt;br /&gt;
    Class Foo; end&lt;br /&gt;
    Class Bar, end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is the use of Abstract Factory Pattern&lt;br /&gt;
    &lt;br /&gt;
    def create_something(factory)&lt;br /&gt;
	new_object = factory.new&lt;br /&gt;
	puts &amp;quot;created a new #{new_object.class} with a factory&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Here we select a factory to use&lt;br /&gt;
    Create_something(Foo)&lt;br /&gt;
    Create_something(Bar)&lt;br /&gt;
&lt;br /&gt;
Output of the code:&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Foo with a factory&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Bar with a factory&lt;br /&gt;
&lt;br /&gt;
The create_something method is creating objects through an abstract interface. It does not have details about implementation used to create these objects. Thus the use of create_something() is used to shield the rest of the code from that knowledge.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
In Java, implementing  Abstract Factory design pattern we need to create a class which has method who defers creation of product objects to its concrete class. This class then needs to be ”extended” by the client class which uses only these interfaces to create objects of concrete class&lt;br /&gt;
[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf]. In Java, Abstract Factory defines a different method for the creation of each product it can produce. The following example shows an implementation of Abstract Factory design pattern in Java. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   public class FactoryFmProto {&lt;br /&gt;
  static class Expression {&lt;br /&gt;
   protected String str;&lt;br /&gt;
   public Expression( String s ) { str = s; }&lt;br /&gt;
   public Expression cloan()     { return null; }&lt;br /&gt;
   public String     toString()  { return str; }&lt;br /&gt;
  }&lt;br /&gt;
  static abstract class Factory {&lt;br /&gt;
   protected Expression prototype = null;&lt;br /&gt;
   public Expression makePhrase() { return prototype.cloan(); }&lt;br /&gt;
   public abstract Expression makeCompromise();&lt;br /&gt;
   public abstract Expression makeGrade();&lt;br /&gt;
  }&lt;br /&gt;
  static class PCFactory extends Factory {&lt;br /&gt;
   public PCFactory() { prototype = new PCPhrase(); }&lt;br /&gt;
   public Expression makeCompromise() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;do it your way, any way, or no way\&amp;quot;&amp;quot; ); }&lt;br /&gt;
   public Expression makeGrade() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;you pass, self-esteem intact\&amp;quot;&amp;quot; ); }&lt;br /&gt;
  }&lt;br /&gt;
   static class NotPCFactory extends Factory {&lt;br /&gt;
   public NotPCFactory() { prototype = new NotPCPhrase(); }&lt;br /&gt;
   public Expression makeCompromise() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;my way, or the highway\&amp;quot;&amp;quot; ); }&lt;br /&gt;
   public Expression makeGrade() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;take test, deal with the results\&amp;quot;&amp;quot; ); }&lt;br /&gt;
  }&lt;br /&gt;
   public static void main( String[] args ) {&lt;br /&gt;
   Factory factory;&lt;br /&gt;
   if (args.length &amp;gt; 0) factory = new PCFactory();&lt;br /&gt;
   else                 factory = new NotPCFactory();&lt;br /&gt;
   for (int i=0; i &amp;lt; 3; i++) System.out.print( factory.makePhrase() + &amp;quot;  &amp;quot; );&lt;br /&gt;
   System.out.println();&lt;br /&gt;
   System.out.println( factory.makeCompromise() );&lt;br /&gt;
   System.out.println( factory.makeGrade() );&lt;br /&gt;
  }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
Basically, Java and Ruby, both can implement Abstract Factory design pattern. But the more important point is the simplicity by which they can apply it. Ruby automatically implements the Abstract Factory pattern as Class Objects. But Java needs helps of interfaces and classes to do so. Thus Java implementation needs a well defined interface to do so but in Ruby it is directly implemented because of private class object property.&lt;br /&gt;
&lt;br /&gt;
Similarly, C# demonstrates the Abstract Factory pattern by creating parallel hierarchies of objects. Object creation has been abstracted and there is no need for hard-coded class names in the client code. This property helps C# to have better implementation than Java. In .NET, there are built in features such as, generics, reflection, object initializers, automatic properties, etc for implementation [http://www.dofactory.com/Patterns/PatternAbstract.aspx].&lt;br /&gt;
&lt;br /&gt;
=Iterator Design Pattern=&lt;br /&gt;
==What is Iterator Design Pattern?==&lt;br /&gt;
The Iterator design pattern allows an object to encapsulate the internal structure and allows the user to move through the collection of data using standard interface. It is one of the simplest and most frequently used design pattern. It is a type of Behavioral design pattern [http://en.wikipedia.org/wiki/Iterator_pattern]. “Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.” [http://sourcemaking.com/design_patterns/iterator]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
Ruby implements iterators with blocks and the ‘each’ method, and with ‘for..in’ statements. For example consider the following example;&lt;br /&gt;
&lt;br /&gt;
    def print_element(container)&lt;br /&gt;
    	Container.each {|o| puts o.inspect }&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    list = [1,2,2,3]&lt;br /&gt;
    hash = {“a”=&amp;gt;1, “b”=&amp;gt;2,”c”=&amp;gt;3, “d”=&amp;gt;4 }&lt;br /&gt;
    print_elements list&lt;br /&gt;
    print_elements hash&lt;br /&gt;
&lt;br /&gt;
The output of the code is,&lt;br /&gt;
    1&lt;br /&gt;
    2&lt;br /&gt;
    3&lt;br /&gt;
    4&lt;br /&gt;
    [“a”,1]&lt;br /&gt;
    [“b”,2]&lt;br /&gt;
    [“c”,3]&lt;br /&gt;
    [“d”,4]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
&lt;br /&gt;
In Java, we can implement Iterator design pattern by using java.util.Enumeration interface which returns a reference to an object. Furthermore, Hashes and Vector have limited capabilities which help simple traversing. Java JDK 1.2 introduced a new Collections package with more aggregate classes, including sets, lists, maps and an Iterator interface. If we wanted to start implementing Iterator design pattern from start, then it would again involve having an interface for accessing and traversing the elements which is further implemented by the concrete class.  Thus a class who needs to access the list will need to call the interface class [http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf]. For example, consider the following scenario where iterator.First() and iterator.Next(), has been implemented in the class ListIterator.&lt;br /&gt;
&lt;br /&gt;
    ...&lt;br /&gt;
    List list = new List();&lt;br /&gt;
    ...&lt;br /&gt;
    ListIterator iterator = new ListIterator(list);&lt;br /&gt;
    iterator.First();&lt;br /&gt;
    while (!iterator.IsDone()) {&lt;br /&gt;
    Object item = iterator.CurrentItem();&lt;br /&gt;
    // Code here to process item.&lt;br /&gt;
    iterator.Next();&lt;br /&gt;
    }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
&lt;br /&gt;
Overall implementation of Iterator design pattern in each object oriented language is simple as it is a basis feature of objects. But in general, the Ruby implementation is more concise. Ruby has built-in iterators which make it easier to implement Iterator pattern for any kind of object. It hides the structure and there is no need for having implementation for those methods in the class. But in Java, the built-in library function help to create easier and clear implementations. C# also has similar implementation as Java for this design pattern [http://www.dofactory.com/Patterns/PatternIterator.aspx]. &lt;br /&gt;
&lt;br /&gt;
In PHP, using an object in a foreach structure will traverse the public values. There are also many multiple Iterator classes available to allow us to iterate through common lists, such as directories, XML structures and recursive arrays. We can also implement our own interfaces depending on requirement [http://us3.php.net/manual/en/language.oop5.iterations.php].&lt;br /&gt;
&lt;br /&gt;
=Decorator Pattern=&lt;br /&gt;
&lt;br /&gt;
This pattern is used to increase the functionality of the existing object dynamically. Suppose we have a program that uses eight objects, but three of them need an additional feature. We could create derived class for these objects having the additional features but then we can create a Decorator class which will add any specific kind of feature required [http://www.patterndepot.com/put/8/Decorator.pdf]. It is a type of behavioral pattern.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
&lt;br /&gt;
Generic decorators can be implmented by using the method_missing method. This method is called when an object receives a message that it does not have a method fo. The method_missing method can forward the message on to other object and wrap additional behavior around the call. In this example we talk about how a coffee class can have many addtions to it like coffee with cream, sprinkles, milk etc and creating a class for each of them will not be the correct solution.In this example the cost can be calculated according to what is sent to it.Cost of the coffee is 2 and the cost of White coffee (coffee + milk) = 2.4. So what happens when we execute the Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost we get the result as 2.9 as the cost of the coffee is 2, the decorator object (now only coffee) is sent to the Milk and it becomes 2.4, which now is then sent to the Whip which is going to be 2.4 + 02 = 2.6 and finally to Sprinkles which becomes 2.6 + 0.3 = 2.9. The below code is an example of decorators where we just create a place holder and we can use this function to perform different functions depending on the parameters supplied to it. The need for this kind of pattern is so as to increase the functionality of a particular class [http://en.wikipedia.org/wiki/Decorator_pattern]. &lt;br /&gt;
&lt;br /&gt;
    module Decorator&lt;br /&gt;
      def initialize(decorated)&lt;br /&gt;
        @decorated = decorated&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    def method_missing(method, *args)&lt;br /&gt;
        args.empty? ? @decorated.send(method) : @decorated.send(method, args)&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
    class Whip&lt;br /&gt;
      include Decorator&lt;br /&gt;
      def cost &lt;br /&gt;
        @decorated.cost + 0.2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    class Sprinkles&lt;br /&gt;
      include Decorator&lt;br /&gt;
&lt;br /&gt;
      def cost&lt;br /&gt;
        @decorated.cost + 0.3&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    Whip.new(Coffee.new).cost&lt;br /&gt;
    #=&amp;gt; 2.2&lt;br /&gt;
    Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost &lt;br /&gt;
    #=&amp;gt; 2.9&lt;br /&gt;
&lt;br /&gt;
There are various other options to implement this design pattern. Other way to implememt the pattern is by using singleton methods and method aliases. Delegation can also be used, and it overcomes one of the most important disadvantage. We can remove add features if we are using delegation but this is not possible if we are using singleton methods and method aliases. Example for this can be found here [http://www.scribd.com/doc/2217773/Design-Patterns-in-Ruby].&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
&lt;br /&gt;
In Java, this pattern is easy to implement by dividing the various responsibilities into classes and interfaces. The below example consider all these responsibilities and have four components which are described below  &lt;br /&gt;
* Component: Defines the interface for objects that can have responsibilities added to them dynamically.&lt;br /&gt;
* ConcreteComponent: Defines an object to which additional responsibilities can be attached.&lt;br /&gt;
* Decorator: maintains a reference to a Component object and defines an interface that conforms to Component's interface.&lt;br /&gt;
* ConcreteDecorator: adds responsibilities to the component.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface IComponent {&lt;br /&gt;
    public void doStuff();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete component&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class Component implements IComponent{&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    System.out.println(&amp;quot;Do Suff&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Decorator&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface Decorator extends IComponent {&lt;br /&gt;
    public void addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete Decorator ('''Extends IComponent''')&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class ConcreteDecorator implements Decorator {&lt;br /&gt;
    IComponent component;&lt;br /&gt;
    public ConcreteDecorator(IComponent component) {&lt;br /&gt;
    super();&lt;br /&gt;
    this.component = component;&lt;br /&gt;
    }&lt;br /&gt;
    public void addedBehavior() {&lt;br /&gt;
    System.out.println(&amp;quot;Decorator does some stuff too&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    component.doStuff();&lt;br /&gt;
    addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
The Client&lt;br /&gt;
&lt;br /&gt;
    import decorator.*;&lt;br /&gt;
    public class Client {&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
    IComponent comp = new Component();&lt;br /&gt;
    Decorator decorator = new ConcreteDecorator(comp);&lt;br /&gt;
    decorator.doStuff();&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
==Comparison of implementations==&lt;br /&gt;
&lt;br /&gt;
Ruby provides different options to implement Decorator pattern like method_missing, delegation and alias methods. This provides flexibility to the user to implement any possible way depending on the requirements and features needed. But in Java, there is more clearer approach using the components provided in the example. It is a straight forward approach. But different options provided by Ruby make it much better than Java.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages like Javascript, decorator pattern can be implemented with no interfaces or traditional OOP inheritance. With simple overriding but this approach is difficult to implement [http://en.wikipedia.org/wiki/Decorator_pattern#JavaScript].&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
We have seen four design patterns Factory design pattern, Abstract Factory design pattern, Iterator design pattern and Decorator Design Pattern. We have chosen these patterns as they are widely used and Ruby has in-built implementations of these. We have mainly tried to compare Ruby and Java but also specified tips about other languages like PHP, C# and Javascript. In Ruby implementing these design patterns is simple and easy because of its main feature of private class objects, unbounded polymorphism and duck typing [http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf]. In Java all the features are mainly implemented through interfaces and classes. This has several disadvantages like increase in code complexity, size and is generally confusing and tedious to trace or understand the code.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf Design Patterns]&lt;br /&gt;
#[http://www.patterndepot.com/put/8/JavaPatterns.htm Design Patterns Java Companion James W Cooper]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 Wiki Design Patterns]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory Method]&lt;br /&gt;
#[http://sourcemaking.com/design_patterns/abstract_factory SourceMaking explains Abstract Factory]&lt;br /&gt;
#[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf Abstract Factory Example in Java]&lt;br /&gt;
#[http://www.dofactory.com/Patterns/PatternAbstract.aspx Abstract Factory explained]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Iterator_pattern Iterator Pattern]&lt;br /&gt;
#[http://sourcemaking.com/design_patterns/iterator Sourcemaking explains Iterator method]&lt;br /&gt;
#[http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf Iterator method explained]&lt;br /&gt;
#[http://www.dofactory.com/Patterns/PatternIterator.aspx DoFactory explains Iterator pattern]&lt;br /&gt;
#[http://us3.php.net/manual/en/language.oop5.iterations.php Iterator pattern for PHP]&lt;br /&gt;
#[http://www.patterndepot.com/put/8/Decorator.pdf Decorator Pattern]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Decorator_pattern Wiki Decorator Pattern]&lt;br /&gt;
#[http://www.scribd.com/doc/2217773/Design-Patterns-in-Ruby Design Patterns in Ruby]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Decorator_pattern#JavaScript Design Patterns Javascript]&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=23267</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 11 zv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=23267"/>
		<updated>2009-10-09T00:19:16Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''What facilities does Ruby offer that makes it easier to realize other GoF (and other) patterns that we did not cover in class? The key idea here is to explore how Ruby can implement these patterns more efficiently or transparently than static (or other dynamic) o-o languages.''&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Before starting off with design patterns for Ruby we need to define what a design pattern is, Design patterns can be described as &amp;quot;a general reusable solution to a commonly occurring problem in software design.&amp;quot; [http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29]&lt;br /&gt;
&amp;quot;The idea of design patterns is to not to reinvent the wheel but to solve the current problems by using solutions that have worked in the past&amp;quot; [http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf]. A design pattern names, abstracts, and identifies the key aspects of a common design structure that make it useful for creating a reusable object-oriented design. It helps to identify the classes and instances and the way they collaborate with each other to form a solution to a problem. Design patterns can be classified into 3 parts [http://en.wikipedia.org/wiki/Creational_pattern Creational], [http://en.wikipedia.org/wiki/Structural_pattern Structural], [http://en.wikipedia.org/wiki/Behavioral_pattern Behavioral] [http://www.patterndepot.com/put/8/JavaPatterns.htm].&lt;br /&gt;
&lt;br /&gt;
=Factory=&lt;br /&gt;
Factories&lt;br /&gt;
The factory design pattern is an object oriented design pattern. It is a creational design pattern and deals with the issues faced in creating objects.&lt;br /&gt;
The main goal of this implementation is to isolate teh code that creates the class form the concete implementation of that class. Ruby example for the same is given below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Factory Example in Ruby==&lt;br /&gt;
&lt;br /&gt;
    class GearFactory&lt;br /&gt;
      def new() &lt;br /&gt;
        if ( ... some condition )&lt;br /&gt;
           return Sprocket.new()&lt;br /&gt;
        else&lt;br /&gt;
           return Cog().new()&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Our client class now becomes:&lt;br /&gt;
    class GearUser &lt;br /&gt;
      def doSomething(factory )&lt;br /&gt;
        ...&lt;br /&gt;
      my_gear = factory.new()&lt;br /&gt;
        ...&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The above code does not have to distinguish between a factory and an ordinary class. We can call the class using the followijng code.&lt;br /&gt;
    client.doSomething(GearFactory.new)          #Use the factory&lt;br /&gt;
    client.doSomething(Cog)                      #Use the Cog class&lt;br /&gt;
    client.doSomething(Sprocket)                 #Use the Sprocket class&lt;br /&gt;
&lt;br /&gt;
==Factory Example in Java==&lt;br /&gt;
In java the Factory implementation is done using interfaces. Declaring them as interfaces helps to maintain a general overview and not depending on the type of factory object that needs to be used. All of these can be placed in a huge factory in a client application.&lt;br /&gt;
A well known example for Java Factory is the UI toolkits that are designed to run on different windowing systems.&lt;br /&gt;
    interface ScrollBar { ... }&lt;br /&gt;
    interface MenuBar   { ... }&lt;br /&gt;
    ...&lt;br /&gt;
And associated classes implementing them on different windowing systems:&lt;br /&gt;
&lt;br /&gt;
    class MotifScrollBar implements ScrollBar { ... }&lt;br /&gt;
    class Win95ScrollBar implements ScrollBar { ... }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
And a factory interface that also doesn't commit to representation:&lt;br /&gt;
&lt;br /&gt;
    interface Factory {&lt;br /&gt;
      public abstract ScrollBar newScrollBar();&lt;br /&gt;
      public abstract MenuBar   newMenuBar();&lt;br /&gt;
      ... &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
But implementation classes that do:&lt;br /&gt;
&lt;br /&gt;
    class MotifFactory implements Factory {&lt;br /&gt;
      public ScrollBar newScrollBar() { return new MotifScrollBar(...); }&lt;br /&gt;
      ...&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory Pattern=&lt;br /&gt;
==What is Abstract Factory Pattern?==&lt;br /&gt;
Abstract Factory Design Pattern encapsulates a group of objects that have common theme. It implements a generic interface to create these objects that are part of the theme. It does not care about the details of the implementation of these objects. The Abstract Factory pattern, a class delegates the responsibility of object instantiation to another object via composition. It is a type of Creational pattern [http://en.wikipedia.org/wiki/Abstract_factory_pattern] “Provide an interface for creating families of related or dependent objects without specifying their concrete classes” [http://sourcemaking.com/design_patterns/abstract_factory]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
Ruby automatically implements the Abstract Factory pattern as Class Objects. All Class objects have the same interface: the new method of each class object creates new instances of the class. Thus the code can pass references to class objects around and they can be used to call new method without knowing the exact type of object that the class creates.&lt;br /&gt;
&lt;br /&gt;
    Class Foo; end&lt;br /&gt;
    Class Bar, end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is the use of Abstract Factory Pattern&lt;br /&gt;
    &lt;br /&gt;
    def create_something(factory)&lt;br /&gt;
	new_object = factory.new&lt;br /&gt;
	puts &amp;quot;created a new #{new_object.class} with a factory&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Here we select a factory to use&lt;br /&gt;
    Create_something(Foo)&lt;br /&gt;
    Create_something(Bar)&lt;br /&gt;
&lt;br /&gt;
Output of the code:&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Foo with a factory&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Bar with a factory&lt;br /&gt;
&lt;br /&gt;
The create_something method is creating objects through an abstract interface. It does not have details about implementation used to create these objects. Thus the use of create_something() is used to shield the rest of the code from that knowledge.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
In Java, implementing  Abstract Factory design pattern we need to create a class which has method who defers creation of product objects to its concrete class. This class then needs to be ”extended” by the client class which uses only these interfaces to create objects of concrete class&lt;br /&gt;
[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf]. In Java, Abstract Factory defines a different method for the creation of each product it can produce. The following example shows an implementation of Abstract Factory design pattern in Java. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   public class FactoryFmProto {&lt;br /&gt;
  static class Expression {&lt;br /&gt;
   protected String str;&lt;br /&gt;
   public Expression( String s ) { str = s; }&lt;br /&gt;
   public Expression cloan()     { return null; }&lt;br /&gt;
   public String     toString()  { return str; }&lt;br /&gt;
  }&lt;br /&gt;
  static abstract class Factory {&lt;br /&gt;
   protected Expression prototype = null;&lt;br /&gt;
   public Expression makePhrase() { return prototype.cloan(); }&lt;br /&gt;
   public abstract Expression makeCompromise();&lt;br /&gt;
   public abstract Expression makeGrade();&lt;br /&gt;
  }&lt;br /&gt;
  static class PCFactory extends Factory {&lt;br /&gt;
   public PCFactory() { prototype = new PCPhrase(); }&lt;br /&gt;
   public Expression makeCompromise() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;do it your way, any way, or no way\&amp;quot;&amp;quot; ); }&lt;br /&gt;
   public Expression makeGrade() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;you pass, self-esteem intact\&amp;quot;&amp;quot; ); }&lt;br /&gt;
  }&lt;br /&gt;
   static class NotPCFactory extends Factory {&lt;br /&gt;
   public NotPCFactory() { prototype = new NotPCPhrase(); }&lt;br /&gt;
   public Expression makeCompromise() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;my way, or the highway\&amp;quot;&amp;quot; ); }&lt;br /&gt;
   public Expression makeGrade() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;take test, deal with the results\&amp;quot;&amp;quot; ); }&lt;br /&gt;
  }&lt;br /&gt;
   public static void main( String[] args ) {&lt;br /&gt;
   Factory factory;&lt;br /&gt;
   if (args.length &amp;gt; 0) factory = new PCFactory();&lt;br /&gt;
   else                 factory = new NotPCFactory();&lt;br /&gt;
   for (int i=0; i &amp;lt; 3; i++) System.out.print( factory.makePhrase() + &amp;quot;  &amp;quot; );&lt;br /&gt;
   System.out.println();&lt;br /&gt;
   System.out.println( factory.makeCompromise() );&lt;br /&gt;
   System.out.println( factory.makeGrade() );&lt;br /&gt;
  }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
Basically, Java and Ruby, both can implement Abstract Factory design pattern. But the more important point is the simplicity by which they can apply it. Ruby automatically implements the Abstract Factory pattern as Class Objects. But Java needs helps of interfaces and classes to do so. Thus Java implementation needs a well defined interface to do so but in Ruby it is directly implemented because of private class object property.&lt;br /&gt;
&lt;br /&gt;
Similarly, C# demonstrates the Abstract Factory pattern by creating parallel hierarchies of objects. Object creation has been abstracted and there is no need for hard-coded class names in the client code. This property helps C# to have better implementation than Java. In .NET, there are built in features such as, generics, reflection, object initializers, automatic properties, etc for implementation [http://www.dofactory.com/Patterns/PatternAbstract.aspx].&lt;br /&gt;
&lt;br /&gt;
=Iterator Design Pattern=&lt;br /&gt;
==What is Iterator Design Pattern?==&lt;br /&gt;
The Iterator design pattern allows an object to encapsulate the internal structure and allows the user to move through the collection of data using standard interface. It is one of the simplest and most frequently used design pattern. It is a type of Behavioral design pattern [http://en.wikipedia.org/wiki/Iterator_pattern]. “Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.” [http://sourcemaking.com/design_patterns/iterator]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
Ruby implements iterators with blocks and the ‘each’ method, and with ‘for..in’ statements. For example consider the following example;&lt;br /&gt;
&lt;br /&gt;
    def print_element(container)&lt;br /&gt;
    	Container.each {|o| puts o.inspect }&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    list = [1,2,2,3]&lt;br /&gt;
    hash = {“a”=&amp;gt;1, “b”=&amp;gt;2,”c”=&amp;gt;3, “d”=&amp;gt;4 }&lt;br /&gt;
    print_elements list&lt;br /&gt;
    print_elements hash&lt;br /&gt;
&lt;br /&gt;
The output of the code is,&lt;br /&gt;
    1&lt;br /&gt;
    2&lt;br /&gt;
    3&lt;br /&gt;
    4&lt;br /&gt;
    [“a”,1]&lt;br /&gt;
    [“b”,2]&lt;br /&gt;
    [“c”,3]&lt;br /&gt;
    [“d”,4]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
&lt;br /&gt;
In Java, we can implement Iterator design pattern by using java.util.Enumeration interface which returns a reference to an object. Furthermore, Hashes and Vector have limited capabilities which help simple traversing. Java JDK 1.2 introduced a new Collections package with more aggregate classes, including sets, lists, maps and an Iterator interface. If we wanted to start implementing Iterator design pattern from start, then it would again involve having an interface for accessing and traversing the elements which is further implemented by the concrete class.  Thus a class who needs to access the list will need to call the interface class [http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf]. For example, consider the following scenario where iterator.First() and iterator.Next(), has been implemented in the class ListIterator.&lt;br /&gt;
&lt;br /&gt;
    ...&lt;br /&gt;
    List list = new List();&lt;br /&gt;
    ...&lt;br /&gt;
    ListIterator iterator = new ListIterator(list);&lt;br /&gt;
    iterator.First();&lt;br /&gt;
    while (!iterator.IsDone()) {&lt;br /&gt;
    Object item = iterator.CurrentItem();&lt;br /&gt;
    // Code here to process item.&lt;br /&gt;
    iterator.Next();&lt;br /&gt;
    }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
&lt;br /&gt;
Overall implementation of Iterator design pattern in each object oriented language is simple as it is a basis feature of objects. But in general, the Ruby implementation is more concise. Ruby has built-in iterators which make it easier to implement Iterator pattern for any kind of object. It hides the structure and there is no need for having implementation for those methods in the class. But in Java, the built-in library function help to create easier and clear implementations. C# also has similar implementation as Java for this design pattern [http://www.dofactory.com/Patterns/PatternIterator.aspx]. &lt;br /&gt;
&lt;br /&gt;
In PHP, using an object in a foreach structure will traverse the public values. There are also many multiple Iterator classes available to allow us to iterate through common lists, such as directories, XML structures and recursive arrays. We can also implement our own interfaces depending on requirement [http://us3.php.net/manual/en/language.oop5.iterations.php].&lt;br /&gt;
&lt;br /&gt;
=Decorator Pattern=&lt;br /&gt;
&lt;br /&gt;
This pattern is used to increase the functionality of the existing object dynamically. Suppose we have a program that uses eight objects, but three of them need an additional feature. We could create derived class for these objects having the additional features but then we can create a Decorator class which will add any specific kind of feature required [http://www.patterndepot.com/put/8/Decorator.pdf]. It is a type of behavioral pattern.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
&lt;br /&gt;
Generic decorators can be implmented by using the method_missing method. This method is called when an object receives a message that it does not have a method fo. The method_missing method can forward the message on to other object and wrap additional behavior around the call. In this example we talk about how a coffee class can have many addtions to it like coffee with cream, sprinkles, milk etc and creating a class for each of them will not be the correct solution.In this example the cost can be calculated according to what is sent to it.Cost of the coffee is 2 and the cost of White coffee (coffee + milk) = 2.4. So what happens when we execute the Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost we get the result as 2.9 as the cost of the coffee is 2, the decorator object (now only coffee) is sent to the Milk and it becomes 2.4, which now is then sent to the Whip which is going to be 2.4 + 02 = 2.6 and finally to Sprinkles which becomes 2.6 + 0.3 = 2.9. The below code is an example of decorators where we just create a place holder and we can use this function to perform different functions depending on the parameters supplied to it. The need for this kind of pattern is so as to increase the functionality of a particular class [http://en.wikipedia.org/wiki/Decorator_pattern]. &lt;br /&gt;
&lt;br /&gt;
    module Decorator&lt;br /&gt;
      def initialize(decorated)&lt;br /&gt;
        @decorated = decorated&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    def method_missing(method, *args)&lt;br /&gt;
        args.empty? ? @decorated.send(method) : @decorated.send(method, args)&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
    class Whip&lt;br /&gt;
      include Decorator&lt;br /&gt;
      def cost &lt;br /&gt;
        @decorated.cost + 0.2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    class Sprinkles&lt;br /&gt;
      include Decorator&lt;br /&gt;
&lt;br /&gt;
      def cost&lt;br /&gt;
        @decorated.cost + 0.3&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    Whip.new(Coffee.new).cost&lt;br /&gt;
    #=&amp;gt; 2.2&lt;br /&gt;
    Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost &lt;br /&gt;
    #=&amp;gt; 2.9&lt;br /&gt;
&lt;br /&gt;
There are various other options to implement this design pattern. Other way to implememt the pattern is by using singleton methods and method aliases. Delegation can also be used, and it overcomes one of the most important disadvantage. We can remove add features if we are using delegation but this is not possible if we are using singleton methods and method aliases. Example for this can be found here [http://www.scribd.com/doc/2217773/Design-Patterns-in-Ruby].&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
&lt;br /&gt;
In Java, this pattern is easy to implement by dividing the various responsibilities into classes and interfaces. The below example consider all these responsibilities and have four components which are described below  &lt;br /&gt;
* Component: Defines the interface for objects that can have responsibilities added to them dynamically.&lt;br /&gt;
* ConcreteComponent: Defines an object to which additional responsibilities can be attached.&lt;br /&gt;
* Decorator: maintains a reference to a Component object and defines an interface that conforms to Component's interface.&lt;br /&gt;
* ConcreteDecorator: adds responsibilities to the component.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface IComponent {&lt;br /&gt;
    public void doStuff();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete component&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class Component implements IComponent{&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    System.out.println(&amp;quot;Do Suff&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Decorator&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface Decorator extends IComponent {&lt;br /&gt;
    public void addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete Decorator ('''Extends IComponent''')&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class ConcreteDecorator implements Decorator {&lt;br /&gt;
    IComponent component;&lt;br /&gt;
    public ConcreteDecorator(IComponent component) {&lt;br /&gt;
    super();&lt;br /&gt;
    this.component = component;&lt;br /&gt;
    }&lt;br /&gt;
    public void addedBehavior() {&lt;br /&gt;
    System.out.println(&amp;quot;Decorator does some stuff too&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    component.doStuff();&lt;br /&gt;
    addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
The Client&lt;br /&gt;
&lt;br /&gt;
    import decorator.*;&lt;br /&gt;
    public class Client {&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
    IComponent comp = new Component();&lt;br /&gt;
    Decorator decorator = new ConcreteDecorator(comp);&lt;br /&gt;
    decorator.doStuff();&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
==Comparison of implementations==&lt;br /&gt;
&lt;br /&gt;
Ruby provides different options to implement Decorator pattern like method_missing, delegation and alias methods. This provides flexibility to the user to implement any possible way depending on the requirements and features needed. But in Java, there is more clearer approach using the components provided in the example. It is a straight forward approach. But different options provided by Ruby make it much better than Java.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages like Javascript, decorator pattern can be implemented with no interfaces or traditional OOP inheritance. With simple overriding but this approach is difficult to implement [http://en.wikipedia.org/wiki/Decorator_pattern#JavaScript].&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
We have seen four design patterns Factory design pattern, Abstract Factory design pattern, Iterator design pattern and Decorator Design Pattern. We have chosen these patterns as they are widely used and Ruby has in-built implementations of these. We have mainly tried to compare Ruby and Java but also specified tips about other languages like PHP, C# and Javascript. In Ruby implementing these design patterns is simple and easy because of its main feature of private class objects, unbounded polymorphism and duck typing [http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf]. In Java all the features are mainly implemented through interfaces and classes. This has several disadvantages like increase in code complexity, size and is generally confusing and tedious to trace or understand the code.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf Design Patterns]&lt;br /&gt;
#[http://www.patterndepot.com/put/8/JavaPatterns.htm Design Patterns Java Companion James W Cooper]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 Wiki Design Patterns]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory Method]&lt;br /&gt;
#[http://sourcemaking.com/design_patterns/abstract_factory SourceMaking explains Abstract Factory]&lt;br /&gt;
#[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf Abstract Factory Example in Java]&lt;br /&gt;
#[http://www.dofactory.com/Patterns/PatternAbstract.aspx Abstract Factory explained]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Iterator_pattern Iterator Pattern]&lt;br /&gt;
#[http://sourcemaking.com/design_patterns/iterator Sourcemaking explains Iterator method]&lt;br /&gt;
#[http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf Iterator method explained]&lt;br /&gt;
#[http://www.dofactory.com/Patterns/PatternIterator.aspx DoFactiry explains Iterator pattern]&lt;br /&gt;
#[http://us3.php.net/manual/en/language.oop5.iterations.php Iterator pattern for PHP]&lt;br /&gt;
#[http://www.patterndepot.com/put/8/Decorator.pdf Decorator Pattern]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Decorator_pattern Wiki Decorator Pattern]&lt;br /&gt;
#[http://www.scribd.com/doc/2217773/Design-Patterns-in-Ruby Design Patterns in Ruby]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Decorator_pattern#JavaScript Design Patterns Javascript]&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=23265</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 11 zv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=23265"/>
		<updated>2009-10-09T00:18:16Z</updated>

		<summary type="html">&lt;p&gt;Naruto: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''What facilities does Ruby offer that makes it easier to realize other GoF (and other) patterns that we did not cover in class? The key idea here is to explore how Ruby can implement these patterns more efficiently or transparently than static (or other dynamic) o-o languages.''&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Before starting off with design patterns for Ruby we need to define what a design pattern is, Design patterns can be described as &amp;quot;a general reusable solution to a commonly occurring problem in software design.&amp;quot; [http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29]&lt;br /&gt;
&amp;quot;The idea of design patterns is to not to reinvent the wheel but to solve the current problems by using solutions that have worked in the past&amp;quot; [http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf]. A design pattern names, abstracts, and identifies the key aspects of a common design structure that make it useful for creating a reusable object-oriented design. It helps to identify the classes and instances and the way they collaborate with each other to form a solution to a problem. Design patterns can be classified into 3 parts [http://en.wikipedia.org/wiki/Creational_pattern Creational], [http://en.wikipedia.org/wiki/Structural_pattern Structural], [http://en.wikipedia.org/wiki/Behavioral_pattern Behavioral] [http://www.patterndepot.com/put/8/JavaPatterns.htm].&lt;br /&gt;
&lt;br /&gt;
=Factory=&lt;br /&gt;
Factories&lt;br /&gt;
The factory design pattern is an object oriented design pattern. It is a creational design pattern and deals with the issues faced in creating objects.&lt;br /&gt;
The main goal of this implementation is to isolate teh code that creates the class form the concete implementation of that class. Ruby example for the same is given below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Factory Example in Ruby==&lt;br /&gt;
&lt;br /&gt;
    class GearFactory&lt;br /&gt;
      def new() &lt;br /&gt;
        if ( ... some condition )&lt;br /&gt;
           return Sprocket.new()&lt;br /&gt;
        else&lt;br /&gt;
           return Cog().new()&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Our client class now becomes:&lt;br /&gt;
    class GearUser &lt;br /&gt;
      def doSomething(factory )&lt;br /&gt;
        ...&lt;br /&gt;
      my_gear = factory.new()&lt;br /&gt;
        ...&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The above code does not have to distinguish between a factory and an ordinary class. We can call the class using the followijng code.&lt;br /&gt;
    client.doSomething(GearFactory.new)          #Use the factory&lt;br /&gt;
    client.doSomething(Cog)                      #Use the Cog class&lt;br /&gt;
    client.doSomething(Sprocket)                 #Use the Sprocket class&lt;br /&gt;
&lt;br /&gt;
==Factory Example in Java==&lt;br /&gt;
In java the Factory implementation is done using interfaces. Declaring them as interfaces helps to maintain a general overview and not depending on the type of factory object that needs to be used. All of these can be placed in a huge factory in a client application.&lt;br /&gt;
A well known example for Java Factory is the UI toolkits that are designed to run on different windowing systems.&lt;br /&gt;
    interface ScrollBar { ... }&lt;br /&gt;
    interface MenuBar   { ... }&lt;br /&gt;
    ...&lt;br /&gt;
And associated classes implementing them on different windowing systems:&lt;br /&gt;
&lt;br /&gt;
    class MotifScrollBar implements ScrollBar { ... }&lt;br /&gt;
    class Win95ScrollBar implements ScrollBar { ... }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
And a factory interface that also doesn't commit to representation:&lt;br /&gt;
&lt;br /&gt;
    interface Factory {&lt;br /&gt;
      public abstract ScrollBar newScrollBar();&lt;br /&gt;
      public abstract MenuBar   newMenuBar();&lt;br /&gt;
      ... &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
But implementation classes that do:&lt;br /&gt;
&lt;br /&gt;
    class MotifFactory implements Factory {&lt;br /&gt;
      public ScrollBar newScrollBar() { return new MotifScrollBar(...); }&lt;br /&gt;
      ...&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory Pattern=&lt;br /&gt;
==What is Abstract Factory Pattern?==&lt;br /&gt;
Abstract Factory Design Pattern encapsulates a group of objects that have common theme. It implements a generic interface to create these objects that are part of the theme. It does not care about the details of the implementation of these objects. The Abstract Factory pattern, a class delegates the responsibility of object instantiation to another object via composition. It is a type of Creational pattern [http://en.wikipedia.org/wiki/Abstract_factory_pattern] “Provide an interface for creating families of related or dependent objects without specifying their concrete classes” [http://sourcemaking.com/design_patterns/abstract_factory]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
Ruby automatically implements the Abstract Factory pattern as Class Objects. All Class objects have the same interface: the new method of each class object creates new instances of the class. Thus the code can pass references to class objects around and they can be used to call new method without knowing the exact type of object that the class creates.&lt;br /&gt;
&lt;br /&gt;
    Class Foo; end&lt;br /&gt;
    Class Bar, end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is the use of Abstract Factory Pattern&lt;br /&gt;
    &lt;br /&gt;
    def create_something(factory)&lt;br /&gt;
	new_object = factory.new&lt;br /&gt;
	puts &amp;quot;created a new #{new_object.class} with a factory&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Here we select a factory to use&lt;br /&gt;
    Create_something(Foo)&lt;br /&gt;
    Create_something(Bar)&lt;br /&gt;
&lt;br /&gt;
Output of the code:&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Foo with a factory&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Bar with a factory&lt;br /&gt;
&lt;br /&gt;
The create_something method is creating objects through an abstract interface. It does not have details about implementation used to create these objects. Thus the use of create_something() is used to shield the rest of the code from that knowledge.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
In Java, implementing  Abstract Factory design pattern we need to create a class which has method who defers creation of product objects to its concrete class. This class then needs to be ”extended” by the client class which uses only these interfaces to create objects of concrete class&lt;br /&gt;
[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf]. In Java, Abstract Factory defines a different method for the creation of each product it can produce. The following example shows an implementation of Abstract Factory design pattern in Java. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   public class FactoryFmProto {&lt;br /&gt;
  static class Expression {&lt;br /&gt;
   protected String str;&lt;br /&gt;
   public Expression( String s ) { str = s; }&lt;br /&gt;
   public Expression cloan()     { return null; }&lt;br /&gt;
   public String     toString()  { return str; }&lt;br /&gt;
  }&lt;br /&gt;
  static abstract class Factory {&lt;br /&gt;
   protected Expression prototype = null;&lt;br /&gt;
   public Expression makePhrase() { return prototype.cloan(); }&lt;br /&gt;
   public abstract Expression makeCompromise();&lt;br /&gt;
   public abstract Expression makeGrade();&lt;br /&gt;
  }&lt;br /&gt;
  static class PCFactory extends Factory {&lt;br /&gt;
   public PCFactory() { prototype = new PCPhrase(); }&lt;br /&gt;
   public Expression makeCompromise() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;do it your way, any way, or no way\&amp;quot;&amp;quot; ); }&lt;br /&gt;
   public Expression makeGrade() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;you pass, self-esteem intact\&amp;quot;&amp;quot; ); }&lt;br /&gt;
  }&lt;br /&gt;
   static class NotPCFactory extends Factory {&lt;br /&gt;
   public NotPCFactory() { prototype = new NotPCPhrase(); }&lt;br /&gt;
   public Expression makeCompromise() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;my way, or the highway\&amp;quot;&amp;quot; ); }&lt;br /&gt;
   public Expression makeGrade() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;take test, deal with the results\&amp;quot;&amp;quot; ); }&lt;br /&gt;
  }&lt;br /&gt;
   public static void main( String[] args ) {&lt;br /&gt;
   Factory factory;&lt;br /&gt;
   if (args.length &amp;gt; 0) factory = new PCFactory();&lt;br /&gt;
   else                 factory = new NotPCFactory();&lt;br /&gt;
   for (int i=0; i &amp;lt; 3; i++) System.out.print( factory.makePhrase() + &amp;quot;  &amp;quot; );&lt;br /&gt;
   System.out.println();&lt;br /&gt;
   System.out.println( factory.makeCompromise() );&lt;br /&gt;
   System.out.println( factory.makeGrade() );&lt;br /&gt;
  }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
Basically, Java and Ruby, both can implement Abstract Factory design pattern. But the more important point is the simplicity by which they can apply it. Ruby automatically implements the Abstract Factory pattern as Class Objects. But Java needs helps of interfaces and classes to do so. Thus Java implementation needs a well defined interface to do so but in Ruby it is directly implemented because of private class object property.&lt;br /&gt;
&lt;br /&gt;
Similarly, C# demonstrates the Abstract Factory pattern by creating parallel hierarchies of objects. Object creation has been abstracted and there is no need for hard-coded class names in the client code. This property helps C# to have better implementation than Java. In .NET, there are built in features such as, generics, reflection, object initializers, automatic properties, etc for implementation [http://www.dofactory.com/Patterns/PatternAbstract.aspx].&lt;br /&gt;
&lt;br /&gt;
=Iterator Design Pattern=&lt;br /&gt;
==What is Iterator Design Pattern?==&lt;br /&gt;
The Iterator design pattern allows an object to encapsulate the internal structure and allows the user to move through the collection of data using standard interface. It is one of the simplest and most frequently used design pattern. It is a type of Behavioral design pattern [http://en.wikipedia.org/wiki/Iterator_pattern]. “Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.” [http://sourcemaking.com/design_patterns/iterator]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
Ruby implements iterators with blocks and the ‘each’ method, and with ‘for..in’ statements. For example consider the following example;&lt;br /&gt;
&lt;br /&gt;
    def print_element(container)&lt;br /&gt;
    	Container.each {|o| puts o.inspect }&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    list = [1,2,2,3]&lt;br /&gt;
    hash = {“a”=&amp;gt;1, “b”=&amp;gt;2,”c”=&amp;gt;3, “d”=&amp;gt;4 }&lt;br /&gt;
    print_elements list&lt;br /&gt;
    print_elements hash&lt;br /&gt;
&lt;br /&gt;
The output of the code is,&lt;br /&gt;
    1&lt;br /&gt;
    2&lt;br /&gt;
    3&lt;br /&gt;
    4&lt;br /&gt;
    [“a”,1]&lt;br /&gt;
    [“b”,2]&lt;br /&gt;
    [“c”,3]&lt;br /&gt;
    [“d”,4]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
&lt;br /&gt;
In Java, we can implement Iterator design pattern by using java.util.Enumeration interface which returns a reference to an object. Furthermore, Hashes and Vector have limited capabilities which help simple traversing. Java JDK 1.2 introduced a new Collections package with more aggregate classes, including sets, lists, maps and an Iterator interface. If we wanted to start implementing Iterator design pattern from start, then it would again involve having an interface for accessing and traversing the elements which is further implemented by the concrete class.  Thus a class who needs to access the list will need to call the interface class [http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf]. For example, consider the following scenario where iterator.First() and iterator.Next(), has been implemented in the class ListIterator.&lt;br /&gt;
&lt;br /&gt;
    ...&lt;br /&gt;
    List list = new List();&lt;br /&gt;
    ...&lt;br /&gt;
    ListIterator iterator = new ListIterator(list);&lt;br /&gt;
    iterator.First();&lt;br /&gt;
    while (!iterator.IsDone()) {&lt;br /&gt;
    Object item = iterator.CurrentItem();&lt;br /&gt;
    // Code here to process item.&lt;br /&gt;
    iterator.Next();&lt;br /&gt;
    }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
&lt;br /&gt;
Overall implementation of Iterator design pattern in each object oriented language is simple as it is a basis feature of objects. But in general, the Ruby implementation is more concise. Ruby has built-in iterators which make it easier to implement Iterator pattern for any kind of object. It hides the structure and there is no need for having implementation for those methods in the class. But in Java, the built-in library function help to create easier and clear implementations. C# also has similar implementation as Java for this design pattern [http://www.dofactory.com/Patterns/PatternIterator.aspx]. &lt;br /&gt;
&lt;br /&gt;
In PHP, using an object in a foreach structure will traverse the public values. There are also many multiple Iterator classes available to allow us to iterate through common lists, such as directories, XML structures and recursive arrays. We can also implement our own interfaces depending on requirement [http://us3.php.net/manual/en/language.oop5.iterations.php].&lt;br /&gt;
&lt;br /&gt;
=Decorator Pattern=&lt;br /&gt;
&lt;br /&gt;
This pattern is used to increase the functionality of the existing object dynamically. Suppose we have a program that uses eight objects, but three of them need an additional feature. We could create derived class for these objects having the additional features but then we can create a Decorator class which will add any specific kind of feature required [http://www.patterndepot.com/put/8/Decorator.pdf]. It is a type of behavioral pattern.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
&lt;br /&gt;
Generic decorators can be implmented by using the method_missing method. This method is called when an object receives a message that it does not have a method fo. The method_missing method can forward the message on to other object and wrap additional behavior around the call. In this example we talk about how a coffee class can have many addtions to it like coffee with cream, sprinkles, milk etc and creating a class for each of them will not be the correct solution.In this example the cost can be calculated according to what is sent to it.Cost of the coffee is 2 and the cost of White coffee (coffee + milk) = 2.4. So what happens when we execute the Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost we get the result as 2.9 as the cost of the coffee is 2, the decorator object (now only coffee) is sent to the Milk and it becomes 2.4, which now is then sent to the Whip which is going to be 2.4 + 02 = 2.6 and finally to Sprinkles which becomes 2.6 + 0.3 = 2.9. The below code is an example of decorators where we just create a place holder and we can use this function to perform different functions depending on the parameters supplied to it. The need for this kind of pattern is so as to increase the functionality of a particular class [http://en.wikipedia.org/wiki/Decorator_pattern]. &lt;br /&gt;
&lt;br /&gt;
    module Decorator&lt;br /&gt;
      def initialize(decorated)&lt;br /&gt;
        @decorated = decorated&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    def method_missing(method, *args)&lt;br /&gt;
        args.empty? ? @decorated.send(method) : @decorated.send(method, args)&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
    class Whip&lt;br /&gt;
      include Decorator&lt;br /&gt;
      def cost &lt;br /&gt;
        @decorated.cost + 0.2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    class Sprinkles&lt;br /&gt;
      include Decorator&lt;br /&gt;
&lt;br /&gt;
      def cost&lt;br /&gt;
        @decorated.cost + 0.3&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    Whip.new(Coffee.new).cost&lt;br /&gt;
    #=&amp;gt; 2.2&lt;br /&gt;
    Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost &lt;br /&gt;
    #=&amp;gt; 2.9&lt;br /&gt;
&lt;br /&gt;
There are various other options to implement this design pattern. Other way to implememt the pattern is by using singleton methods and method aliases. Delegation can also be used, and it overcomes one of the most important disadvantage. We can remove add features if we are using delegation but this is not possible if we are using singleton methods and method aliases. Example for this can be found here [http://www.scribd.com/doc/2217773/Design-Patterns-in-Ruby].&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
&lt;br /&gt;
In Java, this pattern is easy to implement by dividing the various responsibilities into classes and interfaces. The below example consider all these responsibilities and have four components which are described below  &lt;br /&gt;
* Component: Defines the interface for objects that can have responsibilities added to them dynamically.&lt;br /&gt;
* ConcreteComponent: Defines an object to which additional responsibilities can be attached.&lt;br /&gt;
* Decorator: maintains a reference to a Component object and defines an interface that conforms to Component's interface.&lt;br /&gt;
* ConcreteDecorator: adds responsibilities to the component.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface IComponent {&lt;br /&gt;
    public void doStuff();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete component&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class Component implements IComponent{&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    System.out.println(&amp;quot;Do Suff&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Decorator&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface Decorator extends IComponent {&lt;br /&gt;
    public void addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete Decorator ('''Extends IComponent''')&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class ConcreteDecorator implements Decorator {&lt;br /&gt;
    IComponent component;&lt;br /&gt;
    public ConcreteDecorator(IComponent component) {&lt;br /&gt;
    super();&lt;br /&gt;
    this.component = component;&lt;br /&gt;
    }&lt;br /&gt;
    public void addedBehavior() {&lt;br /&gt;
    System.out.println(&amp;quot;Decorator does some stuff too&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    component.doStuff();&lt;br /&gt;
    addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
The Client&lt;br /&gt;
&lt;br /&gt;
    import decorator.*;&lt;br /&gt;
    public class Client {&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
    IComponent comp = new Component();&lt;br /&gt;
    Decorator decorator = new ConcreteDecorator(comp);&lt;br /&gt;
    decorator.doStuff();&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
==Comparison of implementations==&lt;br /&gt;
&lt;br /&gt;
Ruby provides different options to implement Decorator pattern like method_missing, delegation and alias methods. This provides flexibility to the user to implement any possible way depending on the requirements and features needed. But in Java, there is more clearer approach using the components provided in the example. It is a straight forward approach. But different options provided by Ruby make it much better than Java.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages like Javascript, decorator pattern can be implemented with no interfaces or traditional OOP inheritance. With simple overriding but this approach is difficult to implement [http://en.wikipedia.org/wiki/Decorator_pattern#JavaScript].&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
We have seen four design patterns Factory design pattern, Abstract Factory design pattern, Iterator design pattern and Decorator Design Pattern. We have chosen these patterns as they are widely used and Ruby has in-built implementations of these. We have mainly tried to compare Ruby and Java but also specified tips about other languages like PHP, C# and Javascript. In Ruby implementing these design patterns is simple and easy because of its main feature of private class objects, unbounded polymorphism and duck typing [http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf]. In Java all the features are mainly implemented through interfaces and classes. This has several disadvantages like increase in code complexity, size and is generally confusing and tedious to trace or understand the code.&lt;br /&gt;
&lt;br /&gt;
=References=&lt;br /&gt;
#[http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf Design Patterns]&lt;br /&gt;
#[http://www.patterndepot.com/put/8/JavaPatterns.htm Design Patterns Java Companion James W Cooper]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29 Wiki Design Patterns]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Abstract_factory_pattern Abstract Factory Method]&lt;br /&gt;
#[http://sourcemaking.com/design_patterns/abstract_factory]&lt;br /&gt;
#[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf Abstract Factory Example in Java]&lt;br /&gt;
#[http://www.dofactory.com/Patterns/PatternAbstract.aspx Abstract Factory explained]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Iterator_pattern Iterator Pattern]&lt;br /&gt;
#[http://sourcemaking.com/design_patterns/iterator Sourcemaking explains Iterator method]&lt;br /&gt;
#[http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf Iterator method explained]&lt;br /&gt;
#[http://www.dofactory.com/Patterns/PatternIterator.aspx DoFactiry explains Iterator pattern]&lt;br /&gt;
#[http://us3.php.net/manual/en/language.oop5.iterations.php Iterator pattern for PHP]&lt;br /&gt;
#[http://www.patterndepot.com/put/8/Decorator.pdf Decorator Pattern]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Decorator_pattern Wiki Decorator Pattern]&lt;br /&gt;
#[http://www.scribd.com/doc/2217773/Design-Patterns-in-Ruby Design Patterns in Ruby]&lt;br /&gt;
#[http://en.wikipedia.org/wiki/Decorator_pattern#JavaScript Design Patterns Javascript]&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=23252</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 11 zv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=23252"/>
		<updated>2009-10-09T00:03:56Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''What facilities does Ruby offer that makes it easier to realize other GoF (and other) patterns that we did not cover in class? The key idea here is to explore how Ruby can implement these patterns more efficiently or transparently than static (or other dynamic) o-o languages.''&lt;br /&gt;
&lt;br /&gt;
=Introduction=&lt;br /&gt;
Before starting off with design patterns for Ruby we need to define what a design pattern is, Design patterns can be described as &amp;quot;a general reusable solution to a commonly occurring problem in software design.&amp;quot; [http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29]&lt;br /&gt;
&amp;quot;The idea of design patterns is to not to reinvent the wheel but to solve the current problems by using solutions that have worked in the past&amp;quot; [http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf]. A design pattern names, abstracts, and identifies the key aspects of a common design structure that make it useful for creating a reusable object-oriented design. It helps to identify the classes and instances and the way they collaborate with each other to form a solution to a problem. Design patterns can be classified into 3 parts [http://en.wikipedia.org/wiki/Creational_pattern Creational], [http://en.wikipedia.org/wiki/Structural_pattern Structural], [http://en.wikipedia.org/wiki/Behavioral_pattern Behavioral] [http://www.patterndepot.com/put/8/JavaPatterns.htm].&lt;br /&gt;
&lt;br /&gt;
=Factory=&lt;br /&gt;
Factories&lt;br /&gt;
The factory design pattern is an object oriented design pattern. It is a creational design pattern and deals with the issues faced in creating objects.&lt;br /&gt;
The main goal of this implementation is to isolate teh code that creates the class form the concete implementation of that class. Ruby example for the same is given below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Factory Example in Ruby==&lt;br /&gt;
&lt;br /&gt;
    class GearFactory&lt;br /&gt;
      def new() &lt;br /&gt;
        if ( ... some condition )&lt;br /&gt;
           return Sprocket.new()&lt;br /&gt;
        else&lt;br /&gt;
           return Cog().new()&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Our client class now becomes:&lt;br /&gt;
    class GearUser &lt;br /&gt;
      def doSomething(factory )&lt;br /&gt;
        ...&lt;br /&gt;
      my_gear = factory.new()&lt;br /&gt;
        ...&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The above code does not have to distinguish between a factory and an ordinary class. We can call the class using the followijng code.&lt;br /&gt;
    client.doSomething(GearFactory.new)          #Use the factory&lt;br /&gt;
    client.doSomething(Cog)                      #Use the Cog class&lt;br /&gt;
    client.doSomething(Sprocket)                 #Use the Sprocket class&lt;br /&gt;
&lt;br /&gt;
==Factory Example in Java==&lt;br /&gt;
In java the Factory implementation is done using interfaces. Declaring them as interfaces helps to maintain a general overview and not depending on the type of factory object that needs to be used. All of these can be placed in a huge factory in a client application.&lt;br /&gt;
A well known example for Java Factory is the UI toolkits that are designed to run on different windowing systems.&lt;br /&gt;
    interface ScrollBar { ... }&lt;br /&gt;
    interface MenuBar   { ... }&lt;br /&gt;
    ...&lt;br /&gt;
And associated classes implementing them on different windowing systems:&lt;br /&gt;
&lt;br /&gt;
    class MotifScrollBar implements ScrollBar { ... }&lt;br /&gt;
    class Win95ScrollBar implements ScrollBar { ... }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
And a factory interface that also doesn't commit to representation:&lt;br /&gt;
&lt;br /&gt;
    interface Factory {&lt;br /&gt;
      public abstract ScrollBar newScrollBar();&lt;br /&gt;
      public abstract MenuBar   newMenuBar();&lt;br /&gt;
      ... &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
But implementation classes that do:&lt;br /&gt;
&lt;br /&gt;
    class MotifFactory implements Factory {&lt;br /&gt;
      public ScrollBar newScrollBar() { return new MotifScrollBar(...); }&lt;br /&gt;
      ...&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=Abstract Factory Pattern=&lt;br /&gt;
==What is Abstract Factory Pattern?==&lt;br /&gt;
Abstract Factory Design Pattern encapsulates a group of objects that have common theme. It implements a generic interface to create these objects that are part of the theme. It does not care about the details of the implementation of these objects. The Abstract Factory pattern, a class delegates the responsibility of object instantiation to another object via composition. It is a type of Creational pattern [http://en.wikipedia.org/wiki/Abstract_factory_pattern] “Provide an interface for creating families of related or dependent objects without specifying their concrete classes” [http://sourcemaking.com/design_patterns/abstract_factory]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
Ruby automatically implements the Abstract Factory pattern as Class Objects. All Class objects have the same interface: the new method of each class object creates new instances of the class. Thus the code can pass references to class objects around and they can be used to call new method without knowing the exact type of object that the class creates.&lt;br /&gt;
&lt;br /&gt;
    Class Foo; end&lt;br /&gt;
    Class Bar, end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is the use of Abstract Factory Pattern&lt;br /&gt;
    &lt;br /&gt;
    def create_something(factory)&lt;br /&gt;
	new_object = factory.new&lt;br /&gt;
	puts &amp;quot;created a new #{new_object.class} with a factory&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Here we select a factory to use&lt;br /&gt;
    Create_something(Foo)&lt;br /&gt;
    Create_something(Bar)&lt;br /&gt;
&lt;br /&gt;
Output of the code:&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Foo with a factory&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Bar with a factory&lt;br /&gt;
&lt;br /&gt;
The create_something method is creating objects through an abstract interface. It does not have details about implementation used to create these objects. Thus the use of create_something() is used to shield the rest of the code from that knowledge.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
In Java, implementing  Abstract Factory design pattern we need to create a class which has method who defers creation of product objects to its concrete class. This class then needs to be ”extended” by the client class which uses only these interfaces to create objects of concrete class&lt;br /&gt;
[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf]. In Java, Abstract Factory defines a different method for the creation of each product it can produce. The following example shows an implementation of Abstract Factory design pattern in Java. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   public class FactoryFmProto {&lt;br /&gt;
  static class Expression {&lt;br /&gt;
   protected String str;&lt;br /&gt;
   public Expression( String s ) { str = s; }&lt;br /&gt;
   public Expression cloan()     { return null; }&lt;br /&gt;
   public String     toString()  { return str; }&lt;br /&gt;
  }&lt;br /&gt;
  static abstract class Factory {&lt;br /&gt;
   protected Expression prototype = null;&lt;br /&gt;
   public Expression makePhrase() { return prototype.cloan(); }&lt;br /&gt;
   public abstract Expression makeCompromise();&lt;br /&gt;
   public abstract Expression makeGrade();&lt;br /&gt;
  }&lt;br /&gt;
  static class PCFactory extends Factory {&lt;br /&gt;
   public PCFactory() { prototype = new PCPhrase(); }&lt;br /&gt;
   public Expression makeCompromise() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;do it your way, any way, or no way\&amp;quot;&amp;quot; ); }&lt;br /&gt;
   public Expression makeGrade() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;you pass, self-esteem intact\&amp;quot;&amp;quot; ); }&lt;br /&gt;
  }&lt;br /&gt;
   static class NotPCFactory extends Factory {&lt;br /&gt;
   public NotPCFactory() { prototype = new NotPCPhrase(); }&lt;br /&gt;
   public Expression makeCompromise() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;my way, or the highway\&amp;quot;&amp;quot; ); }&lt;br /&gt;
   public Expression makeGrade() {&lt;br /&gt;
      return new Expression( &amp;quot;\&amp;quot;take test, deal with the results\&amp;quot;&amp;quot; ); }&lt;br /&gt;
  }&lt;br /&gt;
   public static void main( String[] args ) {&lt;br /&gt;
   Factory factory;&lt;br /&gt;
   if (args.length &amp;gt; 0) factory = new PCFactory();&lt;br /&gt;
   else                 factory = new NotPCFactory();&lt;br /&gt;
   for (int i=0; i &amp;lt; 3; i++) System.out.print( factory.makePhrase() + &amp;quot;  &amp;quot; );&lt;br /&gt;
   System.out.println();&lt;br /&gt;
   System.out.println( factory.makeCompromise() );&lt;br /&gt;
   System.out.println( factory.makeGrade() );&lt;br /&gt;
  }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
Basically, Java and Ruby, both can implement Abstract Factory design pattern. But the more important point is the simplicity by which they can apply it. Ruby automatically implements the Abstract Factory pattern as Class Objects. But Java needs helps of interfaces and classes to do so. Thus Java implementation needs a well defined interface to do so but in Ruby it is directly implemented because of private class object property.&lt;br /&gt;
&lt;br /&gt;
Similarly, C# demonstrates the Abstract Factory pattern by creating parallel hierarchies of objects. Object creation has been abstracted and there is no need for hard-coded class names in the client code. This property helps C# to have better implementation than Java. In .NET, there are built in features such as, generics, reflection, object initializers, automatic properties, etc for implementation [http://www.dofactory.com/Patterns/PatternAbstract.aspx].&lt;br /&gt;
&lt;br /&gt;
=Iterator Design Pattern=&lt;br /&gt;
==What is Iterator Design Pattern?==&lt;br /&gt;
The Iterator design pattern allows an object to encapsulate the internal structure and allows the user to move through the collection of data using standard interface. It is one of the simplest and most frequently used design pattern. It is a type of Behavioral design pattern [http://en.wikipedia.org/wiki/Iterator_pattern]. “Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.” [http://sourcemaking.com/design_patterns/iterator]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
Ruby implements iterators with blocks and the ‘each’ method, and with ‘for..in’ statements. For example consider the following example;&lt;br /&gt;
&lt;br /&gt;
    def print_element(container)&lt;br /&gt;
    	Container.each {|o| puts o.inspect }&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    list = [1,2,2,3]&lt;br /&gt;
    hash = {“a”=&amp;gt;1, “b”=&amp;gt;2,”c”=&amp;gt;3, “d”=&amp;gt;4 }&lt;br /&gt;
    print_elements list&lt;br /&gt;
    print_elements hash&lt;br /&gt;
&lt;br /&gt;
The output of the code is,&lt;br /&gt;
    1&lt;br /&gt;
    2&lt;br /&gt;
    3&lt;br /&gt;
    4&lt;br /&gt;
    [“a”,1]&lt;br /&gt;
    [“b”,2]&lt;br /&gt;
    [“c”,3]&lt;br /&gt;
    [“d”,4]&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
&lt;br /&gt;
In Java, we can implement Iterator design pattern by using java.util.Enumeration interface which returns a reference to an object. Furthermore, Hashes and Vector have limited capabilities which help simple traversing. Java JDK 1.2 introduced a new Collections package with more aggregate classes, including sets, lists, maps and an Iterator interface. If we wanted to start implementing Iterator design pattern from start, then it would again involve having an interface for accessing and traversing the elements which is further implemented by the concrete class.  Thus a class who needs to access the list will need to call the interface class [http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf]. For example, consider the following scenario where iterator.First() and iterator.Next(), has been implemented in the class ListIterator.&lt;br /&gt;
&lt;br /&gt;
    ...&lt;br /&gt;
    List list = new List();&lt;br /&gt;
    ...&lt;br /&gt;
    ListIterator iterator = new ListIterator(list);&lt;br /&gt;
    iterator.First();&lt;br /&gt;
    while (!iterator.IsDone()) {&lt;br /&gt;
    Object item = iterator.CurrentItem();&lt;br /&gt;
    // Code here to process item.&lt;br /&gt;
    iterator.Next();&lt;br /&gt;
    }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
==Comparison of Implementations==&lt;br /&gt;
&lt;br /&gt;
Overall implementation of Iterator design pattern in each object oriented language is simple as it is a basis feature of objects. But in general, the Ruby implementation is more concise. Ruby has built-in iterators which make it easier to implement Iterator pattern for any kind of object. It hides the structure and there is no need for having implementation for those methods in the class. But in Java, the built-in library function help to create easier and clear implementations. C# also has similar implementation as Java for this design pattern [http://www.dofactory.com/Patterns/PatternIterator.aspx]. &lt;br /&gt;
&lt;br /&gt;
In PHP, using an object in a foreach structure will traverse the public values. There are also many multiple Iterator classes available to allow us to iterate through common lists, such as directories, XML structures and recursive arrays. We can also implement our own interfaces depending on requirement [http://us3.php.net/manual/en/language.oop5.iterations.php].&lt;br /&gt;
&lt;br /&gt;
=Decorator Pattern=&lt;br /&gt;
&lt;br /&gt;
This pattern is used to increase the functionality of the existing object dynamically. Suppose we have a program that uses eight objects, but three of them need an additional feature. We could create derived class for these objects having the additional features but then we can create a Decorator class which will add any specific kind of feature required [http://www.patterndepot.com/put/8/Decorator.pdf]. It is a type of behavioral pattern.&lt;br /&gt;
&lt;br /&gt;
==Implementation in Ruby==&lt;br /&gt;
&lt;br /&gt;
Generic decorators can be implmented by using the method_missing method. This method is called when an object receives a message that it does not have a method fo. The method_missing method can forward the message on to other object and wrap additional behavior around the call. In this example we talk about how a coffee class can have many addtions to it like coffee with cream, sprinkles, milk etc and creating a class for each of them will not be the correct solution.In this example the cost can be calculated according to what is sent to it.Cost of the coffee is 2 and the cost of White coffee (coffee + milk) = 2.4. So what happens when we execute the Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost we get the result as 2.9 as the cost of the coffee is 2, the decorator object (now only coffee) is sent to the Milk and it becomes 2.4, which now is then sent to the Whip which is going to be 2.4 + 02 = 2.6 and finally to Sprinkles which becomes 2.6 + 0.3 = 2.9. The below code is an example of decorators where we just create a place holder and we can use this function to perform different functions depending on the parameters supplied to it. The need for this kind of pattern is so as to increase the functionality of a particular class [http://en.wikipedia.org/wiki/Decorator_pattern]. &lt;br /&gt;
&lt;br /&gt;
    module Decorator&lt;br /&gt;
      def initialize(decorated)&lt;br /&gt;
        @decorated = decorated&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    def method_missing(method, *args)&lt;br /&gt;
        args.empty? ? @decorated.send(method) : @decorated.send(method, args)&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
    class Whip&lt;br /&gt;
      include Decorator&lt;br /&gt;
      def cost &lt;br /&gt;
        @decorated.cost + 0.2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    class Sprinkles&lt;br /&gt;
      include Decorator&lt;br /&gt;
&lt;br /&gt;
      def cost&lt;br /&gt;
        @decorated.cost + 0.3&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    Whip.new(Coffee.new).cost&lt;br /&gt;
    #=&amp;gt; 2.2&lt;br /&gt;
    Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost &lt;br /&gt;
    #=&amp;gt; 2.9&lt;br /&gt;
&lt;br /&gt;
There are various other options to implement this design pattern. Other way to implememt the pattern is by using singleton methods and method aliases. Delegation can also be used, and it overcomes one of the most important disadvantage. We can remove add features if we are using delegation but this is not possible if we are using singleton methods and method aliases. Example for this can be found here [http://www.scribd.com/doc/2217773/Design-Patterns-in-Ruby].&lt;br /&gt;
&lt;br /&gt;
==Implementation in Java==&lt;br /&gt;
&lt;br /&gt;
In Java, this pattern is easy to implement by dividing the various responsibilities into classes and interfaces. The below example consider all these responsibilities and have four components which are described below  &lt;br /&gt;
* Component: Defines the interface for objects that can have responsibilities added to them dynamically.&lt;br /&gt;
* ConcreteComponent: Defines an object to which additional responsibilities can be attached.&lt;br /&gt;
* Decorator: maintains a reference to a Component object and defines an interface that conforms to Component's interface.&lt;br /&gt;
* ConcreteDecorator: adds responsibilities to the component.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface IComponent {&lt;br /&gt;
    public void doStuff();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete component&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class Component implements IComponent{&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    System.out.println(&amp;quot;Do Suff&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Decorator&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface Decorator extends IComponent {&lt;br /&gt;
    public void addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete Decorator ('''Extends IComponent''')&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class ConcreteDecorator implements Decorator {&lt;br /&gt;
    IComponent component;&lt;br /&gt;
    public ConcreteDecorator(IComponent component) {&lt;br /&gt;
    super();&lt;br /&gt;
    this.component = component;&lt;br /&gt;
    }&lt;br /&gt;
    public void addedBehavior() {&lt;br /&gt;
    System.out.println(&amp;quot;Decorator does some stuff too&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    component.doStuff();&lt;br /&gt;
    addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
The Client&lt;br /&gt;
&lt;br /&gt;
    import decorator.*;&lt;br /&gt;
    public class Client {&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
    IComponent comp = new Component();&lt;br /&gt;
    Decorator decorator = new ConcreteDecorator(comp);&lt;br /&gt;
    decorator.doStuff();&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
==Comparison of implementations==&lt;br /&gt;
&lt;br /&gt;
Ruby provides different options to implement Decorator pattern like method_missing, delegation and alias methods. This provides flexibility to the user to implement any possible way depending on the requirements and features needed. But in Java, there is more clearer approach using the components provided in the example. It is a straight forward approach. But different options provided by Ruby make it much better than Java.&lt;br /&gt;
&lt;br /&gt;
In dynamic languages like Javascript, decorator pattern can be implemented with no interfaces or traditional OOP inheritance. With simple overriding but this approach is difficult to implement [http://en.wikipedia.org/wiki/Decorator_pattern#JavaScript].&lt;br /&gt;
&lt;br /&gt;
=Conclusion=&lt;br /&gt;
&lt;br /&gt;
We have seen four design patterns Factory design pattern, Abstract Factory design pattern, Iterator design pattern and Decorator Design Pattern. We have chosen these patterns as they are widely used and Ruby has in-built implementations of these. We have mainly tried to compare Ruby and Java but also specified tips about other languages like PHP, C# and Javascript. In Ruby implementing these design patterns is simple and easy because of its main feature of private class objects, unbounded polymorphism and duck typing [http://people.engr.ncsu.edu/efg/517/f07/lectures/notes/lec6.pdf]. In Java all the features are mainly implemented through interfaces and classes. This has several disadvantages like increase in code complexity, size and is generally confusing and tedious to trace or understand the code.&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=22753</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 11 zv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=22753"/>
		<updated>2009-10-07T23:58:28Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Decorator Pattern */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Overview=&lt;br /&gt;
Before starting off with design patterns for Ruby we need to define what a design pattern is, Design patterns can be described as &amp;quot;a general reusable solution to a commonly occurring problem in software design.&amp;quot; [http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29]&lt;br /&gt;
The idea of design patterns is to not to reinvent the wheel but to solve the current problems by using solutions that have worked in the past.&lt;br /&gt;
A design pattern names, abstracts, and identifies the key aspects of a common design structure that make it useful for creating a reusable object-oriented design. It helps to identify the classes and instances and the way they collaborate with each other to form a solution to a problem.&lt;br /&gt;
Design patterns c an be classified into 3 parts&lt;br /&gt;
Creational, Structural, Behavioral (See if we can give links for these.)&lt;br /&gt;
&lt;br /&gt;
=Factory=&lt;br /&gt;
Factories&lt;br /&gt;
The factory design pattern is an object oriented design pattern. It is a creational design pattern and deals with the issues faced in creating objects.&lt;br /&gt;
The main goal of this implementation is to isolate teh code that creates the class form the concete implementation of that class. Ruby example for the same is given below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Factory Example in Ruby==&lt;br /&gt;
&lt;br /&gt;
    class GearFactory&lt;br /&gt;
      def new() &lt;br /&gt;
        if ( ... some condition )&lt;br /&gt;
           return Sprocket.new()&lt;br /&gt;
        else&lt;br /&gt;
           return Cog().new()&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Our client class now becomes:&lt;br /&gt;
    class GearUser &lt;br /&gt;
      def doSomething(factory )&lt;br /&gt;
        ...&lt;br /&gt;
      my_gear = factory.new()&lt;br /&gt;
        ...&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The above code does not have to distinguish between a factory and an ordinary class. We can call the class using the followijng code.&lt;br /&gt;
    client.doSomething(GearFactory.new)          #Use the factory&lt;br /&gt;
    client.doSomething(Cog)                      #Use the Cog class&lt;br /&gt;
    client.doSomething(Sprocket)                 #Use the Sprocket class&lt;br /&gt;
&lt;br /&gt;
==Factory Example in Java==&lt;br /&gt;
In java the Factory implementation is done using interfaces. Declaring them as interfaces helps to maintain a general overview and not depending on the type of factory object that needs to be used. All of these can be placed in a huge factory in a client application.&lt;br /&gt;
A well known example for Java Factory is the UI toolkits that are designed to run on different windowing systems.&lt;br /&gt;
    interface ScrollBar { ... }&lt;br /&gt;
    interface MenuBar   { ... }&lt;br /&gt;
    ...&lt;br /&gt;
And associated classes implementing them on different windowing systems:&lt;br /&gt;
&lt;br /&gt;
    class MotifScrollBar implements ScrollBar { ... }&lt;br /&gt;
    class Win95ScrollBar implements ScrollBar { ... }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
And a factory interface that also doesn't commit to representation:&lt;br /&gt;
&lt;br /&gt;
    interface Factory {&lt;br /&gt;
      public abstract ScrollBar newScrollBar();&lt;br /&gt;
      public abstract MenuBar   newMenuBar();&lt;br /&gt;
      ... &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
But implementation classes that do:&lt;br /&gt;
&lt;br /&gt;
    class MotifFactory implements Factory {&lt;br /&gt;
      public ScrollBar newScrollBar() { return new MotifScrollBar(...); }&lt;br /&gt;
      ...&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=AbstractFactory Model=&lt;br /&gt;
Abstract Factory Design Pattern encapsulates a group of objects that have common theme. It implements a generic interface to create these objects that are part of the theme. It does not care about the details of the implementation of these objects.  It is a type of Creational pattern [http://en.wikipedia.org/wiki/Abstract_factory_pattern] “Provide an interface for creating families of related or dependent objects without specifying their concrete classes” [http://sourcemaking.com/design_patterns/abstract_factory]&lt;br /&gt;
&lt;br /&gt;
Ruby automatically implements the Abstract Factory pattern as Class Objects. All Class objects have the same interface: the new method of each class object creates new instances of the class. Thus the code can pass references to class objects around and they can be used to call new method without knowing the exact type of object that the class creates.&lt;br /&gt;
&lt;br /&gt;
    Class Foo; end&lt;br /&gt;
    Class Bar, end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is the use of Abstract Factory Pattern&lt;br /&gt;
    &lt;br /&gt;
    def create_something(factory)&lt;br /&gt;
	new_object = factory.new&lt;br /&gt;
	puts &amp;quot;created a new #{new_object.class} with a factory&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Here we select a factory to use&lt;br /&gt;
    Create_something(Foo)&lt;br /&gt;
    Create_something(Bar)&lt;br /&gt;
&lt;br /&gt;
Output of the code:&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Foo with a factory&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Bar with a factory&lt;br /&gt;
&lt;br /&gt;
The create_something method is creating objects through an abstract interface. It does not have details about implementation used to create these objects. Thus the use of create_something() is used to shield the rest of the code from that knowledge.&lt;br /&gt;
&lt;br /&gt;
But in Java for implementation of Abstract Factory design pattern we need to create a class which has method who defers creation of product objects to its concrete class. This class then needs to be ”extended” by the client class which uses only these interfaces to create objects of concrete class.&lt;br /&gt;
[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf]. Thus Java implementation needs a well defined interface to do so but in Ruby it is directly implemented because of private class object property.&lt;br /&gt;
&lt;br /&gt;
=Iterator Design Pattern=&lt;br /&gt;
An Iterator object encapsulates the internal structure of how the iteration occurs. It is a type of Behavioral design pattern. [http://en.wikipedia.org/wiki/Iterator_pattern]. “Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.” [http://sourcemaking.com/design_patterns/iterator]&lt;br /&gt;
&lt;br /&gt;
Ruby implements iterators with blocks and the ‘each’ method, and with ‘for..in’ statements. For example consider the following example;&lt;br /&gt;
&lt;br /&gt;
    def print_element(container)&lt;br /&gt;
    	Container.each {|o| puts o.inspect }&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    list = [1,2,2,3]&lt;br /&gt;
    hash = {“a”=&amp;gt;1, “b”=&amp;gt;2,”c”=&amp;gt;3, “d”=&amp;gt;4 }&lt;br /&gt;
    print_elements list&lt;br /&gt;
    print_elements hash&lt;br /&gt;
&lt;br /&gt;
The output of the code is,&lt;br /&gt;
    1&lt;br /&gt;
    2&lt;br /&gt;
    3&lt;br /&gt;
    4&lt;br /&gt;
    [“a”,1]&lt;br /&gt;
    [“b”,2]&lt;br /&gt;
    [“c”,3]&lt;br /&gt;
    [“d”,4]&lt;br /&gt;
&lt;br /&gt;
In Java implementing Iterator design pattern would again involve having an interface for accessing and traversing the elements which is further implemented by the concrete class.  Thus a class who needs to access the list will need to call the interface class. [http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf] Thus Ruby helps in implementing this design pattern easily by providing functions like “each” which does the handling of the concrete class implementation.&lt;br /&gt;
&lt;br /&gt;
=Decorator Pattern=&lt;br /&gt;
It is used to increase the functionality of the existing object dynamically. It adds the behavior at runtime.&lt;br /&gt;
The below code is an example of decorators where we just create a place holder and we can use this function to perform different functions depending on the parameters supplied to it. &lt;br /&gt;
The need for this kind of pattern is so as to increase the functionality of a particular class. &lt;br /&gt;
&lt;br /&gt;
==Decorator Example in Ruby==&lt;br /&gt;
In this example we talk about how a coffee class can have many addtions to it like coffee with cream, sprinkles, milk etc and creating a class for each of them will not be the correct solution.In this example the cost can be calculated according to what is sent to it.Cost of the coffee is 2 and the cost of White coffee (coffee + milk) = 2.4. So what happens when we execute the Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost we get the result as 2.9 as the cost of the coffee is 2, the decorator object (now only coffee) is sent to the Milk and it becomes 2.4, which now is then sent to the Whip which is going to be 2.4 + 02 = 2.6 and finally to Sprinkles which becomes 2.6 + 0.3 = 2.9.&lt;br /&gt;
    module Decorator&lt;br /&gt;
      def initialize(decorated)&lt;br /&gt;
        @decorated = decorated&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    def method_missing(method, *args)&lt;br /&gt;
        args.empty? ? @decorated.send(method) : @decorated.send(method, args)&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
    class Whip&lt;br /&gt;
      include Decorator&lt;br /&gt;
      def cost &lt;br /&gt;
        @decorated.cost + 0.2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    class Sprinkles&lt;br /&gt;
      include Decorator&lt;br /&gt;
&lt;br /&gt;
      def cost&lt;br /&gt;
        @decorated.cost + 0.3&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    Whip.new(Coffee.new).cost&lt;br /&gt;
    #=&amp;gt; 2.2&lt;br /&gt;
    Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost &lt;br /&gt;
    #=&amp;gt; 2.9&lt;br /&gt;
&lt;br /&gt;
==Decorator Example in Java==&lt;br /&gt;
The components for this example are described below&lt;br /&gt;
* Component: Defines the interface for objects that can have responsibilities added to them dynamically.&lt;br /&gt;
* ConcreteComponent: Defines an object to which additional responsibilities can be attached.&lt;br /&gt;
* Decorator: maintains a reference to a Component object and defines an interface that conforms to Component's interface.&lt;br /&gt;
* ConcreteDecorator: adds responsibilities to the component.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface IComponent {&lt;br /&gt;
    public void doStuff();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete component&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class Component implements IComponent{&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    System.out.println(&amp;quot;Do Suff&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Decorator&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface Decorator extends IComponent {&lt;br /&gt;
    public void addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete Decorator ('''Extends IComponent''')&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class ConcreteDecorator implements Decorator {&lt;br /&gt;
    IComponent component;&lt;br /&gt;
    public ConcreteDecorator(IComponent component) {&lt;br /&gt;
    super();&lt;br /&gt;
    this.component = component;&lt;br /&gt;
    }&lt;br /&gt;
    public void addedBehavior() {&lt;br /&gt;
    System.out.println(&amp;quot;Decorator does some stuff too&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    component.doStuff();&lt;br /&gt;
    addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
The Client&lt;br /&gt;
&lt;br /&gt;
    import decorator.*;&lt;br /&gt;
    public class Client {&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
    IComponent comp = new Component();&lt;br /&gt;
    Decorator decorator = new ConcreteDecorator(comp);&lt;br /&gt;
    decorator.doStuff();&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=22752</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 11 zv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=22752"/>
		<updated>2009-10-07T23:56:34Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Decorator Example in Java */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Overview=&lt;br /&gt;
Before starting off with design patterns for Ruby we need to define what a design pattern is, Design patterns can be described as &amp;quot;a general reusable solution to a commonly occurring problem in software design.&amp;quot; [http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29]&lt;br /&gt;
The idea of design patterns is to not to reinvent the wheel but to solve the current problems by using solutions that have worked in the past.&lt;br /&gt;
A design pattern names, abstracts, and identifies the key aspects of a common design structure that make it useful for creating a reusable object-oriented design. It helps to identify the classes and instances and the way they collaborate with each other to form a solution to a problem.&lt;br /&gt;
Design patterns c an be classified into 3 parts&lt;br /&gt;
Creational, Structural, Behavioral (See if we can give links for these.)&lt;br /&gt;
&lt;br /&gt;
=Factory=&lt;br /&gt;
Factories&lt;br /&gt;
The factory design pattern is an object oriented design pattern. It is a creational design pattern and deals with the issues faced in creating objects.&lt;br /&gt;
The main goal of this implementation is to isolate teh code that creates the class form the concete implementation of that class. Ruby example for the same is given below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Factory Example in Ruby==&lt;br /&gt;
&lt;br /&gt;
    class GearFactory&lt;br /&gt;
      def new() &lt;br /&gt;
        if ( ... some condition )&lt;br /&gt;
           return Sprocket.new()&lt;br /&gt;
        else&lt;br /&gt;
           return Cog().new()&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Our client class now becomes:&lt;br /&gt;
    class GearUser &lt;br /&gt;
      def doSomething(factory )&lt;br /&gt;
        ...&lt;br /&gt;
      my_gear = factory.new()&lt;br /&gt;
        ...&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The above code does not have to distinguish between a factory and an ordinary class. We can call the class using the followijng code.&lt;br /&gt;
    client.doSomething(GearFactory.new)          #Use the factory&lt;br /&gt;
    client.doSomething(Cog)                      #Use the Cog class&lt;br /&gt;
    client.doSomething(Sprocket)                 #Use the Sprocket class&lt;br /&gt;
&lt;br /&gt;
==Factory Example in Java==&lt;br /&gt;
In java the Factory implementation is done using interfaces. Declaring them as interfaces helps to maintain a general overview and not depending on the type of factory object that needs to be used. All of these can be placed in a huge factory in a client application.&lt;br /&gt;
A well known example for Java Factory is the UI toolkits that are designed to run on different windowing systems.&lt;br /&gt;
    interface ScrollBar { ... }&lt;br /&gt;
    interface MenuBar   { ... }&lt;br /&gt;
    ...&lt;br /&gt;
And associated classes implementing them on different windowing systems:&lt;br /&gt;
&lt;br /&gt;
    class MotifScrollBar implements ScrollBar { ... }&lt;br /&gt;
    class Win95ScrollBar implements ScrollBar { ... }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
And a factory interface that also doesn't commit to representation:&lt;br /&gt;
&lt;br /&gt;
    interface Factory {&lt;br /&gt;
      public abstract ScrollBar newScrollBar();&lt;br /&gt;
      public abstract MenuBar   newMenuBar();&lt;br /&gt;
      ... &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
But implementation classes that do:&lt;br /&gt;
&lt;br /&gt;
    class MotifFactory implements Factory {&lt;br /&gt;
      public ScrollBar newScrollBar() { return new MotifScrollBar(...); }&lt;br /&gt;
      ...&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=AbstractFactory Model=&lt;br /&gt;
Abstract Factory Design Pattern encapsulates a group of objects that have common theme. It implements a generic interface to create these objects that are part of the theme. It does not care about the details of the implementation of these objects.  It is a type of Creational pattern [http://en.wikipedia.org/wiki/Abstract_factory_pattern] “Provide an interface for creating families of related or dependent objects without specifying their concrete classes” [http://sourcemaking.com/design_patterns/abstract_factory]&lt;br /&gt;
&lt;br /&gt;
Ruby automatically implements the Abstract Factory pattern as Class Objects. All Class objects have the same interface: the new method of each class object creates new instances of the class. Thus the code can pass references to class objects around and they can be used to call new method without knowing the exact type of object that the class creates.&lt;br /&gt;
&lt;br /&gt;
    Class Foo; end&lt;br /&gt;
    Class Bar, end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is the use of Abstract Factory Pattern&lt;br /&gt;
    &lt;br /&gt;
    def create_something(factory)&lt;br /&gt;
	new_object = factory.new&lt;br /&gt;
	puts &amp;quot;created a new #{new_object.class} with a factory&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Here we select a factory to use&lt;br /&gt;
    Create_something(Foo)&lt;br /&gt;
    Create_something(Bar)&lt;br /&gt;
&lt;br /&gt;
Output of the code:&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Foo with a factory&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Bar with a factory&lt;br /&gt;
&lt;br /&gt;
The create_something method is creating objects through an abstract interface. It does not have details about implementation used to create these objects. Thus the use of create_something() is used to shield the rest of the code from that knowledge.&lt;br /&gt;
&lt;br /&gt;
But in Java for implementation of Abstract Factory design pattern we need to create a class which has method who defers creation of product objects to its concrete class. This class then needs to be ”extended” by the client class which uses only these interfaces to create objects of concrete class.&lt;br /&gt;
[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf]. Thus Java implementation needs a well defined interface to do so but in Ruby it is directly implemented because of private class object property.&lt;br /&gt;
&lt;br /&gt;
=Iterator Design Pattern=&lt;br /&gt;
An Iterator object encapsulates the internal structure of how the iteration occurs. It is a type of Behavioral design pattern. [http://en.wikipedia.org/wiki/Iterator_pattern]. “Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.” [http://sourcemaking.com/design_patterns/iterator]&lt;br /&gt;
&lt;br /&gt;
Ruby implements iterators with blocks and the ‘each’ method, and with ‘for..in’ statements. For example consider the following example;&lt;br /&gt;
&lt;br /&gt;
    def print_element(container)&lt;br /&gt;
    	Container.each {|o| puts o.inspect }&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    list = [1,2,2,3]&lt;br /&gt;
    hash = {“a”=&amp;gt;1, “b”=&amp;gt;2,”c”=&amp;gt;3, “d”=&amp;gt;4 }&lt;br /&gt;
    print_elements list&lt;br /&gt;
    print_elements hash&lt;br /&gt;
&lt;br /&gt;
The output of the code is,&lt;br /&gt;
    1&lt;br /&gt;
    2&lt;br /&gt;
    3&lt;br /&gt;
    4&lt;br /&gt;
    [“a”,1]&lt;br /&gt;
    [“b”,2]&lt;br /&gt;
    [“c”,3]&lt;br /&gt;
    [“d”,4]&lt;br /&gt;
&lt;br /&gt;
In Java implementing Iterator design pattern would again involve having an interface for accessing and traversing the elements which is further implemented by the concrete class.  Thus a class who needs to access the list will need to call the interface class. [http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf] Thus Ruby helps in implementing this design pattern easily by providing functions like “each” which does the handling of the concrete class implementation.&lt;br /&gt;
&lt;br /&gt;
=Decorator Pattern=&lt;br /&gt;
It is used to increase the functionality of the existing object dynamically. It adds the behavior at runtime.&lt;br /&gt;
The below code is an example of decorators where we just create a place holder and we can use this function to perform different functions depending on the parameters supplied to it. &lt;br /&gt;
The need for this kind of pattern is so as to increase the functionality of a particlar class. In this example we talk about how a coffee class can have many addtions to it like coffee with cream, sprinkles, milk etc and creating a class for each of them will not be the correct solution.In this example the cost can be calculated according to what is sent to it.Cost of the coffee is 2 and the cost of White coffee (coffee + milk) = 2.4. So what happens when we execute the Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost we get the result as 2.9 as the cost of the coffee is 2, the decorator object (now only coffee) is sent to the Milk and it becomes 2.4, which now is then sent to the Whip which is going to be 2.4 + 02 = 2.6 and finally to Sprinkles which becomes 2.6 + 0.3 = 2.9.&lt;br /&gt;
&lt;br /&gt;
==Decorator Example in Ruby==&lt;br /&gt;
    module Decorator&lt;br /&gt;
      def initialize(decorated)&lt;br /&gt;
        @decorated = decorated&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    def method_missing(method, *args)&lt;br /&gt;
        args.empty? ? @decorated.send(method) : @decorated.send(method, args)&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
    class Whip&lt;br /&gt;
      include Decorator&lt;br /&gt;
      def cost &lt;br /&gt;
        @decorated.cost + 0.2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    class Sprinkles&lt;br /&gt;
      include Decorator&lt;br /&gt;
&lt;br /&gt;
      def cost&lt;br /&gt;
        @decorated.cost + 0.3&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    Whip.new(Coffee.new).cost&lt;br /&gt;
    #=&amp;gt; 2.2&lt;br /&gt;
    Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost &lt;br /&gt;
    #=&amp;gt; 2.9&lt;br /&gt;
&lt;br /&gt;
==Decorator Example in Java==&lt;br /&gt;
The components for this example are described below&lt;br /&gt;
* Component: Defines the interface for objects that can have responsibilities added to them dynamically.&lt;br /&gt;
* ConcreteComponent: Defines an object to which additional responsibilities can be attached.&lt;br /&gt;
* Decorator: maintains a reference to a Component object and defines an interface that conforms to Component's interface.&lt;br /&gt;
* ConcreteDecorator: adds responsibilities to the component.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface IComponent {&lt;br /&gt;
    public void doStuff();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete component&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class Component implements IComponent{&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    System.out.println(&amp;quot;Do Suff&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Decorator&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface Decorator extends IComponent {&lt;br /&gt;
    public void addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete Decorator ('''Extends IComponent''')&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class ConcreteDecorator implements Decorator {&lt;br /&gt;
    IComponent component;&lt;br /&gt;
    public ConcreteDecorator(IComponent component) {&lt;br /&gt;
    super();&lt;br /&gt;
    this.component = component;&lt;br /&gt;
    }&lt;br /&gt;
    public void addedBehavior() {&lt;br /&gt;
    System.out.println(&amp;quot;Decorator does some stuff too&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    component.doStuff();&lt;br /&gt;
    addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
The Client&lt;br /&gt;
&lt;br /&gt;
    import decorator.*;&lt;br /&gt;
    public class Client {&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
    IComponent comp = new Component();&lt;br /&gt;
    Decorator decorator = new ConcreteDecorator(comp);&lt;br /&gt;
    decorator.doStuff();&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
	<entry>
		<id>https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=22749</id>
		<title>CSC/ECE 517 Fall 2009/wiki2 11 zv</title>
		<link rel="alternate" type="text/html" href="https://wiki.expertiza.ncsu.edu/index.php?title=CSC/ECE_517_Fall_2009/wiki2_11_zv&amp;diff=22749"/>
		<updated>2009-10-07T23:37:36Z</updated>

		<summary type="html">&lt;p&gt;Naruto: /* Decorator Example in Java */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;=Overview=&lt;br /&gt;
Before starting off with design patterns for Ruby we need to define what a design pattern is, Design patterns can be described as &amp;quot;a general reusable solution to a commonly occurring problem in software design.&amp;quot; [http://en.wikipedia.org/wiki/Design_pattern_%28computer_science%29]&lt;br /&gt;
The idea of design patterns is to not to reinvent the wheel but to solve the current problems by using solutions that have worked in the past.&lt;br /&gt;
A design pattern names, abstracts, and identifies the key aspects of a common design structure that make it useful for creating a reusable object-oriented design. It helps to identify the classes and instances and the way they collaborate with each other to form a solution to a problem.&lt;br /&gt;
Design patterns c an be classified into 3 parts&lt;br /&gt;
Creational, Structural, Behavioral (See if we can give links for these.)&lt;br /&gt;
&lt;br /&gt;
=Factory=&lt;br /&gt;
Factories&lt;br /&gt;
The factory design pattern is an object oriented design pattern. It is a creational design pattern and deals with the issues faced in creating objects.&lt;br /&gt;
The main goal of this implementation is to isolate teh code that creates the class form the concete implementation of that class. Ruby example for the same is given below.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Factory Example in Ruby==&lt;br /&gt;
&lt;br /&gt;
    class GearFactory&lt;br /&gt;
      def new() &lt;br /&gt;
        if ( ... some condition )&lt;br /&gt;
           return Sprocket.new()&lt;br /&gt;
        else&lt;br /&gt;
           return Cog().new()&lt;br /&gt;
        end&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Our client class now becomes:&lt;br /&gt;
    class GearUser &lt;br /&gt;
      def doSomething(factory )&lt;br /&gt;
        ...&lt;br /&gt;
      my_gear = factory.new()&lt;br /&gt;
        ...&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
The above code does not have to distinguish between a factory and an ordinary class. We can call the class using the followijng code.&lt;br /&gt;
    client.doSomething(GearFactory.new)          #Use the factory&lt;br /&gt;
    client.doSomething(Cog)                      #Use the Cog class&lt;br /&gt;
    client.doSomething(Sprocket)                 #Use the Sprocket class&lt;br /&gt;
&lt;br /&gt;
==Factory Example in Java==&lt;br /&gt;
In java the Factory implementation is done using interfaces. Declaring them as interfaces helps to maintain a general overview and not depending on the type of factory object that needs to be used. All of these can be placed in a huge factory in a client application.&lt;br /&gt;
A well known example for Java Factory is the UI toolkits that are designed to run on different windowing systems.&lt;br /&gt;
    interface ScrollBar { ... }&lt;br /&gt;
    interface MenuBar   { ... }&lt;br /&gt;
    ...&lt;br /&gt;
And associated classes implementing them on different windowing systems:&lt;br /&gt;
&lt;br /&gt;
    class MotifScrollBar implements ScrollBar { ... }&lt;br /&gt;
    class Win95ScrollBar implements ScrollBar { ... }&lt;br /&gt;
    ...&lt;br /&gt;
&lt;br /&gt;
And a factory interface that also doesn't commit to representation:&lt;br /&gt;
&lt;br /&gt;
    interface Factory {&lt;br /&gt;
      public abstract ScrollBar newScrollBar();&lt;br /&gt;
      public abstract MenuBar   newMenuBar();&lt;br /&gt;
      ... &lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
But implementation classes that do:&lt;br /&gt;
&lt;br /&gt;
    class MotifFactory implements Factory {&lt;br /&gt;
      public ScrollBar newScrollBar() { return new MotifScrollBar(...); }&lt;br /&gt;
      ...&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
=AbstractFactory Model=&lt;br /&gt;
Abstract Factory Design Pattern encapsulates a group of objects that have common theme. It implements a generic interface to create these objects that are part of the theme. It does not care about the details of the implementation of these objects.  It is a type of Creational pattern [http://en.wikipedia.org/wiki/Abstract_factory_pattern] “Provide an interface for creating families of related or dependent objects without specifying their concrete classes” [http://sourcemaking.com/design_patterns/abstract_factory]&lt;br /&gt;
&lt;br /&gt;
Ruby automatically implements the Abstract Factory pattern as Class Objects. All Class objects have the same interface: the new method of each class object creates new instances of the class. Thus the code can pass references to class objects around and they can be used to call new method without knowing the exact type of object that the class creates.&lt;br /&gt;
&lt;br /&gt;
    Class Foo; end&lt;br /&gt;
    Class Bar, end&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Here is the use of Abstract Factory Pattern&lt;br /&gt;
    &lt;br /&gt;
    def create_something(factory)&lt;br /&gt;
	new_object = factory.new&lt;br /&gt;
	puts &amp;quot;created a new #{new_object.class} with a factory&amp;quot;&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
Here we select a factory to use&lt;br /&gt;
    Create_something(Foo)&lt;br /&gt;
    Create_something(Bar)&lt;br /&gt;
&lt;br /&gt;
Output of the code:&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Foo with a factory&amp;lt;br/&amp;gt;&lt;br /&gt;
Created a Bar with a factory&lt;br /&gt;
&lt;br /&gt;
The create_something method is creating objects through an abstract interface. It does not have details about implementation used to create these objects. Thus the use of create_something() is used to shield the rest of the code from that knowledge.&lt;br /&gt;
&lt;br /&gt;
But in Java for implementation of Abstract Factory design pattern we need to create a class which has method who defers creation of product objects to its concrete class. This class then needs to be ”extended” by the client class which uses only these interfaces to create objects of concrete class.&lt;br /&gt;
[http://userpages.umbc.edu/~tarr/dp/lectures/Factory-2pp.pdf]. Thus Java implementation needs a well defined interface to do so but in Ruby it is directly implemented because of private class object property.&lt;br /&gt;
&lt;br /&gt;
=Iterator Design Pattern=&lt;br /&gt;
An Iterator object encapsulates the internal structure of how the iteration occurs. It is a type of Behavioral design pattern. [http://en.wikipedia.org/wiki/Iterator_pattern]. “Provide a way to access the elements of an aggregate object sequentially without exposing its underlying representation.” [http://sourcemaking.com/design_patterns/iterator]&lt;br /&gt;
&lt;br /&gt;
Ruby implements iterators with blocks and the ‘each’ method, and with ‘for..in’ statements. For example consider the following example;&lt;br /&gt;
&lt;br /&gt;
    def print_element(container)&lt;br /&gt;
    	Container.each {|o| puts o.inspect }&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    list = [1,2,2,3]&lt;br /&gt;
    hash = {“a”=&amp;gt;1, “b”=&amp;gt;2,”c”=&amp;gt;3, “d”=&amp;gt;4 }&lt;br /&gt;
    print_elements list&lt;br /&gt;
    print_elements hash&lt;br /&gt;
&lt;br /&gt;
The output of the code is,&lt;br /&gt;
    1&lt;br /&gt;
    2&lt;br /&gt;
    3&lt;br /&gt;
    4&lt;br /&gt;
    [“a”,1]&lt;br /&gt;
    [“b”,2]&lt;br /&gt;
    [“c”,3]&lt;br /&gt;
    [“d”,4]&lt;br /&gt;
&lt;br /&gt;
In Java implementing Iterator design pattern would again involve having an interface for accessing and traversing the elements which is further implemented by the concrete class.  Thus a class who needs to access the list will need to call the interface class. [http://userpages.umbc.edu/~tarr/dp/lectures/Iterator-2pp.pdf] Thus Ruby helps in implementing this design pattern easily by providing functions like “each” which does the handling of the concrete class implementation.&lt;br /&gt;
&lt;br /&gt;
=Decorator Pattern=&lt;br /&gt;
It is used to increase the functionality of the existing object dynamically. It adds the behavior at runtime.&lt;br /&gt;
The below code is an example of decorators where we just create a place holder and we can use this function to perform different functions depending on the parameters supplied to it. &lt;br /&gt;
The need for this kind of pattern is so as to increase the functionality of a particlar class. In this example we talk about how a coffee class can have many addtions to it like coffee with cream, sprinkles, milk etc and creating a class for each of them will not be the correct solution.In this example the cost can be calculated according to what is sent to it.Cost of the coffee is 2 and the cost of White coffee (coffee + milk) = 2.4. So what happens when we execute the Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost we get the result as 2.9 as the cost of the coffee is 2, the decorator object (now only coffee) is sent to the Milk and it becomes 2.4, which now is then sent to the Whip which is going to be 2.4 + 02 = 2.6 and finally to Sprinkles which becomes 2.6 + 0.3 = 2.9.&lt;br /&gt;
&lt;br /&gt;
==Decorator Example in Ruby==&lt;br /&gt;
    module Decorator&lt;br /&gt;
      def initialize(decorated)&lt;br /&gt;
        @decorated = decorated&lt;br /&gt;
      end&lt;br /&gt;
&lt;br /&gt;
    def method_missing(method, *args)&lt;br /&gt;
        args.empty? ? @decorated.send(method) : @decorated.send(method, args)&lt;br /&gt;
    end&lt;br /&gt;
   end&lt;br /&gt;
&lt;br /&gt;
    class Whip&lt;br /&gt;
      include Decorator&lt;br /&gt;
      def cost &lt;br /&gt;
        @decorated.cost + 0.2&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    class Sprinkles&lt;br /&gt;
      include Decorator&lt;br /&gt;
&lt;br /&gt;
      def cost&lt;br /&gt;
        @decorated.cost + 0.3&lt;br /&gt;
      end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    Whip.new(Coffee.new).cost&lt;br /&gt;
    #=&amp;gt; 2.2&lt;br /&gt;
    Sprinkles.new(Whip.new(Milk.new(Coffee.new))).cost &lt;br /&gt;
    #=&amp;gt; 2.9&lt;br /&gt;
&lt;br /&gt;
==Decorator Example in Java==&lt;br /&gt;
&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface IComponent {&lt;br /&gt;
    public void doStuff();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete component&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class Component implements IComponent{&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    System.out.println(&amp;quot;Do Suff&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Decorator&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public interface Decorator extends IComponent {&lt;br /&gt;
    public void addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
The Concrete Decorator ('''Extends IComponent''')&lt;br /&gt;
    package decorator;&lt;br /&gt;
    public class ConcreteDecorator implements Decorator {&lt;br /&gt;
    IComponent component;&lt;br /&gt;
    public ConcreteDecorator(IComponent component) {&lt;br /&gt;
    super();&lt;br /&gt;
    this.component = component;&lt;br /&gt;
    }&lt;br /&gt;
    public void addedBehavior() {&lt;br /&gt;
    System.out.println(&amp;quot;Decorator does some stuff too&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    public void doStuff() {&lt;br /&gt;
    component.doStuff();&lt;br /&gt;
    addedBehavior();&lt;br /&gt;
    }&lt;br /&gt;
   }&lt;br /&gt;
&lt;br /&gt;
The Client&lt;br /&gt;
&lt;br /&gt;
    import decorator.*;&lt;br /&gt;
    public class Client {&lt;br /&gt;
    public static void main(String[] args) {&lt;br /&gt;
    IComponent comp = new Component();&lt;br /&gt;
    Decorator decorator = new ConcreteDecorator(comp);&lt;br /&gt;
    decorator.doStuff();&lt;br /&gt;
    }&lt;br /&gt;
    }&lt;/div&gt;</summary>
		<author><name>Naruto</name></author>
	</entry>
</feed>