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

Popular posts from this blog

matlab - How to equate a structure array to structure array -

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -