[ 
https://issues.apache.org/jira/browse/ISIS-1612?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16830163#comment-16830163
 ] 

Andi Huber commented on ISIS-1612:
----------------------------------

A year later, having made heavy use of @Mixin in the meantime, I change my view 
on this:

If code readability is the goal, keeping mixins to only represent single 
actions might be best practice! That way an action's support methods are 
encapsulated with the mixin's action.

Using lombok helps reduce boilerplate, here's my best practice style:
{code:java}
@Mixin @RequiredArgsConstructor
public class Brand_delete {
    
    @Inject private Brands brands;
    
    private final Brand holder;
    
    @Action(semantics = SemanticsOf.IDEMPOTENT_ARE_YOU_SURE)
    public BrandManager $$() {
        
        brands.delete(holder);
        
        return BrandManager.current();
    }
    
    public String disable$$() {
        
        if(holder.getProducts()!=null) {
            return "Cannot delete a 'Brand' that has associated products.";
        }
        
        return null;
        
    }

}
{code}

> Extend the programming model so that mixins can have multiple actions
> ---------------------------------------------------------------------
>
>                 Key: ISIS-1612
>                 URL: https://issues.apache.org/jira/browse/ISIS-1612
>             Project: Isis
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 1.14.0
>            Reporter: Dan Haywood
>            Priority: Major
>             Fix For: 1.18.0
>
>
> I see this as a hybrid of a contributed service and a mixin.
> I quite like the idea of calling these "responsibilities", eg
> {code}
> @Responsibility
> public class Customer_orders {
>     private final Customer customer;
>     public List<Order> getOrders() { ... }
>     public Customer addOrder(...) { ... }
>     public Customer removeOrder(...) { ... }
> }
> {code}



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to