All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.yetamine.lang.creational.Factory Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2016 Yetamine
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.yetamine.lang.creational;

import java.util.Objects;
import java.util.function.Function;

/**
 * An interface for factories and builders.
 *
 * @param 
 *            the type of the product
 */
@FunctionalInterface
public interface Factory {

    /**
     * Provides a new instance of the product.
     *
     * 

* Technically, the result does not have to be a brand new instance if the * result is immutable and may be shared. However, the result must be such * an instance that it can be used by multiple clients without their mutual * interference. * * @return a new instance of the product */ T build(); /** * Makes a factory which uses a template object as the prototype for making * more instances. * * @param * the type of the template * @param * the type of the product * @param template * the template for the builder. It must not be {@code null}. * @param builder * the builder which takes a template object and returns an * independent copy of it. It must not be {@code null}. * * @return a factory using a template object */ static Factory prototype(U template, Function builder) { Objects.requireNonNull(template); Objects.requireNonNull(builder); return () -> builder.apply(template); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy