java - Confusion in Builder plus Singleton pattern in example from fluffycat -
i tryingout builder examples fluffycat
sodaimpsingleton sodaimpsingleton = new sodaimpsingleton(new cherrysodaimp()); system.out.println("testing medium soda on cherry platform"); mediumsoda mediumsoda = new mediumsoda(); mediumsoda.poursoda();
here there no relation between sodaimsingleton , mediumsuda, still when mediumsoda.poursoda() called prints cherrysodaimp.poursodaimp() how/why happening?
there relationship. sodaimpsingleton
instantiated cherrysodaimp
. next, mediumsoda extends soda
, in constructor calling method setsodaimp()
, implemented sodaimpsingleton.getthesodaimp();
in abstract soda
class, static method returns cherrysodaimp
instance created on first line.
Comments
Post a Comment