Class ComponentWithSetterInjection

    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getData()
      Returns the component's data
      void printData()
      Prints the component's data using the injected print service
      void setData​(java.lang.String data)
      Sets the component's data
      void setPrintService​(PrintService printService)
      Allows the framework to set the reference to the print service.
      In the wildlife you'll probably see setter injection in conjunction with annotations.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • setPrintService

        public void setPrintService​(PrintService printService)
        Allows the framework to set the reference to the print service.
        In the wildlife you'll probably see setter injection in conjunction with annotations. Annotations allow to choose an individual setter name (because the annotation indicates the need, not the name of the method), and they support properties. Maybe one component needs a thread-safe printer service while the most do not. Using an injection annotation the component can describe what it needs on a more fine-grained level.
        Parameters:
        printService - service to be injected
      • getData

        public java.lang.String getData()
        Description copied from interface: Component
        Returns the component's data
        Specified by:
        getData in interface Component
        Returns:
        data
      • setData

        public void setData​(java.lang.String data)
        Description copied from interface: Component
        Sets the component's data
        Specified by:
        setData in interface Component
        Parameters:
        data - component data
      • printData

        public void printData()
        Description copied from interface: Component
        Prints the component's data using the injected print service
        Specified by:
        printData in interface Component