Java Web Hosting for Developers

Developing Applications with Java

drawObject Rectangle Circle Triangle draw The question that

Filed under: Design Patterns Java — webmaster @ 5:34 pm

drawObject Rectangle Circle Triangle draw The question that most people who first review this pattern ask is what does visiting mean? There is only one way that an outside class can gain access to another class, and that is by calling its public methods. In the Visitor case, visiting each class means that you are calling a method already installed for this purpose, called accept. The accept method has one argument: the instance of the visitor, and in return, it calls the visit method of the Visitor, passing itself as an argument. visited.accept(this); Visited Visitor v.visit(this); instance Putting it in simple code terms, every object that you want to visit must have the following method: public void accept(Visitor v) { v.visit(this); //call visitor method } In this way, the Visitor object receives a reference to each of the instances, one by one, and can then call its public methods to obtain data, perform calculations, generate reports, or just draw the object on the screen. When to Use the Visitor Pattern You should consider using a Visitor pattern when you want to perform an operation on the data contained in a number of objects that have

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