Qi4j

Qi4j in 2 minutes

To show that Qi4j is not necessarily complex, not hard to get going with and easy to deploy, we are first showing the classic HelloWorld, as small as it can get and still be Composite Oriented Programming and not only standard OOP.

Ready, Set, Go!

Let's say we want to do the common HelloWorld example, but with a more domain-oriented setting. We have a Speach interface that does the talking;

Speaker.javaexternal link, opens in new window

Qi4j is an implementation of Composite Oriented Programming. So, we need a Composite for our domain model. We are creating a PoliticianComposite, that among other things can talk, via the Speaker interface. We create a PoliticianComposite that extends from the Composite interface and our Speaker interface. But we also need an implementation for Speaker, which we also declare in our Composite, the @Mixins( SpeakerMixin.class ).

PoliticianComposite.javaexternal link

And of course, the simple implementation of the Speaker interface. In this case, return a String with the content "Hello, World!".

SpeakerMixin.javaexternal link

So far so good. We now need to make this into something that can run. This can be done like this;

Main.javaexternal link, opens in new window

The SingletonAssembler creates the simplest Qi4j Runtime. It provides access to a CompositeBuilderFactory, from which we can instantiate our PoliticianComposite as a Speaker.

Done!

Powered by SiteVisionexternal link.