This project has retired. For details please refer to its Attic page.
Polygene™ in 2 minutes
Polygene™
Introduction
Tutorials
Javadoc
Samples
Core
Libraries
Extensions
Tools
Glossary 

Polygene™ in 2 minutes

Tip

Theses tutorials are based on actual code found in the tutorials/ directory of the Polygene™ SDK sources. You should start your favorite editor and find the code related to this tutorial, run it and play with it.

To show that Polygene™ 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.

If you want to reproduce what’s explained in this tutorial, remember to depend on the Core Runtime artifact that depends on Core API, Core SPI, and Core Bootstrap:

Table 1. Artifact

Group IDArtifact IDVersion

org.apache.polygene.core

org.apache.polygene.core.runtime

3.0.0


See the Depend on Polygene™ tutorial for details.

Ready, Set, Go!

Let’s say we want to do the common HelloWorld example, but with a more domain-oriented setting. We have a Speaker interface that does the talking. But we also need an implementation for Speaker, which we declare here via the @Mixins( SpeakerMixin.class ).

@Mixins( SpeakerMixin.class )
public interface Speaker
{
    String sayHello();
}

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

public class SpeakerMixin
    implements Speaker
{
    @Override
    public String sayHello()
    {
        return "Hello, World!";
    }
}

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

public class Main
{
    public static void main( String[] args )
        throws Exception
    {
        SingletonAssembler assembler = new SingletonAssembler(              // <1>
            module -> module.transients( Speaker.class ) );                 // <2>
        Speaker speaker = assembler.module().newTransient( Speaker.class ); // <3>
        System.out.println( speaker.sayHello() );
    }
}
  1. The SingletonAssembler is a convenience class that creates a Polygene™ Runtime instance and an application with one layer and one module in it.
  2. We declare a TransientComposite of type Speaker.
  3. We create the Composite instance from the Module.

Done!

Next step, Polygene™ in 10 minutes.