Before you understand how to use Macaroni framework, you probably want to know why you should use it.

This article answers why the Macaroni framework has appeared.

C Motivation

We do set 2 simple aims:

  1. Simplify things
  2. Reduce dependecies

The questions are: What we want to simplify? What dependencies we want to remove?

Say, you want a class to produce events and another class to consume them... Have a look at the classic observer pattern (a.k.a. Publish/subscribe or pub/sub):

observer pattern

Let's define those abstractions in a simple code:


public interface Subject {
    public void attach(Observer aListener);


To be able to distribute evens among any class implementing a specific interface, you have to have an abstract observer interface

public interface Observer {
    public void update();


Now, let's implements something..
If you want a class be able to produce events, you have to maintain a collection of observers (event listeners). Furthermore, you have to maintain the event distribution process itself:

import java.util.Collection;

public class ConcreteSubject implements Subject{
    private Collection<Observer> observers;
    public void attach(Observer observer) {
    public void notifyObservers(){
        for(Observer observer: observers){


Off course, you need an observer implementation. Not a big deal!

public class ConcreteObserver implements Observer{

    public void update() {
        // DO something really useful



Finally, you need something to assemble the things together and make it run:

public class Assembler {
    public void runIt(){
        Subject subject=new ConcreteSubject();
        Observer observer=new ConcreteObserver();


Now let's see what we have.. We do have the 5 classes coupled together.

  1. ConcreteSubject + Observer + Subject
  2. ConcreteObserver+ ConcreteObserver + Subject
  3. Observer + Subject
  4. Assemler + ConcreteSubject + ConcreteObserver

So, we have 5 classes with about 6 dependencies among them.


Macaroni framework provides little bit simplier model: