java - If we are using Factory Pattern should we hide products from user? -


let have animalfactory class produces dog, cat , fish. using animalfactory makes things incredibly simpler , fine.

my question is there rule or good practice suggests hide dog, cat , fish being used directly? mean dog mydog = new dog(); forbidden in code.

if there is, how can hide them properly?

yes, if objects should created through factory, should try avoid possibility of skipping rule.

in c#, if consumers of dog, cat , fish on different assemblies, can make constructors internal, way factory, implemented in same assembly "animals" can create them.

i'm sure there's similar in java.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -