Events in boundaries

102 views
Skip to first unread message

Lee

unread,
Mar 12, 2014, 6:05:16 PM3/12/14
to clean-code...@googlegroups.com
Hi

Is there a reason why the interfaces that form a boundary couldn't be implemented with one direction using an event?

for example:
whereas you may have an external (to the app) item send a request to an interactor using an interface the interactor implements, the interactor performs its work, then responds using the interface the external item implements. is there a reason why the external item couldn't implement an interface that includes an event that the interactor subscribes to, with the incoming request object being passed as EventArgs?

If i'm not being clear enough let me know and i'll provide the more specific scenario that makes me want to do this.

any thoughts appreciated

Lee

Jop van Raaij

unread,
Mar 14, 2014, 5:03:10 AM3/14/14
to clean-code...@googlegroups.com
I think this is exactly what Uncle Bob describes as the presenter. See http://blog.8thlight.com/uncle-bob/2012/08/13/the-clean-architecture.html.

The client (external to the app) implements the presenter and puts it into the interactor. The interactor uses the interface of the presenter to put the result in the presenter.

Maybe I don't understand the question?

Lee

unread,
Mar 14, 2014, 7:53:53 AM3/14/14
to clean-code...@googlegroups.com
Hi Jop

Thanks for the link, i'll elaborate a bit more;

What i understand from the architecture episode is that the communication between the internal interactor and the external client is normally through 2 interface definitions; both defined internally, with one being implemented by the interactor and used by the client, the other implemented by the client and used by the interactor, together these 2 interfaces form part of the boundary, as the interactor implements an interface this makes me think of the interactor as implementing a method, the client uses the method to pass in the request.

what i'd like to do is define two interfaces that are both implemented by the external client, one interface would be an Event that the interactor is subscribed to, the second the method the interactor uses to reply to the client. therefore instead of the client calling a method on the interactor; the client raises the event which passes control to the interactor, the request could be included in the EventArgs and the 'sender' of the event is the client which implements the reply interface. (i'm using C#).

the only down side that comes to my mind is that the instance of the interactor exists prior to being used as it is subscribed to the event, however this isn't actually the true interactor for the use case, the object subscribed to the event would actually use an "InteractorFactory" to get the actual interactor instance required and execute that true interactor.

The reason i want to do this is because the application i'm going to write emulates Micro computers on a network that interact with DPS6 superminis over HDLC/Topsynet, so the client to my interactors is actually the interface to the network, each communications message that comes in will be addressed to a Topsynet channel, essentially addressed to a piece of software on a micro, or in my case; a specific interactor.

the strategy of using an event in the boundary seems fine to me in this scenario, but i haven't come across an example of this and i'm new to Clean Code (seen the light!), so could be missing something.

thanks
Lee

Caio Fernando Bertoldi Paes de Andrade

unread,
Mar 14, 2014, 8:16:38 AM3/14/14
to clean-code...@googlegroups.com
Lee,

In his post about Domain Discontinuity, Uncle Bob states that architecture is directly influenced by whether the application is request/response, event or batch-based.

So I guess your event-based approach will cause some major changes in how your architecture will look like.

Maybe UncleBob himself can clarify more about this.

Cheers,
Caio

--
The only way to go fast is to go well.
---
You received this message because you are subscribed to the Google Groups "Clean Code Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clean-code-discu...@googlegroups.com.
To post to this group, send email to clean-code...@googlegroups.com.
Visit this group at http://groups.google.com/group/clean-code-discussion.

Lee

unread,
Mar 14, 2014, 3:40:38 PM3/14/14
to clean-code...@googlegroups.com
Hi Caio

Interesting article, i think the introduction is an absolute classic, unfortunately the article doesn't elaborate regarding the differences in architecture.

Although i would like to use an event in the boundary interface, i don't think the system itself is event driven as such, the way a GUI application could be. the essence of the system is that the DPS6s send out messages/requests to Micros, the micro performs some processing based on the request and/or type of request, then usually sends back a response. the exception would be a message such as a time synchronization message, whereby the micro updates its internal clock but doesn't send a response.

i would also be interested to hear UncleBobs thoughts

cheers
Lee
To unsubscribe from this group and stop receiving emails from it, send an email to clean-code-discussion+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages