User talk:Spangul: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
(Created page with "=Forms-Ruby= ==Introduction== Forms in web applications are an essential interface for user input. However, form markup can quickly become tedious to write and maintain because o...")
 
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 50: Line 50:


==References==
==References==
 
<references></references>
[1] Wikipedia, the free encyclopedia: Call Super, 2010. Wikimedia Foundation, Inc.: [http://en.wikipedia.org/wiki/Call_super]
 
[2] Fowler, Martin. "MF Bliki: Call Super"[http://martinfowler.com/bliki/CallSuper.html]
 
[3] Wikipedia, the free encyclopedia: Template method pattern, 2010.  Wikimedia Foundation, Inc.: [http://en.wikipedia.org/wiki/Template_method_pattern]

Latest revision as of 03:05, 3 October 2012

Forms-Ruby

Introduction

Forms in web applications are an essential interface for user input. However, form markup can quickly become tedious to write and maintain because of form control naming and their numerous attributes. Rails deals away with these complexities by providing view helpers for generating form markup.<ref>guides.rubyonrails.org/form_helpers.html</ref> Rails provides excellent features to create forms and gather user input. Forms in Rails are an effective way to obtain user input in a convenient manner. Forms can include different types of data fields that will help obtain different types of data. For example, Text box can fetch a few words from the user and Text Area, a paragraph. Forms are embedded in a Web Application and are very user-friendly. Forms in Rails also have in-built functionalities to verify the data the user enters, validate it using a set of predefined rules, display corresponding error messages (in case of non-compliance) and storing the information in the database if it passes validation.

Diagram of Call Super Anti-patter
Call Super Anti-pattern

Example of the Call Super Anti-pattern

In the example below, the super class of TestCase is extended by the TestCaseOne class. The subclass TestCaseOne calls setup at the beginning of its own setup() method and then does any extra steps.

public class TestCase{
  public void setup() {
    ...
  }
}
public class TestCaseOne extends TestCase{
  public void setup() {
    super.setup();
    ...
  }
}

Alternative Implementation

Instead of forcing a method to call super(), it is generally considered a better practice to use the template method pattern. In this pattern, the method that would be required to be called via super(), that method would actually call another method that is abstract has to be created by the subclass.

Example Using Alternative Implementation (Template Method Pattern)

In the example below, the super class implementation of setup() calls another method doExtraStuff() which is abstract and therefore has to be implemented by the subclass when it is extended.

public class TestCase{
  public void setup() {
    .....
    doExtraStuff();
  }
  abstract void doExtraStuff();
}

public class TestCaseOne extends TestCase{
  void doExtraStuff() {
    ...
  }
}

References

<references></references>