> IIRC, what you ask for already exist in several forms in Qi4j. On one
> hand you can place the mutable and immutable methods in separate
> interfaces and pass one or the other (or "both") around. The other way
> is the brand new feature of 'multiple types for entities', which
> allows more than one interface per Entity instance.

But if I have a composite, which implements both immutable and mutable 
interfaces, and then it is passed around as immutable interface, it is possible 
for client to cast it into mutable interface, and then use methods of that 
interace to change state. So it must be two different composites which 
implement mutable and immutable interfaces. That's why I don't think using 
multiple types for one entity is gonna work here - then it will be a matter of 
simple casting the entity object to get rid of immutability. Kind of what 
const_cast does in C++.
I'm just wondering, if I'm doing this thing correctly. I've excluded the 
methods "getChildren" since all they do is query (that bidirectional 
association thingy). I am aware of Composite design pattern ( 
http://en.wikipedia.org/wiki/Composite_pattern ), but Qi4j site is talking 
something about "design patterns and so called best practices" being effect of 
problems, which Qi4j tries to solve. So I decided to not to use it. Correct me, 
if I misunderstood something here. :)
Also wondering whether I'm using the @Uses annotation in correct way? I mean, 
it's purpose is to just inject custom objects from builder, right? I wrote this 
code from scratch in e-mail, since I don't have access to my home comp right 
now, so might have syntax or other errors.

@Mixins({ ImmutableComposable.ImmutableComposableMixin.class })
interface ImmutableComposable {
  ImmutableComposable getParent();

  abstract class ImmutableComposableMixin implements ImmutableComposable {
    @Uses MutableComposable.MutableComposable _state;
    
    public ImmutableComposable getParent() {
      return this._state.parent().asImmutable();
    }
}

@Mixins({ MutableComposable.MutableComposableMixin.class })
interface MutableComposable {
  public MutableComposable getParent();
  public void setParent(MutableComposable newParent);
  public ImmutableComposable asImmutable();

  interface MutableComposableState {
     public Association<MutableComposable> parent();
  }

   abstract class MutableComposableMixin implements MutableComposable {
     @This private MutableComposable.MutableComposableState _state;

     @Service private ImmutableComposableFactory _icf;

     private ImmutableComposable _immutable;
     
     public MutableComposable getParent() {
        return this._state.parent().get();
     }

     public void setParent(MutableComposable newParent) {
       this._state.parent().set(newParent);
     }

     public ImmutableComposable asImmutable {
       if (this._immutable == null) {
          this._immutable = this._icf.createNewImmutable(this._state);
       }
       return this._immutable;
     }
}

// The ImmutableComposableFacotry then simply uses builder to create prototype, 
and injects state via builder.uses() method.
 
> > I hope I am not asking for too much. Of course if your project is not
> > open-source or you can't or don't want to give it out, it's no problem.
> 
> Yes it is not open-source, but that is not the main reason, since
> sharing some snippets isn't a big deal. But I have not done enough
> 'coding' on it yet, mostly just drawings on paper and whiteboard. And
> I am also on the road (currently in Berlin, soon to Prague) and don't
> have enough time on these things right now.

Ahh, okay. Well, if you get time and/or some code done and feel like sharing, 
feel free to do so. Once I actually have something proper to share, I think I 
will, if anyone shows interest.

_________________________________________________________________
Invite your mail contacts to join your friends list with Windows Live Spaces. 
It's easy!
http://spaces.live.com/spacesapi.aspx?wx_action=create&wx_url=/friends.aspx&mkt=en-us
_______________________________________________
qi4j-dev mailing list
[email protected]
http://lists.ops4j.org/mailman/listinfo/qi4j-dev

Reply via email to