molecules

So recently I’ve started a project. It is a library of useful Java classes with built-in validations.

Sorry, what?

Think about a person. Now try to make a Person class. I guess you would craft something like this:

public class Person {
    private String firstName;
    private String lastName;
    private Date birthDate;
    private String email;    
}

Enter fullscreen mode Exit fullscreen mode

Can you see that we have these properties: name and email address, but we have to map them to types like String, Date, etc. And do not forget about validating this data in the service or controller layer…

So instead of these, why can’t we have Name or Email types? And these types should know what is a valid email address or what is the maximum length of a name.

By using molecules, your Person class could look something like this:

public class Person {
    private Name firstName;
    private Name lastName;
    private BirthDate birthDate;
    private Email email;
}

Enter fullscreen mode Exit fullscreen mode

I see. What now?

Do you like the idea? Check out all the molecules or help! 🙂

At the moment I am at the early stages, so any help and/or advice is appreciated! 🙂

Check it here: https://github.com/floppylab/molecules

原文链接:molecules

© 版权声明
THE END
喜欢就支持一下吧
点赞14 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容