Interface BeanFactory

All Known Implementing Classes:
AbstractBeanFactory, BeanCreator, BeanFactoryManager

public interface BeanFactory
Interface for a factory to create instances of WritableBean. In case you are implementing beans extending Bean, you can simply ignore this interface and create your instances with the new operator. However, framework code should use this interface to create instances for a given class to support the flexibility provided by this module.
Since:
1.0.0
  • Method Summary

    Modifier and Type
    Method
    Description
    default <B extends WritableBean>
    B
    create(Class<B> type)
    Creates a new instance of the WritableBean for the given Class.
    ATTENTION:
    When creating beans from only an interface you will receive a dynamic proxy instance in JVM runtime mode.
    <B extends WritableBean>
    B
    create(Class<B> type, BeanClass beanClass)
     
    get()
     
  • Method Details

    • create

      default <B extends WritableBean> B create(Class<B> type)
      Creates a new instance of the WritableBean for the given Class.
      ATTENTION:
      When creating beans from only an interface you will receive a dynamic proxy instance in JVM runtime mode. In environments where dynamic proxies are not available mmm-bean-generator provides a tooling for you to generate according implementations during AOT compile time (e.g. for GraalVM or TeaVM). In any case some unknown implementation will work behind the scene and therefore you should not rely on the #getClass() method of a bean instance. Instead you should use ReadableBean.getJavaClass(ReadableBean) to get the proper expected result.
      Type Parameters:
      B - type of the WritableBean.
      Parameters:
      type - the Class reflecting the WritableBean.
      Returns:
      a new instance of the WritableBean specified by the given Class. If type is an interface, a generated implementation is used (either as dynamic proxy or generated at compile time). Otherwise if a class is given it needs to extend Bean, be non-abstract and requires a non-arg constructor.
    • create

      <B extends WritableBean> B create(Class<B> type, BeanClass beanClass)
      Type Parameters:
      B - type of the WritableBean.
      Parameters:
      type - the Class reflecting the WritableBean.
      beanClass - the BeanClass that has to correspond to the Class given by parameter type.
      Returns:
      a new instance of the WritableBean specified by the given Class. If type is an interface, a dynamic proxy implementation is generated. Otherwise if a class is given it needs to extend Bean, be non-abstract and requires a non-arg constructor.
    • get

      static BeanFactory get()
      Returns:
      the instance of BeanFactory.