Glue classes proposal (beta)

Marek Kozieł develop4lasu at gmail.com
Sat Mar 14 19:02:01 PDT 2009


Notice that it's beta specification: it's not described in full details,
half validated (translation), and it's provided for you to pre-analyse. I
still need some time to provide syntax which fully supports generics.
Multi-glue classes are under consideration as well, but this may occur to be
to complex to handle by any earth living programmer.

OVERVIEW
FEATURE SUMMARY:
Glue classes allow to link utils direct with objects.

MAJOR ADVANTAGE:
Forgotten functionality can be not such big deal now.

MAJOR BENEFIT(s):
+ New functions can be easy localised (critically important while introduce
new peoples into project).
+ Security: glue class do not see anything protected.
+ Light binding new functions with existing classes.
+ Number of used classes reduction.
+ Allow to assign methods and functions(static methods) to arrays, classes,
interfaces, …
+ It's proof against same method occurs in class and delegator as well like
in two delegators.
+ Allow to link gained(.jar) logic with new one, witch is impossible before
final developer implements his classes.
+ Allow to project compact interfaces and do not worry about additional
logic.


MAJOR DISADVANTAGE:
- Do not know any ;) sorry.

ALTERNATIVES:
Utils classes.


EXAMPLES

SIMPLE EXAMPLE:
public class base glue <? extends Date>
{

  private static final SimpleDateFormat sdf = new
SimpleDateFormat("yyyy.MM.dd");

  public String format(This this) {
    synchronized (sdf) {
      return sdf.format(this);
    }
  }

  private static final Date applicationStart = new Date();

  public static Date applicationStart() {
    return applicationStart;
  }

}
base: logic name, should start with lowercase because it's representing
logic not class.
glue <? extends Date>: logic will glue to all classes extending Date.
.format(This this): method that will be 'visible' for declared objects.
This: Object type representing this.getClass()
this: equivalent with given bound (? extends Date).
Usage:
import java.util.Date;
import pl.some.utils.base; // imported to allow ..format() execution

public class Test {

  public static void test_0(Date date) {
    System.out.println(date..format()); //simple usage
  }

  public static void test_1(Date date) {
    System.out.println(date..base.format()); //used when we have more logics
with same methods
  }

  public static void test_2(Date date) {
    System.out.println(date..pl.some.utils.base.format()); // full
declaration

  }

  public static void test_3() {
    System.out.println(Date..applicationStart()..format()); // mixed case
  }

}


ADVANCED EXAMPLE:

Will come...


DETAILS

SPECIFICATION:
JLS 8.8:
http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.8ClassDeclaration:
  NormalClassDeclaration
  GlueClassDeclaration
  EnumDeclaration

GlueClassDeclaration
  ClassModifiersopt class Identifier glue<ActualTypeArgument> GlueClassBody

ActualTypeArgument
  (JLS 4.5.1) represent objects for witch glue works: <? extends Date>,
<Date>, <Object[][]>, ...

COMPILATION:

Everything we need is already in JDK, we just need little trick to bind
static method in compilation time with existing classes.

TESTING:
Like simple static methods.

LIBRARY SUPPORT:
No.

REFLECTIVE APIS:
No.

OTHER CHANGES:
No.

MIGRATION:
None.


COMPATIBILITY
New jars are fully compatible. Code is only backward compatible.

REFERENCES
Glue classes proposal beta:
http://lasu2string.blogspot.com/2009/03/glue-classes-proposal.html

-- 
Pozdrowionka. / Regards.
Lasu aka Marek Kozieł

http://lasu2string.blogspot.com/



More information about the coin-dev mailing list