﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>llyys commented on Limit your abstractions: Application Events&amp;ndash;Proposed Solution #2&amp;ndash;Cohesion</title><description>Why add another event abstraction for executing simple business logic?

If you could just add some simple entity logic directly on to the entity. And invoke entity method "manually" by executing method when something happens. 

For example 

class Cargo{
    public virtual string DeliveryStatus {get;set;}
    public virtual Delivery Delivery {get;set;}
...
   #region business logic
public void onCargoArrived(){
   DeliveryStatus=DeliveryStatus.Ready;
}

public void onCargoMisdirected(){
   DeliveryStatus=DeliveryStatus.Misdirected; 
   CargoRecievedDate=null;  
}

}</description><link>http://ayende.com/154017/limit-your-abstractions-application-events-proposed-solution-2-cohesion#comment8</link><guid>http://ayende.com/154017/limit-your-abstractions-application-events-proposed-solution-2-cohesion#comment8</guid><pubDate>Wed, 15 Feb 2012 22:24:32 GMT</pubDate></item><item><title>Ayende Rahien commented on Limit your abstractions: Application Events&amp;ndash;Proposed Solution #2&amp;ndash;Cohesion</title><description>Ilyys,
who calls those methods? </description><link>http://ayende.com/154017/limit-your-abstractions-application-events-proposed-solution-2-cohesion#comment9</link><guid>http://ayende.com/154017/limit-your-abstractions-application-events-proposed-solution-2-cohesion#comment9</guid><pubDate>Wed, 15 Feb 2012 21:36:52 GMT</pubDate></item><item><title>Stephen Shen commented on Limit your abstractions: Application Events&amp;ndash;Proposed Solution #2&amp;ndash;Cohesion</title><description>This is very cool. I like the extension method.
I am wondering do we really need generic T abstraction in the IHappenedOn&lt;T&gt;? 

Will this interface be used to inspect another type other than Cargo? Say yes if in another context, shall we do another specific interface
eg IHappendOnCargo,  &amp; IHappendedOnApple, 
vs IHappenedOn&lt;T&gt; for Cargo, and Apple?

Shall we limit this sort of abstraction? 
</description><link>http://ayende.com/154017/limit-your-abstractions-application-events-proposed-solution-2-cohesion#comment7</link><guid>http://ayende.com/154017/limit-your-abstractions-application-events-proposed-solution-2-cohesion#comment7</guid><pubDate>Fri, 10 Feb 2012 02:29:07 GMT</pubDate></item><item><title>Ayende Rahien commented on Limit your abstractions: Application Events&amp;ndash;Proposed Solution #2&amp;ndash;Cohesion</title><description>Shawn, 
It is an extension method:

public static void ExecuteAll{T}(this IKernel kernel, Action{T} action)
{
  foreach(var item in kernel.ResolveAll{T})
  {
     action(item);
  }
}
</description><link>http://ayende.com/154017/limit-your-abstractions-application-events-proposed-solution-2-cohesion#comment6</link><guid>http://ayende.com/154017/limit-your-abstractions-application-events-proposed-solution-2-cohesion#comment6</guid><pubDate>Thu, 09 Feb 2012 18:48:27 GMT</pubDate></item><item><title>shawn commented on Limit your abstractions: Application Events&amp;ndash;Proposed Solution #2&amp;ndash;Cohesion</title><description>I'd be curious to see container.ExecuteAll, unless this is a new feature in Windsor 3 that I've totally overlooked somehow or something like that. This precise scenario is something that comes up a lot in my apps and I am always curious to see how different people implement it.</description><link>http://ayende.com/154017/limit-your-abstractions-application-events-proposed-solution-2-cohesion#comment5</link><guid>http://ayende.com/154017/limit-your-abstractions-application-events-proposed-solution-2-cohesion#comment5</guid><pubDate>Thu, 09 Feb 2012 18:42:46 GMT</pubDate></item><item><title>Sony Mathew commented on Limit your abstractions: Application Events&amp;ndash;Proposed Solution #2&amp;ndash;Cohesion</title><description>Argh...my generics &lt;T&gt; where stripped out..</description><link>http://ayende.com/154017/limit-your-abstractions-application-events-proposed-solution-2-cohesion#comment4</link><guid>http://ayende.com/154017/limit-your-abstractions-application-events-proposed-solution-2-cohesion#comment4</guid><pubDate>Thu, 09 Feb 2012 15:44:51 GMT</pubDate></item><item><title>Sony Mathew commented on Limit your abstractions: Application Events&amp;ndash;Proposed Solution #2&amp;ndash;Cohesion</title><description>Tried to post this on your previous post but looks like it didn't succeed.

IHappenOn&lt;T&gt; amounts to the mediated Event/Listener or Observer pattern e.g. Observer&lt;T&gt; or Listener&lt;T&gt; or even Processor&lt;T&gt; mediated by a central Mediator. Unfortunately in Java (not sure about C#) using Generics gets in the way because implementations generally implement multiple Listener&lt;T&gt; and  Java Type erasure will cause a compile failure.  Hence the approach I took with Event classes inlining their Mediator, Listener and optionally Processor interfaces as shown in my pasted code from a few posts ago:

&lt;pre&gt;
class CargoDeliveryStatusEvent extends Event {
  interface Mediator {  
    void fire(CargoDeliveryStatusEvent e);
    void register(Listener l);
  }
  
  interface Listener {
    void handle(CargoDeliveryStatusEvent e);
  }
  
  CargoDeliveryStatusEvent(Cargo.DeliveryStatus deliveryStatus) {
    ...
  }
}
&lt;/pre&gt;</description><link>http://ayende.com/154017/limit-your-abstractions-application-events-proposed-solution-2-cohesion#comment3</link><guid>http://ayende.com/154017/limit-your-abstractions-application-events-proposed-solution-2-cohesion#comment3</guid><pubDate>Thu, 09 Feb 2012 15:35:45 GMT</pubDate></item><item><title>Mark commented on Limit your abstractions: Application Events&amp;ndash;Proposed Solution #2&amp;ndash;Cohesion</title><description>Much easier to understand!  What we need to remember is while some of us may be rock stars when it comes to coding, junior developers (or noobs) are not.  As much as you "want"/"push" them to learn these higher level concepts it doesn't happen.  Keeping code simple goes a long way in my opinion.</description><link>http://ayende.com/154017/limit-your-abstractions-application-events-proposed-solution-2-cohesion#comment2</link><guid>http://ayende.com/154017/limit-your-abstractions-application-events-proposed-solution-2-cohesion#comment2</guid><pubDate>Thu, 09 Feb 2012 15:17:55 GMT</pubDate></item></channel></rss>