Skip to content

nguyenanduong/banme

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 

Repository files navigation

Introduction

Banme provides a set of syntactic sugars on top of Java so that help to reduce the verbosity and reinforce best practices. Banme is not a new language but a Java extension. A pure Java program can compile with Banme. On the other hand, Banme libraries are compatible and usable in other Java program.

Features

Service

Service is a final, stateless class which provides a single responsibility or a set of related responsibilities. Service can be injected with dependencies but cannot be inherited. Banme advocates "Composition over Inheritance" hence improve testability. Banme also favors "Convention over Configuration" and "DRY"

public service FooService 
   implements FooInterface 
   injects FooSayer {

   public void sayHello() {
       // fooSayer is automatically inferred by naming convention
       fooSayer.say("Hello");
   }
   
   public static void main(String[] args) {
       // Auto generated constructor for constructor injection
       FooInterface fooService = new FooService(new FooSayer());
       fooService.sayHello();
   }
}

Injects with qualifier:

public service FooService 
   implements FooInterface 
   injects @FooQualifier FooSayer {
   ...
}

Override naming convention:

public service FooService 
   implements FooInterface 
   injects FooSayer as myFooSayer {
   ...
}

Entity

Banme entities are value classes which are immutable by default. All args constructor, no arg constructor, getters, and fluent interface for building are auto generated.

public entity Bar {
   int width;
   int height;
}

var bar1 = new Bar(1,1);
var bar2 = bar1.width(2).height(3);
var x = bar1.width;
var y = bar2.height;
assert (x != y);
assert (bar1 != bar2);

Mutable entity

public mutable entity Bar {
   int width;
   int height;
}

var bar = new Bar(1,2);
bar.width = 2;
assert bar.width == 2;

Anonymous Entity

var bar = {
   width: 1,
   height: 2
}

Destructuring

var bar = new Bar(1,2);
var { width, height } = bar;

Elvis operator

public entity Bar {
    Qux qux;
}

public entity Qux {
    String name;
}

var bar = new Bar(null);
var name = bar?.qux.name;

FAQs

About

Make Java great again

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published