[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [aspectj-users] annotations vs. marker interfaces

Hi -

You're right that annotations don't replace interfaces, but
I'm not sure they're intended to.

I'm not sure who promised that annotations would replace
marker interfaces.  It's of course possible that some uses
of tag interfaces can be replaced - particularly where
you'd like to avoid targeting subtypes of the tagged types
(and the annotation is not inherited (default)).

(I don't think the implementation of the Observer pattern
just uses marker interfaces.  To me, when you declare a
member on an interface and declare that a class implements
the interface, you're using the interface as a mixin (not
just a marker aka tag).)  

wrt ITD's, Since 1.1, inter-type declarations must resolve
to a specific type at compile time.  You used to be able to
use a typepattern:

  void (Foo || Bar).go(){}

Now it has to be a type (it may be an interface).  One
reason is so "this" in the body has a given declared
compile-time type.   E.g., if the declared type is an
interface, then you will not be able to refer to a method
on a target type (not in the interface) without casting.
 e.g.,

  // given
  interface IFoo{}
  class C {
    void bar() {}
  }
  
  // and in an aspect..
  declare parents : C implements IFoo ;
  public void IFoo.foo() {  
      bar(); // illegal - no bar() in IFoo
      ((C) this).bar(); // works for C, not for others
  }

Does that make sense?  The statement about annotations and
ITD's just extend the 1.1 rule to the case of
annotation-based type patterns.

Wes

On Tue, 01 Nov 2005 19:51:06 +0000
 mmonteiro@xxxxxxxxxxxx wrote:
> Hi everybody, 
> I've been experimenting with the latest features of
> AspectJ 5. In particular, I wanted to assess whether
> annotations can completely replace marker interfaces.
> That was an early promise of annotations before the
> advent of AspectJ 5, if I recall correctly.
> If annotations can really replace marker interfaces, it
> should be possible to rewrite the widely known
> implementation of the Observer pattern by
> Hannemann/Kiczales using annotations such @Subject and
> @Observer, in place of the Subject and Observer marker
> interfaces... 
> However, the documentation accompanying AJDT says that
> "An annotation type may not be the target of an
> inter-type declaration"
> Well, I see two ways to interpret this:
> a) we cannot use ITDs add state and behaviour to
> annotation types.
> b) we cannot use ITDs to add state and behaviour to types
> _referred through annotation types_. 
> a) makes sense, but I'm not sure the doc means b) as
> well.
> If b) is true as well, annotations cannot be used in
> place of marker interfaces. Is this correct, or am I
> missing something? 
> Thanks, 
> Miguel Pessoa Monteiro, Ph.D.
> URL: http://gec.di.uminho.pt/mpm/
> Escola Superior de Tecnologia de Castelo Branco
> ESTCB URL: http://www.est.ipcb.pt/portal/ 
> 
> _______________________________________________
> aspectj-users mailing list
> aspectj-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/aspectj-users