Did factory method violates dependency inversion principle?
<pre><code>public class DependentPizzaStore {
  public Pizza createPizza(String type) {
    Pizza pizza = null;
    if (Style.equals("NY")) {
      if (type.equals("cheese")) {
        pizza = new NYStyleCheesePizza();
      }
      else if(type.equals("Veggie")){
        pizza = new NYStyleVeggiePizza();
      }
    }

    pizza.prepare();
    pizza.bake();
    pizza.cut();
    pizza.box();
    return pizza;
  }
}
</code></pre>

<p>this example from headfirst design patterns violates the "Dependency Inversion Principle" this means "Depend upon abstractions. Do not depend upon concrete classes".</p>

<p>The example above violates the rules because DependentPizzaStore(high-level component) depend on concrete implementation of pizzas(low-level component).</p>

<p>to fix this we use factory method pattern.</p>

<pre><code>public abstract class PizzaStore {
  protected abstract Pizza createPizza(String item);
  public Pizza orderPizza(String type) {
    Pizza pizza = createPizza(type);
    System.out.println("--- Making a " + pizza.getName() + " ---");
    pizza.prepare();
    pizza.bake();
    pizza.cut();
    pizza.box();
    return pizza;
  }

  public class NYPizzaStore extends PizzaStore {
    protected Pizza createPizza(String item) {
      Pizza pizza = null;
      if (item.equals("cheese")) {
        pizza = new CheesePizza();
      } else if (item.equals("veggie")) {
        pizza = new VeggiePizza();
      }
      return pizza;
    }   
  }
</code></pre>

<p>now PizzaStore(high-level component) depends only on pizza abstraction of pizza concrete classes and also concrete pizzas depend on pizza abstraction because they extends to it.</p>

<p><strong>My question is did NYPizzaStore class also violates "Dependency Inversion Principle" because it depends on cheesePizza() and VeggiePizza() which is concrete implementation of pizza.</strong></p>
