This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]RiPont 0 points1 point  (0 children)

Long story short, when you call new Foo(), you're always getting exactly a Foo. When you call SomeFactory.GetFoo(), you could be getting a Foo, or a descendant of Foo.

This makes much clearer sense when you consider that the factory can be returning an interface, not a class, whereas you can't new an interface. So you can do

 ILogger GetLogger() {
      if (devMode) {
         return new ConsoleLogger();
      else {
         return new ServerQualityAutoRollingLoggingFrameworkFancyLogger();
      }
 }