Java Web Hosting for Developers

Developing Applications with Java

THE VISITOR PATTERN The Visitor pattern turns the

Filed under: Design Patterns Java — webmaster @ 6:18 am

THE VISITOR PATTERN The Visitor pattern turns the tables on our object-oriented model and creates an external class to act on data in other classes. This is useful if there are a fair number of instances of a small number of classes and you want to perform some operation that involves all or most of them. Motivation While at first it may seem unclean to put operations that should be inside a class in another class instead, there are good reasons for doing it. Suppose each of a number of drawing object classes has similar code for drawing itself. The drawing methods may be different, but they probably all use underlying utility functions that we might have to duplicate in each class. Further, a set of closely related functions is scattered throughout a number of different classes as shown below: drawObject Circle draw Triangle draw Rectangle draw Instead, we write a Visitor class which contains all the related draw methods and have it visit each of the objects in succession:

Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java 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