Tuesday, January 26, 2010

Best Place To Eat At Whistler

Factories Design: Singleton

In this article we will see one of the common creational patterns, the Singleton . This pattern ensures that a class has only one instance and provides a global point of access to it.

This pattern is often used when one class controls access to a single physical resource or when data must be available to all application objects.

The Singleton pattern is implemented by a class a private constructor. There will be a method that will instantiate the object by calling the constructor only if there is still no.

can cause problems for programs with multiple threads, if two threads try to create the instance at the same time and it does not exist yet. That only one of them can create the object you can use mutual exclusion (synchronized ) in the method of creating a class that implements the pattern .

should say also that if multiple class loaders for the application may be an instance of the class in each of them, but the instance is unique in that magazine.

A successful deployment of Singleton pattern in Java could be the next Bill proposed by the researcher Pough:
 
public class Singleton {/ / Private constructor Prevents instantiation from classes
Other private Singleton () {}

/ ** * SingletonHolder
is loaded on the first execution of
* Singleton.getInstance () or the first access to
* SingletonHolder.INSTANCE, NOT before.
* / private static class

SingletonHolder {private static final Singleton INSTANCE = new Singleton ();}

public static
Singleton getInstance () {return
SingletonHolder.INSTANCE;
}}

Although widely used, there is a stream against the use of this pattern due to the problems it introduces. On this page Scout Densmore explains the problems attributed to Brian Button Singletons. Then do an adaptation of what is said there:
  • The Singletons are usually used to provide a global point of access for service. Thus no need to pass a reference to this service, which is like using a global variable. In the end what happens is that the design units remain hidden within the code and are not visible when examining the interfaces. We need to inspect the code to understand what objects are using the classes.

  • The Singletons will limit the creation of objects. This is true, but now they are mixing two different responsibilities in the same class. A class should not worry about whether or not a Singleton, but you should only worry about their business responsibilities. To limit the creation of classes should be set up factories or other objects that restrict the creation. Thus, each object would maintain a better-defined responsibilities.

  • The Singletons promote tight coupling between classes . A loose coupling between classes can substitute alternative implementations of collaborating classes in testing. A better alternative is to modify the design to pass references to objects in the classes and methods so as to reduce the coupling.

  • The Singletons maintain the state until the completion of the program. This persistent state is detrimental to the unit tests, since each test must be independent of the others. If this is not met, could lead to situations where the tests fail where they should not because they are hiding mistakes. You can avoid passing object references to lectures and methods.

is why it looks like a design pattern to avoid whenever possible.

References:
Singleton Pattern in Wikipedia
Singleton Pattern - Design Patterns
Singletons in Java, the standard single instance David Barral
Singleton Pattern in c2.com Why Singletons Are
Evil by Scott Densmore
Other design patterns

Sunday, January 24, 2010

Canon Dslr Leather Bag

Selenium functional tests

HQ Selenium is a framework that automates functional testing of web applications. It consists of several tools used to define and automate these tests. Specifically, let's see:
  • Selenium IDE: This is a Firefox plugin that lets you define a test of a web application keeping in a script the actions executed by the user on the browser. This script can be re-run after every time you want.
  • Selenium RC (Remote Control) : Allows you to automate testing of web applications based on defined scripts using Selenium IDE.
We will now see an example of functional testing a web application.

First we descarganos Firefox plugin Selenium IDE . We can do it from this page . This will download the Selenium IDE plugin and install it in your browser. Then it will restart to complete installation.

Now let's do a test of a web application. In this case it is an application that stores all items of interest from magazines that I buy, and the proof is to introduce a new article.

First, we Tools-> Selenium IDE . This opens a window that lets you record the script with the test to be performed:

From this point all we do is recorded on your browser in the script. At this point introduce a new article called "New " and title "New ." Once entered, click on the red button on the Selenium IDE window to stop recording the script. Prove that it has introduced the item.

Now repeat the test by clicking the green triangle in the top right of the window Selenium IDE. This repeats the previous run and therefore, in the list of products we now have 2 items with the name "New ."

can save this test from File-> Save E. Test Cas But more interesting for us will option File-> Export Test Case As -> Java (JUnit) Selenium RC to export this script to a test case for JUnit we will use later to automate this test:
 com.example.tests package; 
com.thoughtworks.selenium
import .*;
import java.util.regex.Pattern;

public class Test {
SeleneseTestCase extends public void setUp () throws Exception {setUp
( http://change-this-to-the-site-you-are-testing/ "," * chrome ");}

testPrueba public void () throws Exception {
selenium.open (" / RevisteroMyFacesWeb / ") ;
selenium.click ("link = New Item");
selenium.waitForPageToLoad ("30000");
selenium.type (j_id_jsp_815202587_1: nombreArticulo "," New ");
selenium.type (j_id_jsp_815202587_1: descripcionArticulo" "New");
selenium.click (j_id_jsp_815202587_1: j_id_jsp_815202587_35 ");
selenium.waitForPageToLoad (" 30000 ");
}}

Once we defined the test now to automate. We will use JUnit tool and Selenium RC (Remote Control) . We will also use plugin Maven Selenium to , which starts the server Selenium RC when running the tests.

Create a Maven project with the following pom.xml :
 \u0026lt;project xmlns = "http://maven.apache.org/POM/4.0.0" 
xmlns: xsi = "http: / / www.w3.org/2001/XMLSchema-instance "
xsi: schemaLocation =" http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0. xsd ">
\u0026lt;modelVersion> 4.0.0 \u0026lt;/ modelVersion>
\u0026lt;groupId> com.roldan \u0026lt;/ groupId>
\u0026lt;artifactId> RevisteroPruebasSelenium \u0026lt;/ artifactId>
\u0026lt;version> 0.0.1-snapshot \u0026lt;/ version>
\u0026lt;dependencies>
\u0026lt;dependency>
\u0026lt;groupId> Junit \u0026lt;/ groupId>
\u0026lt;artifactId> Junit \u0026lt;/ artifactId>
\u0026lt;version> 3.8 .2 \u0026lt;/ version>
\u0026lt;scope> test \u0026lt;/ scope>
\u0026lt;/ dependency>
\u0026lt;dependency>
\u0026lt;groupId> org.seleniumhq.selenium.client-drivers \u0026lt;/ groupId>
\u0026lt;artifactId> selenium-java-client-driver \u0026lt;/ artifactId>
\u0026lt;version> 1.0.1 \u0026lt;/ version>
\u0026lt;scope> test \u0026lt;/ scope>
\u0026lt;/ dependency>
\u0026lt;/ dependencies>
\u0026lt;build>
\u0026lt;plugins>
\u0026lt;plugin>
\u0026lt;groupId> org.codehaus.mojo \u0026lt;/ groupId>
\u0026lt;artifactId> selenium-maven-plugin \u0026lt;/ artifactId>
\u0026lt;executions>
\u0026lt;execution>
\u0026lt;phase> process-test-classes \u0026lt;/ phase>
\u0026lt;goals>
\u0026lt;goal> start-server \u0026lt;/ goal>
\u0026lt;/ goals>
\u0026lt;configuration>
\u0026lt;background> ; true \u0026lt;/ background>
\u0026lt;/ configuration>
\u0026lt;/ execution>
\u0026lt;/ executions>
\u0026lt;/ plugin>
\u0026lt;/ plugins>
\u0026lt;/ build>
\u0026lt;/ project>

We also configure the Maven plugin for Selenium to start the Selenium server in the phase preceding the test ( process-test-classe s) defines two units, JUnit and Java client driver for Selenium , which allows running the tests set up from Selenium IDE . We will adapt

test class generated from Selenium IDE to make use of the Java driver for Selenium:
 com.roldan.selenium package; 
com.thoughtworks.selenium
import .*;
CrearNuevoArticuloTest
public class extends SeleneseTestCase {

protected DefaultSelenium createSeleniumClient(String url) throws Exception {
return new DefaultSelenium("localhost", 4444, "*firefox", url);
}

public void testCrearNuevoArticulo() throws Exception {
DefaultSelenium selenium = createSeleniumClient("http://localhost:8080/");
selenium.start();

selenium.open("/RevisteroMyFacesWeb/");
selenium.click("link=Nuevo Artículo");
selenium.waitForPageToLoad("30000");
selenium.type("j_id_jsp_815202587_1:nombreArticulo", "Nuevo");
selenium.type("j_id_jsp_815202587_1:descripcionArticulo", "New");
selenium.click (j_id_jsp_815202587_1: j_id_jsp_815202587_35 ");
selenium.waitForPageToLoad (" 30000 ");

selenium.stop ();

}}

The difference is that now at the beginning of create a test client Selenium and final test closes this client.

If the test is now released for this project with mvn test , will receive a browser that repeats the test set, and has been recorded yet another article.

References: Selenium
HQ Web
Turorial of Workaholics
on Selenium IDE Turorial of Workaholics on Selenium RC Tutorial
Two sequential tests Ideas on Selenium and JUnit
Web Selenium plugin for Maven

Friday, January 8, 2010

How To Make A Friendship Anklet



Each time you start developing a new application as software engineers we turn to face the same or similar problems have been addressed in previous developments. Not only that, we are facing in many cases the same problems others have had to solve.

Making all prior knowledge is useful and saves time in the design and development of new applications. This is something well known and therefore the patterns have emerged design, and guidelines to follow under certain conditions supported by prior knowledge.

In construction, the architect Christopher Alexander proposed the learning and use of a series of patterns for the construction of buildings higher quality. In his words, "each pattern describes a problem that occurs many times in our environment, as well as the solution to it, so that we can use this solution a million times later without having to think of it another time. "

The patterns Christopher Alexander and his colleagues identified are an attempt to formalize and capture a practical way generations of architectural knowledge. The patterns are not abstract principles that require their rediscovery for a successful implementation, nor are specific to a particular situation or cultural, are somewhere in between. A pattern defines a possible solution to correct a design problem within a given context, describing the invariant qualities of all solutions.

Taking the idea of \u200b\u200bpattern the computer world, a design pattern is a solution to a design problem that should possess the following characteristics:
  • must be checked its effectiveness solving similar problems in the past.
  • should be reusable, which means that it is applicable to different design problems in different circumstances. The

design patterns were a great success from the book Design Patterns written by the group Gang of Four (GoF, which were collected 23 common design patterns. These defined patterns by the GoF are divided into 3 groups creational patterns, structural and behavioral .

creational patterns: They try to solve the problems that can arise in the creation of objects.
  • Factory Abstract: Provides an interface for creating families of objects or dependent on each other, without specifying their concrete classes.
  • Factory Method: Define an interface for creating an object, but let subclasses decide which class to instantiate. Allows a class to its subclasses delegate object creation.
  • Builder: Separate the construction of a complex object from its representation so that the same construction process can create different representations. Prototype
  • : Specifies the types of objects to create using a prototypical instance, and create new objects by copying this prototype.
  • Singleton: Ensure a class has only one instance and provides a global point of access to it.

structural patterns: They try to facilitate the design identifying simple ways to establish relationships between entities.
  • Adapter: Convert the interface of a class into another which is what customers expect. Allow cooperating classes that otherwise could not to have incompatible interfaces.
  • Bridge: Decouple an abstraction from its implementation so that the two can vary independently. Composite
  • : Combine objects in tree structures to represent part-whole hierarchies. Allows customers to uniformly treat the individual objects and compounds. Decorator
  • : Dynamically adds new responsibilities to an object, providing a flexible alternative to inheritance to extend the functionality.
  • Facade: Provides a unified interface for a set of interfaces in a subsystem. Defines a high-level interface that makes the subsystem easier to use.
  • Flyweight: Use sharing to allow a large number of fine-grained objects efficiently.
  • Proxy: Provide a surrogate or representative of another object to control access to it.

Behavioral Patterns: Identify common communication patterns between objects and try to increase the flexibility of this communication.
  • Chain of Responsibility: Avoid coupling the sender of a request to its receiver by giving more than one object a chance to respond to the petition. Create a string with the receiving objects and passes the request through the chain until it is treated by an object.
  • Command: Encapsulate a request on an object, allowing you parameterize clients with different requests, queue or keep track of requests and to undo the operations.
  • Interpreter: Given a language, define a representation for its grammar along with an interpreter that uses the representation to interpret sentences in the language. Iterator
  • : Provides a way to sequentially access the elements of an aggregate object without exposing its internal representation.
  • Mediator: Define an object that encapsulates how they interact a set of objects. Promotes loose coupling by keeping objects from referring to each other explicitly, and lets you vary their interaction independently. Memento
  • : Represents and externalize an object's internal state without violating encapsulation, so that it can return to that status later.
  • Observer: Define a dependency on one-to-many relationship between objects, so that when an object changes state is notified and updated automatically every object.
  • State: Allow an object to alter its behavior when its internal state changes. Appear to change the object's class.
  • Strategy: Define a family of algorithms, encapsulate each one of them and make them interchangeable. Lets the algorithm vary independently from clients that use it.
  • Template Method: Define an operation in the skeleton of an algorithm, deferring some of its subclasses steps. Lets subclasses redefine certain steps of the algorithm without changing its structure.
  • Visitor: Represent an operation on elements of an object structure. Allows you to define a new operation without changing the classes of the elements on which it operates.

Over time, have arisen new patterns, especially in the field of enterprise Java development . Some of them are:
  • Front Controller Model View Controller (MVC) ended
  • View
  • Session Facade - Facade Session
  • Locator Service -
  • Object Locator Service value - Value Object object
  • Data Transfer - Data Transfer Object (DTO)
  • Officer of Company - Bussiness Delegate
  • Data Access Object - Data Access Object (DAO)
  • Dependency Injection (DI) - Inversion of Control (IoC)
  • Open Session In View (osiva)
  • ThreadLocal Session

In this article we have tried to give an introduction to design patterns . In future articles I will try to develop some of the patterns herein analyzed its usefulness, strengths and weaknesses.

References:
Design Patterns (Erich Gamma, Richard Helm, Ralph Johnson, Vlissides Hohn)
Professional Java Server Programming J2EE, 1.3 Edition (Subrahmanyam Allamaraju, Cedric Beust, Marc Wilcox, Sameer Tyagi Rod Johnson, Gary Watson, Alan Williamson, John Davies, Ramesh Nagappa, Andy Longshaw, PG Sarang, Tyler Jewell, Alex Toussaint)
Design Patterns in Wikipedia
Introduction to design patterns by Manuel Lagos Torres
ingenierosoftware.com Design Patterns in

Saturday, December 26, 2009

What Does Liver Pain Feel Like?



Dear Reyes Magos:

years ago that I write. I wanted so much, I thought to do the letter was useless. That all trades, so you are very busy as I thought it best to leave the letter for other years. That has consequences as This year, it has been, in short, a disaster. I should have known that by ordering that it is not, usually when you order three days you stay with one, and eventually you just formed, or not. The fact is that the year began and will end worst fatal.
This year I write to heal health and to not tell you not warned in time. As I said 2009 has been generally very twisted, but, in truth, most of the time and not even I have that feeling, saying that good tree that snuggles up nice shade shelters him and that moment only the bad things good become secondary. So, what was this year I am writing to ask you, NOTHING. I stopped caring too much and now with just me and spare me, do not need you or to you or to papanoel, just wanted to make sure that 2010 starts changing some things better than they could haver thought that was led this past year as well. Change, mayoritariamene is good, and the last few months ... to me, changes me and I get too many of his ears.




For that, thanks for nothing (since he was 6 years at least I'm hoping the Robot Emilio) and tell them it was a no-pleasure doing business with you.
I hope you have a 2010 like my 2009 and my 2010 do just as well that my last quarter of 2009.

PD: Who laughs last laughs best.