Java Reference
In-Depth Information
51.
52. public void addProjectItem(ProjectItem element){
53. if (!projectItems.contains(element)){
54. projectItems.add(element);
55. }
56. }
57.
58. public void removeProjectItem(ProjectItem element){
59. projectItems.remove(element);
60. }
61.
62. public String toString(){
63. return name;
64. }
65. }
The Chain of Responsibility behavior is manifested in the getOwner and getDetails methods of Task . For
getOwner , a Task will either return its internally referenced owner (if non-null), or that of its parent. If the parent
was a Task and its owner was null as well, the method call is passed on to the next parent until it eventually
encounters a non-null owner or it reaches the Project itself. This makes it easy to set up a group of Tasks where
the same individual is the designated owner, responsible for the completion of a Task and all sub Tasks .
The getDetails method is another example of Chain of Responsibility behavior, but it behaves somewhat
differently. It calls the getDetails method of each parent until it reaches a Task or Project that is identified as
a terminal node. This means that getDetails returns a series of Strings representing all the details for a
particular Task chain.
 
Search WWH ::




Custom Search