Interface IBeanFactory

  • All Known Implementing Classes:
    ProxyIBeanFactory

    public interface IBeanFactory
    Creates IBean instances for given bean interfaces.
    For example:
     
         IBeanFactory factory = ...;
         SomeBeanType bean = factory.create(SomeBeanType.class);
     
     
    IBeanFactorys are the heart and the core of the IBean framework. They are responsible for creating instances for provided IBean compliant interfaces with their desired behavior. IBean interfaces consist of setter and getter methods and super-interfaces.
    Following code shows an example of a bean interface:
     
         public interface Person {
             
             void setFirstname(String s);
             String getFirstname();
             
             void setDateOfBirth(Date d);
             Date getDateOfBirth();
             
         }
     
     

    An IBeanFactory of course cannot create a bean instance from every kind of interface. An interface that can be handled by a factory needs to follow these criteria:
    • Every method declared in the interface must either be
      • a getter or setter method,
      • a default method (interface method with a given default implementation) or
      • a method belonging to an extension interface.
    • Always a tuple of a setter and a getter method virtually defines an interface field. (firstname and dateOfBirth would be the fields of the example above.) That means for each setter a getter must exist as well and vice versa.
    • An IBeanFactory always looks on the complete list of methods including those from super interfaces. The factory does not care in which hierarchy level a method is declared. That means for example that you can declare getter and setter methods in different parent or sub interfaces as long as they are complete in the final interface that is provided to the create(Class) method.
    • Default methods are ignored by the IBeanFactory. You must therefore not have default implementations for getter or setter methods.
    • Whether an interface method is a getter or setter method and whether a method pair builds up a valid setter-getter combination is defined by the so called bean style. All built in bean styles for example require a consistent type to be used in both methods to unambiguously define the field type. If a setter for example has a primitive boolean parameter, the getter should return the same type, not even Boolean would be accepted instead. See BeanStyle for more information.
    • A method can also belong to a so called extension interface. Extension interfaces are a group of interfaces that are well known by the IBeanFactory. These interfaces are declared as super interfaces of the bean interface and add certain functionality to the beans. The IBeanFactory simply ignores all methods from these extension super interfaces. See org.coliper.ibean.extension package for more details about extension interfaces.
    If you try to create a bean instance from an interface that does not follow these set of conditions a InvalidIBeanTypeException will be thrown.

    See IBean tutorial for a more holistic view on IBean.

    At the moment there is only one IBeanFactory implementation which is ProxyIBeanFactory.

    • Method Detail

      • create

        <T> T create​(Class<T> beanType)
              throws InvalidIBeanTypeException
        Creates a new instance of a given bean type.
        Type Parameters:
        T - generic type T is the bean class provided with parameter beanType
        Parameters:
        beanType - a IBean that matches general IBean rules and that complies to the specific requirements for this factory like bean styles or supported extension interfaces
        Returns:
        an instance of the bean type, never null. The returned beans will usually have default values set for all field values, like null for objects or zero for number primitives.
        Throws:
        InvalidIBeanTypeException - if the given beanType is not a valid IBean interface for this factory