001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.lang3.builder;
018
019/**
020 * The Builder interface is designed to designate a class as a <em>builder</em>
021 * object in the Builder design pattern. Builders are capable of creating and
022 * configuring objects or results that normally take multiple steps to construct
023 * or are very complex to derive.
024 *
025 * <p>
026 * The builder interface defines a single method, {@link #build()}, that
027 * classes must implement. The result of this method should be the final
028 * configured object or result after all building operations are performed.
029 * </p>
030 *
031 * <p>
032 * It is a recommended practice that the methods supplied to configure the
033 * object or result being built return a reference to {@code this} so that
034 * method calls can be chained together.
035 * </p>
036 *
037 * <p>
038 * Example Builder:
039 * <pre><code>
040 * class FontBuilder implements Builder&lt;Font&gt; {
041 *     private Font font;
042 *
043 *     public FontBuilder(String fontName) {
044 *         this.font = new Font(fontName, Font.PLAIN, 12);
045 *     }
046 *
047 *     public FontBuilder bold() {
048 *         this.font = this.font.deriveFont(Font.BOLD);
049 *         return this; // Reference returned so calls can be chained
050 *     }
051 *
052 *     public FontBuilder size(float pointSize) {
053 *         this.font = this.font.deriveFont(pointSize);
054 *         return this; // Reference returned so calls can be chained
055 *     }
056 *
057 *     // Other Font construction methods
058 *
059 *     public Font build() {
060 *         return this.font;
061 *     }
062 * }
063 * </code></pre>
064 *
065 * Example Builder Usage:
066 * <pre><code>
067 * Font bold14ptSansSerifFont = new FontBuilder(Font.SANS_SERIF).bold()
068 *                                                              .size(14.0f)
069 *                                                              .build();
070 * </code></pre>
071 *
072 * @param <T> the type of object that the builder will construct or compute.
073 *
074 * @since 3.0
075 */
076@FunctionalInterface
077public interface Builder<T> {
078
079    /**
080     * Returns a reference to the object being constructed or result being
081     * calculated by the builder.
082     *
083     * @return the object constructed or result calculated by the builder.
084     */
085    T build();
086}