Code Monkey home page Code Monkey logo

btf's Introduction

Read me first

This project, as of version 1.1, is licensed under both LGPLv3 and ASL 2.0. See file LICENSE for more details. Versions 1.0 and lower are licensed under LGPLv3 only.

Note the "L" in "LGPL". LGPL AND GPL ARE QUITE DIFFERENT!

What this is

This package contains interfaces to help for two design patterns:

  • the builder pattern;
  • another pattern, which I came up with, called the "freeze/thaw pattern".

All in all, it consists of only three Java source files, one per interface. Full source code is included in this README.

Current version

The current version is 1.2.

Maven artifact

<dependency>
    <groupId>com.github.fge</groupId>
    <artifactId>btf</artifactId>
    <version>your-version-here</version>
</dependency>

Source

Builder

The full source of this interface is as follows:

public interface Builder<T>
{
    T build();
}

There is really no need to comment on this interface; it is pretty obvious.

Freeze/thaw

These are two interfaces:

// Frozen
@Immutable
public interface Frozen<T extends Thawed<? extends Frozen<T>>>
{
    T thaw();
}

// Thawed
@NotThreadSafe
public interface Thawed<F extends Frozen<? extends Thawed<F>>>
{
    F freeze();
}

These interfaces are meant to be used in a pair of classes, where class F is immutable, and class T is a modifiable version of F. The recommended use is as follows:

  • F and T are in the same package; all instance variables of either class are package local;
  • F has no publicly available constructor;
  • F has a static factory method in order to return a "virgin" instance of T.

As you can see from the annotations (which are JSR 305 annotations), another part of the contract is that any F instance is immutable; as to T instances, there is no guarantee as to their thread safety.

In summary, the free/thaw pattern is a "reversible" builder pattern -- that is, a pattern where you can create, from a "frozen", immutable instance, an equivalent builder instance bearing the same characteristics.

btf's People

Contributors

fge avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.