Richard Wallace wrote:
> Ok, that's pretty cool.  I got it working, but I have to admit I don't 
> entirely understand _how_ it works.  I think I may just be missing the 
> details behind private mixins.  I knew that with mixins you could define 
> the implementation of the operations for entities and composites, but I 
> had no idea you could use them to introduce what, I'm guessing, amounts 
> to private properties.

Correct. You declare mixin implementations using @Mixins, and that can 
be used for either methods in the Composite type *or* methods in any 
interfaces required by @This uses. In the case of properties and 
associations it's a little bit more magic, since they are backed by 
generic mixins which handles any method as long they return properties 
or associations. I.e. you can do funky stuff like this:

public class BusinessMixin
   implements Business
{
   @This PrivateState state;

   public void doStuff()
   {
     state.someProperty().get();
   }

   interface PrivateState
   {
     Property<String> someProperty();
   }
}

The Business interface might be included in the Composite type (e.g. 
BusinessComposite extends Business,EntityComposite). The @This injection
states that a reference to "PrivateState" should be provided. The only 
thing that is relevant as to whether this is possible or not is whether 
all methods in PrivateState has mixin implementations. Since it only 
contains properties, and the generic mixin PropertyMixin which is 
declared on the Composite base interface can handle it, everything is fine.

> Is it the @This annotation that makes it work?  

Yeah, you can think of "@This" as "this is how I want to view myself", 
and as long as the injected type can be implemented using any 
combination of typed mixins and generic mixins, that's ok.

In general, Composite Oriented Programming has the position that an 
object does not really exist unless it is being observed, i.e. any 
context that any internal or external usage thinks that it has, it has 
(this is true even for external usages of PrivateState if you get clever 
with casting, but that's a different topic). There is really nothing 
"inherent" in an object, which is rather different from traditional 
modeling. Context is everything, and therefore non-context is nothing.

<Cue analogies with quantum mechanics and the notion of probability 
waves, observers and events>

> Does that make that field a field of the composite or entity the mixin 
> is being applied to?

Yes, someProperty() above will be considered to be a property of the 
Entity, even though the only reference to it is from the internal @This 
reference.

/Rickard

_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to