Decorator
This is the class that will be "decorated".
The functionality of one of these objects (not the
class itself) will be extended through the use of a
decorator object.
-----------------------------------------------------
class Person{
public void makeStatement(String statement){
System.out.println(statement);
}
}
-----------------------------------------------------
The decorator class.
NOTE: I believe that the decorator should
not take a person as a constructor arg but have a
setPerson function. This would enable one decorator
object to "decorate" or extend multiple person objects.
-----------------------------------------------------
class RelativistDecorator{
private Person person;
public RelativistDecorator(Person person){
this.person = person;
}
public void makeStatement(String statement){
person.makeStatement("In my opinion "
+ statement);
}
}
-----------------------------------------------------
A test stub to demonstrate the decorator in use.
-----------------------------------------------------
class Test{
public static void main(String[] args){
System.out.println("class: Test, method: main");
String statement = "time alone is good";
Person person = new Person();
person.makeStatement(statement);
new RelativistDecorator(person).makeStatement(statement);
}
}
-----------------------------------------------------
Here is a tar with the above java classes in it.
decorator.tar