package us.deans.pigs.client; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import us.deans.pigs.api.Wolf; import us.deans.pigs.api.Pig; import us.deans.pigs.api.AnimalFactory; public class Chapters { final static Logger logger = LogManager.getLogger(Story.class); AnimalFactory aFactory = null; // using constructor injection to inject dependency on AminalFactory - (one instance of this class will always be needed). public Chapters() { this.aFactory = new AnimalFactory(); } // meet the wolf public void chapter_01(){ logger.info("\n\nChapter 1 : \n"); // System.out.println("\n\nChapter 1 : \n"); logger.info("Once upon a time, there was this wolf..."); try { Wolf wolf = (Wolf) aFactory.getMe("a wolf"); } catch(Exception ex){ logger.error("Here..." + ex.getMessage()); logger.error("And this too..." + ex.getStackTrace()); } logger.info("A hungry wolf... a baaad wolf..."); } // the house of straw -- factory public void chapter_02() { // welcome logger.info("\n\nChapter 2 : \n"); logger.info("Meanwhile, the first pig builds a house..."); // see the pig // use a frickin' factory. try{ Pig pig = (Pig) aFactory.getMe("a pig"); pig.gather("straw"); pig.buildHouse(); } catch (Exception ex) { logger.error("Here..." + ex.getMessage()); logger.error("And this too..." + ex.getStackTrace()); } logger.info("Oh, oh... here comes the wolf!"); logger.info("The pig runs like hell toward the woods, where his brother lives"); } // the house of sticks -- constructor injection public void chapter_03() { logger.info("\n\nChapter 3 : \n"); logger.info("...Just so happens the second pig was also building a house..."); // see the pig try{ Pig pig = (Pig) aFactory.getMe("a pig"); pig.gather("sticks"); pig.buildHouse(); } catch (Exception ex) { logger.error("Here..." + ex.getMessage()); logger.error("And this too..." + ex.getStackTrace()); } logger.info("The first pig shows up and is glad to see his brother's house."); logger.info("Hide inside... here comes the wolf!"); } // the house of bricks public void chapter_04() { logger.info("\n\nChapter 4 : \n"); logger.info("The third pig builds a house..."); // see the pig try{ Pig pig = (Pig) aFactory.getMe("a pig"); pig.gather("bricks"); pig.buildHouse(); } catch (Exception ex) { logger.error("Here..." + ex.getMessage()); logger.error("And this too..." + ex.getStackTrace()); } logger.info("Oh, oh... here comes the wolf!"); } }