Java Web Hosting for Developers

Developing Applications with Java

total_days += emp.getVacDays(); } } Note that while

Filed under: Design Patterns Java — webmaster @ 2:15 pm

total_days += emp.getVacDays(); } } Note that while in this case Boss is derived from Employee, it need not be related at all as long as it has an accept method for the Visitor class. It is quite important, however, that you implement a visit method in the Visitor for every class you will be visiting and not count on inheriting this behavior, since the visit method from the parent class is an Employee rather than a Boss visit method. Likewise, each of your derived classes (Boss, Employee, etc. must have its own accept method rather than calling one in its parent class. Bosses are Employees, too We show below a simple application that carries out both Employee visits and Boss visits on the collection of Employees and Bosses. The original VacationVisitor will just treat Bosses as Employees and get only their ordinary vacation data. The bVacationVisitor will get both. VacationVisitor vac = new VacationVisitor(); bVacationVisitor bvac = new bVacationVisitor(); for (int i = 0; i < employees.length; i++) { employees[i].accept(vac); employees[i].accept(bvac); } total.setText(new Integer(vac.getTotalDays()).toString()); btotal.setText( new Integer(bvac.getTotalDays()).toString()); The two lines of displayed data represent the two sums that are computed when the user clicks on the Vacations button.

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Tomcat Web Hosting services

No Comments

No comments yet.

RSS feed for comments on this post. TrackBack URI

Sorry, the comment form is closed at this time.

Powered by Java Web Hosting