TorpedoBlu
04-03-2010, 10:14
ciao ragazzi, sviluppo java da qualche anno (J2EE) ma purtroppo in ambito bancario siamo alla java4
cerco di mantenermi aggiornato, ma a volte faccio proprio fatica.
I generics penso di averli capiti ma ci sono esempi in rete che mi risultano difficili, ad esempio :
un interesante pattern chiamato Assigner Design Pattern
dice:
A final variable is used to define a constant value and reference, and can only be defined once. In most cases, declaring a final variable is just a matter of assigning to a primitive value or an object reference directly. However, in some cases, declaring a final class/instance variable may be more involving especially it gets assigned from a method that throws an Exception (eg API for database access, web access), or it may involve multiple statements.
Editors Note: This content was submitted by geekycoder
In such cases, the code may become cluttered with class helper methods and dummy temporary variables that help define the final variable, making the code look less elegant and harder to maintain. The following common ways of declaring a final variable in those situations might look familiar to many.
http://geekycoder.files.wordpress.com/2010/03/image.png
Recommended way: Assigner Design Pattern
A better way to declare final instance/class variable is to use Generic method and interface with the advantages of
* forcing initializing method in the same statement as the final variable declaration.
* reusing as design pattern (term: Assigner Design Pattern) and enhancing code readability
There is generic helper class whose interface and method accept a parametric type similar to the type of final variable. The advantage of using Generics is that the type mismatch will be caught at compile time rather than runtime. This design pattern is termed Assigner because it assigns value to a variable from initializing method.
http://geekycoder.files.wordpress.com/2010/03/image2.png
Using the design pattern, the code becomes cleaner and elegant.
http://geekycoder.files.wordpress.com/2010/03/image3.png
qualcuno mi illumina?
cerco di mantenermi aggiornato, ma a volte faccio proprio fatica.
I generics penso di averli capiti ma ci sono esempi in rete che mi risultano difficili, ad esempio :
un interesante pattern chiamato Assigner Design Pattern
dice:
A final variable is used to define a constant value and reference, and can only be defined once. In most cases, declaring a final variable is just a matter of assigning to a primitive value or an object reference directly. However, in some cases, declaring a final class/instance variable may be more involving especially it gets assigned from a method that throws an Exception (eg API for database access, web access), or it may involve multiple statements.
Editors Note: This content was submitted by geekycoder
In such cases, the code may become cluttered with class helper methods and dummy temporary variables that help define the final variable, making the code look less elegant and harder to maintain. The following common ways of declaring a final variable in those situations might look familiar to many.
http://geekycoder.files.wordpress.com/2010/03/image.png
Recommended way: Assigner Design Pattern
A better way to declare final instance/class variable is to use Generic method and interface with the advantages of
* forcing initializing method in the same statement as the final variable declaration.
* reusing as design pattern (term: Assigner Design Pattern) and enhancing code readability
There is generic helper class whose interface and method accept a parametric type similar to the type of final variable. The advantage of using Generics is that the type mismatch will be caught at compile time rather than runtime. This design pattern is termed Assigner because it assigns value to a variable from initializing method.
http://geekycoder.files.wordpress.com/2010/03/image2.png
Using the design pattern, the code becomes cleaner and elegant.
http://geekycoder.files.wordpress.com/2010/03/image3.png
qualcuno mi illumina?