Examples of Classes and Methods

Suppose that there is an existing StringTransformer class and also the following:

     public interface StringTransformable {
         public String transform(String x);
     }

The following classes each extend StringTransformer and implement StringTransformable. Note especially:


     public class Capitalizer extends StringTransformer implements StringTransformable {
         public String transform(String thePhrase) {
             return thePhrase.toUpperCase();
         }
     }

     public class NameDropper extends StringTransformer implements StringTransformable {
	private String name;

	public NameDropper() {
		this.name = "Santa Claus";
	}

	public NameDropper(String name) {
		this.name = name;
	}

	public String transform(String thePhrase) {
		return this.name + " says " + thePhrase;
	}
     }