package ch8_general_programming;

import java.util.*;

public class item_52_refer_to_objects_by_interface {

    // We have a method that consumes a Collection
    static void consumeCollection(Collection<String> list) {
        for(String s : list) {
            System.out.println("...processing : " + s);
        }
    }
    // We have an inferior method that consumes an ArrayList
    // Note that this method takes an ArrayList, but doesn't need any implementation specific to an ArrayList
    // This method could easily accept any type of Collection to do the same operation
    static void consumeCollectionBadly(ArrayList<String> list) {
        for(String s : list) {
            System.out.println("...processing : " + s);
        }
    }

    public static void main(String[] args) {
        //Lets build a few different types of collections
        ArrayList<String> arrayList = new ArrayList<String>();
        arrayList.add("Foo");
        arrayList.add("Bar");
        arrayList.add("Baz");
        arrayList.add("Qux");
        arrayList.add(1, "Foo");

        Stack<String> stack = new Stack<String>();
        stack.push("Foo");
        stack.push("Bar");
        stack.push("Baz");
        stack.push("Qux");
        stack.push("Foo");

        HashSet<String> hashSet = new HashSet<String>();
        hashSet.add("Foo");
        hashSet.add("Bar");
        hashSet.add("Baz");
        hashSet.add("Qux");
        hashSet.add("Foo");

        // If we try using our inferior method on each collection, we would have to cast each collection
        System.out.println("***Processing ArrayList with consumeCollectionBadly");
        consumeCollectionBadly(arrayList);

        // Using our superior method, we can be flexible in how we build collections to give to the method
        System.out.println("***Processing ArrayList with consumeCollection");
        consumeCollection(arrayList);
        System.out.println("***Processing Stack with consumeCollectionBadly");
        consumeCollection(stack);
        System.out.println("***Processing HashSet with consumeCollectionBadly");
        consumeCollection(hashSet);
    }
}
@@ -154,24 +154,38 @@
 a Collection
+ and prints it
 %0D%0A    static
@@ -207,16 +207,24 @@
 llection
+AndPrint
 (Collect
@@ -403,32 +403,46 @@
 mes an ArrayList
+ and prints it
 %0D%0A    // Note th
@@ -664,16 +664,24 @@
 ionBadly
+AndPrint
 (ArrayLi
@@ -1637,24 +1637,40 @@
 h collection
+ to an ArrayList
 %0D%0A        Sy
@@ -1773,16 +1773,24 @@
 ionBadly
+AndPrint
 (arrayLi
@@ -2009,16 +2009,24 @@
 llection
+AndPrint
 (arrayLi
@@ -2136,16 +2136,24 @@
 llection
+AndPrint
 (stack);
@@ -2228,32 +2228,32 @@
 ectionBadly%22);%0D%0A
-
         consumeC
@@ -2261,16 +2261,24 @@
 llection
+AndPrint
 (hashSet

Refactor method names and improve comments