Mostrando entradas con la etiqueta Java. Mostrar todas las entradas
Mostrando entradas con la etiqueta Java. Mostrar todas las entradas

domingo, 13 de mayo de 2012

1) Consider static factory methods instead of constructors

The simple way to instantiate an object in Java is through of constructors, but we can do this whit a static factory method, the static factory methods are methods for create objects. 

Example:

public static Boolean valueOf(boolean b){
    return b ? Boolean.TRUE : Boolean.FALSE;
}

Advantages:

 -We can write whatever name to the method, a diference to constructors we should name it with the same name of the class. This permits write clearer names, names more descriptives a diference to overwrite any numbers of constructors.

-Static factory methods aren't required to create a new object each time they're invoked. This useful when we need control the number of instances also allow use Singleton objects.

-We can return an object of any subtype of their return type. That's give you great flexibility, inclusive you can return a subtype objects without public constructor.

-The static factory methods reduce the verbosity of creating parameterized type instances. 



Disadvantages:

-The classes without public or protected constructors can't be subclassed. That's isn't good certainly but you can suggest composition instead of inheritance.

-You can't distinguish static factory methods from other static methods. But you can use some common names for static factory methods:

  • valueOf
  • of
  • getInstance
  • newInstance
  • getType
  • newType

jueves, 10 de mayo de 2012

Coming soon

I'm thinking write some articles about Java but in english, reasons? because i'm studying english and i need to practice one. I know, my english isn't as good but i'll try to do my best work.

I'm going to write advanced Java topics and i hope it help us to be better Java developers :). Well, you should be waiting for my next post. Coming soon :)

miércoles, 3 de marzo de 2010

Diagrama de clases JTM


He aquí el diagrama de clases de JTM y aún no está terminado :P. Ojala que pronto lo esté.

viernes, 18 de septiembre de 2009

Mostrando Código

Y Bien, este nuevo post es para ver si funciona la inserción de código de distintos lenguajes y que se formateen de acuerdo a su sintaxis.


Probemos un hola mundo con Java
//HolaMundo.java
public class HolaMundo{
    public static void main(String[] args){
        System.out.println("Hola Mundo");
    }
}

Probemos un script en SQL
--Tabla Persona
CREATE TABLE Persona(
 id int not null,
 nombre varchar(50),
 primary key(id)
)
 
Parece que sí funcionó (=


Los Autenticos Decadentes - Viviré Por Siempre