/*==========================================================*/
/*  Univerally Accessible Method Demo                       */
/*  Author: Bary W Pollack                                  */
/*  File: UniversalDemo.java                                */
/*  Last Modified: Aug. 16, 2008                            */
/*                                                          */
/*  How to create a method that is accessible by everyone,  */
/*  everywhere. It can do anything it needs to do...        */
/*==========================================================*/

/**
 *    Main driver
 */
public class UniversalDemo {

    UniversalDemo() {
        System.out.println("\nShow how to set up a 'universally-accessible' method\n");
        System.out.println("First call, the counter is " + Universal.universalMethod());
        System.out.println("Second call, the counter is " + Universal.universalMethod());
        SomeClass someClass = new SomeClass();
        someClass.increment();
    }

    public static void main(String[] args) {
        new UniversalDemo();
        System.out.println("At the end, the counter is " + Universal.universalMethod());
        System.out.println();
    }

}


/**
 *    This class contains the "universally accesible method"
 */
class Universal {

    private static int counter = 0;

    // This method is accessible from *anywhere* / *everywhere*
    public static int universalMethod() {
        return ++counter;
    }

}


/**
 *    Here's a class that uses universalMethod()
 */
class SomeClass {

    SomeClass() {
        System.out.println("SomeClass Constructor; the counter is " + Universal.universalMethod());
    }

    void increment() {
        System.out.println("increment(), the counter is " + Universal.universalMethod());
    }

}
    