7

I am responsible for a software project for a few years now (a Java desktop application, which is mostly event-driven). I started it from scratch, and at the beginning of this project I made some strong choices on the architecture of the software.

My architecture

I introduced the Module class, which represents a functionnal part of the application, with a well-defined responsability. The only thing a Module exposes to the world is a set of "communication handles". There are 4 types of communication handles :

  • an Emitter<T> can emit a message of type T.
  • a Handler<T> can receive a message of type T
  • a Puller<R, Q> can make a query represented by a message of type Q, and will receive a response message of type R
  • a PullServer<R, Q> can receive a query represented by a message of type Q and will send back a response message of type R.

Then, at the beginning of the execution of the application, I instanciate all the modules that compose the application, and I set up all the connections between them. An Emitter can be linked to one or many Handlers, and a PullServer can serve one or many Pullers (the types of these two endpoints must be compatible, of course).

All the classes used to represent a message are immutable, and are defined in one subproject. Every Module depends on that subproject, and nothing more. This makes the Modules very decoupled (a Module knows nothing about the other Modules, and their input/output to the outside world very clear). Also, the dynamic aspect of the application (the dataflow) is defined in a unique place, in the main function. Also, it is super easy to test a Module, we just have to provide fake Emitters and PullServers, and plug it to the Module's Handlers and Pullers.

My thoughts on this architecture

So, this is the first "big" software project I work on, and I made up this design because it felt like the right thing to do. Now, the project is working just fine, with a total of 57 Modules working together.

One of my co-worker, who joined the project recently, asked me if this was a common architecture, if there was a name for such a design. I don't have an answer, since I am not really familiar with other real-world software architectures.

It seems to me that this design is close the the concept of Actors, that we can find in languages such as Scala (and maybe Erlang). However, Actors do not provide the decoupling provided by my design. And Actors have an additional capability : each Actor has its own message queue, and its own thread of execution (kind of).

Also, I think my design is somewhat related to the Dependency Injection pattern, in the sense that dependencies between the Modules are defined in a central place. However, this pattern deals with interfaces, not with messages. It does not define how the modules communicate (notification, request/response).

The question (finally !)

Do you know of a software project that's architecture is similar to mine? Is there a name for that?

Edit

@Doc Brown suggests that this design is similar to the Flow Design. I cannot agree more. Here is a one to one comparision between those two designs :

  • My Module is the same thing as a Functionnal Unit.
  • My Emitter/Handler are the same as the Output-pin/Input-pin, except mine don't have a name. In my design, the "communication handles" are only identified by their types.
  • The connections between my Modules is the equivalent of their wires.
  • My Puller/PullServer is similar to their Dependency relations. However, they say there is an explicit dependency from the caller to the callee. In my design they are decoupled.
  • They define the concept of Boards. That's interesting, I think I'll borrow this idea !
  • They define the concept of Configuration. I do have the need for configuring a Module in my program, and for that I define a configuration Handler on some of my Modules.
  • Both solutions are synchronous.
  • I don't have the concept of map and join. But I don't feel the need for it.

Well found, Doc !

5
  • 9
    It's called the "barjak Template." Tell your coworker I said so. Sheesh, developers can be so hung up on popularity. If it's really that important to him, suggest that he change his name to Kardashian. </kidding> Feb 17, 2012 at 18:29
  • Great question, well formatted, well said! +1
    – Dynamic
    Feb 17, 2012 at 18:32
  • I asked this question here not just because of my co-worker. I'm actually really curious to know if some developers had the same approach than me for structuring a large program.
    – barjak
    Feb 17, 2012 at 19:29
  • @RobertHarvey : I'll call it the barjak template only if it really is unique, which I highly doubt ! Also, I have to admit that the idea of formalizing the "communication handles" (handler, emitter, puller, pullServer) was not completely mine, another co-worker helped a lot for that.
    – barjak
    Feb 17, 2012 at 19:33
  • No one seems to have mentioned the Publish/Subscribe pattern, often associated with distributed computing, message brokers, etc... Message passing is done by publishing; wiring is done by subscribing. I suppose that your Puller/PullServer could be modeled as a two step pub/sub pattern, in which subscribers subscribe to content though can also publish queries and publishers provide content but also subscribe to queries.
    – Erik Eidt
    Sep 12, 2016 at 18:52

3 Answers 3

5

"Flow Design" or "Flow Orientation" is what you are looking for, read this

Link

The german software engineer Ralf Westfal has written a lot of articles about this style of software design, especially in the form of "Event based components". His german blog contains some more pointers to other articles (most of them in german).

3
  • Wow I'm impressed, this is so close to my design ! I can even make a 1:1 comparison between Flow Design and Barjak design. Ok, I'm doing that by editing my question. Thanks for those links !
    – barjak
    Feb 17, 2012 at 20:32
  • Have you ever used this design yourself ?
    – barjak
    Feb 17, 2012 at 20:51
  • 1
    @barjak: not in production code, but I am pretty sure this will work and has a lot of advantages. I tried one of those "Katas" - clean-code-advisors.com/ressourcen/application-katas
    – Doc Brown
    Feb 17, 2012 at 21:05
8

Seems like event-driven architecture, but I don't know of any examples exactly like what you are doing. Is your co-worker asking out of curiosity or could it be a veiled criticism (i.e. why did you do things in this way)?

7
  • Thanks for you input. The event-driven architecture is indeed very loosely coupled. I guess this is part of the answer. As I understand it, event driven architecture is very broad category. The Swing example, cited in the Wikipedia article, is not quite related to my architecture (except that both make use of the Observer pattern)
    – barjak
    Feb 17, 2012 at 19:47
  • As an aside, maybe there are more descriptive class names you can come up with that will give you a better metaphor for your architecture. Feb 17, 2012 at 19:49
  • About your second question, it is definitely a curiosity question from my co-worker. He actually is quite impressed by the capabilities of this system, and he was wondering how such a design could have emerged. Also, his question was about both the architecture I presented here, and the library I wrote for defining and building the immutable messages I was talking about. I haven't talked about it in my question, since it is independent from the presented architecture. But these two things work really well together, and allowed us to write really cool tools around them.
    – barjak
    Feb 17, 2012 at 20:01
  • english is not my native language, so it's not easy to come up with something else than simple words ! Any suggestions ? :)
    – barjak
    Feb 17, 2012 at 20:05
  • 1
    MessageSupplier, MessageReciever, QuerySupplier, QueryReciever, may be good names for Emitter, Handler, Puller, PullServer, because it emphasizes the relationships between the classes in a common way. But you know the architecture better than I do and maybe the names as okay as they are... Feb 17, 2012 at 20:49
1

As other said, you are using event-driven architecture, and it looks like you are using some kind of observer pattern or signal/slots to announce/handle events.

3
  • Yes, the signal/slot concept from the Qt library came to my mind. An interresting thing in my implementation is that these signal/slots (Emitter/Handler) of a Module can be discovered at runtime, allowing for cool tricks. I'm curious whether this is something Qt can do.
    – barjak
    Feb 17, 2012 at 20:54
  • @barjak Yes, Qt informs if for example specific slot doesn't exists. Not sure if that is what you meant with "discovered at runtime" (my java experience is not big). Feb 17, 2012 at 20:56
  • No, I was talking about the capability to list all the signals and all the slots of a class. In my implementation, a Module can be asked to list its Handlers. This is quite handy for automatically generating a GUI that stimulates any Module you give to him.
    – barjak
    Feb 17, 2012 at 21:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.