Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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 !

share|improve this question
7  
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> –  Robert Harvey Feb 17 '12 at 18:29
    
Great question, well formatted, well said! +1 –  Dynamic Feb 17 '12 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 '12 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 '12 at 19:33
add comment

3 Answers

up vote 3 down vote accepted

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

http://geekswithblogs.net/theArchitectsNapkin/archive/2011/03/19/flow-design-cheat-sheet-ndash-part-i-notation.aspx

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". On this german page

http://clean-code-advisors.com/ressourcen/flow-design-ressourcen

you can find links to more articles, most of them in german, some also in english.

share|improve this answer
    
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 '12 at 20:32
    
Have you ever used this design yourself ? –  barjak Feb 17 '12 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 '12 at 21:05
add comment

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)?

share|improve this answer
    
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 '12 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. –  Garrett Hall Feb 17 '12 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 '12 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 '12 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... –  Garrett Hall Feb 17 '12 at 20:49
show 2 more comments

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.

share|improve this answer
    
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 '12 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). –  BЈовић Feb 17 '12 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 '12 at 21:01
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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