Visitor Design Pattern Tutorial with Java Coding Example for Beginners | Visitor Pattern Explained

Поділитися
Вставка
  • Опубліковано 24 тра 2024
  • Visitor design pattern is a behavioral design pattern. Visitor design pattern lets you separate algorithms from the objects on which they operate. With the help of visitor pattern, we can move the operational logic from the objects to another class. As per the pattern, element object has to accept the visitor object so that visitor object handles the operation on the element object.
    We use a visitor class which changes the executing algorithm of an element class and execution algorithm of element can vary as and when visitor varies. It is a way of separating the algorithm (logic) from the current data structure.
    The Visitor pattern suggests that you place the new behaviour into a separate class called visitor, instead of trying to integrate it into existing classes. The original object that had to perform the behavior is now passed to one of the visitor’s methods as an argument, providing the method access to all necessary data contained within the object.
    ** Problem and Solution **
    The most common example of visitor pattern is shopping in the supermarket. In the supermarket, we pick the goods and add them to our cart. When we collect all the necessary goods to the cart, we go to the bill desk for billing. The cashier checks all the goods picked by us and tells us the total amount; we have to pay. Here, the cashier acts as a visitor on our cart to calculate the total cost. Helper in stores could be another example of visitor for our cart who helps dragging the shopping cart from store to my car.
    ** Where to use Visitor Design Pattern **
    1. Use visitor design pattern whenever we have to perform an operation on a group of similar kind of Objects.
    2. Use visitor design pattern whenever you need to perform an operation on all elements of a complex object structure (for example, an object tree).
    3. Use visitor design pattern whenever you want to clean up the business logic of auxiliary behaviors.
    4. Use visitor design pattern whenever a behavior makes sense only in some classes of a class hierarchy, but not in others.
    ** Advantages of Visitor Design Pattern **
    1. Supports Open/Closed Principle. You can introduce a new behavior that can work with objects of different classes without changing these classes.
    2. Supports Single Responsibility Principle. You can move multiple versions of the same behavior into the same class.
    3. A visitor object can accumulate some useful information while working with various objects. This might be handy when you want to traverse some complex object structure, such as an object tree, and apply the visitor to each object of this structure.
    4. If the logic of operation changes, then we need to make changes only in the visitor implementation.
    ** Chapter Timestamps **
    0:00 Welcome to Visitor Design Pattern
    0:23 Recap of Template Method Design Pattern
    1:29 Introduction to Visitor Design Pattern
    2:28 Real world example of Visitor Design Pattern
    3:28 Java coding example of Visitor Design Pattern
    8:57 Usage of Visitor Design Pattern
    9:32 Advantages of Visitor Design Pattern
    10:18 Summary of Visitor Design Pattern
    #visitorpattern #visitordesignpattern #javadesignpatterns
    ** Previous Video Links **
    Template Method Design Pattern • Template Method Design...
    ** GITHUB Project **
    github.com/codeonedigest/java...
    ** CHECK OUT OUR OTHER VIDEOS **
    Spring boot project setup: • Spring boot Project St...
    Spring Boot Microservice with postgres database Project: • Spring Boot Microservi...
    Prepare Docker file, Container and Build Image: • Docker Tutorial for Be...
    Deploy Docker Image AWS Elastic Container Service: • Deploy Springboot Micr...
    Run MongoDB in Docker Container: • Run MongoDB Image in D...
    ** CHECK OUR PLAYLISTS **
    Java Design Pattern Complete Tutorial • Java Design Patterns f...
    Spring Boot Complete Tutorial • Spring Boot Tutorial w...
    Docker Containers Complete Tutorial
    • Cloud & Container Tuto...
    ** ABOUT OUR CHANNEL **
    CodeOneDigest is a youtube channel that produces videos on programming languages, cloud and container technologies, Software design principles, Java frameworks in English and Hindi languages.
    Check out our channel here:
    / @codeonedigest
    Don’t forget to subscribe!
    ** OUR WEBSITE **
    codeonedigest.wordpress.com/
    ** GET IN TOUCH **
    Email us on codeonedigest@gmail.com
    FOLLOW US ON SOCIAL - LIKE, SHARE & SUBSCRIBE
    UA-cam: / @codeonedigest
    Twitter: / codeonedigest
    Facebook: / codeonedigest
    Linkedin: / codeone-digest-10b418255
    Github: github.com/codeonedigest
    Website: codeonedigest.wordpress.com/
    Tumblr: www.tumblr.com/codeonedigest
  • Наука та технологія

КОМЕНТАРІ • 4

  • @morrismanganhe1113
    @morrismanganhe1113 Місяць тому +1

    Simplest Explanation!

    • @codeonedigest
      @codeonedigest  17 днів тому +1

      Glad it was helpful! thanks for your valuable feedback. Do like share & subscribe our channel to grow codeonedigest channel.

  • @manikandan027
    @manikandan027 3 місяці тому +1

    Excellent

    • @codeonedigest
      @codeonedigest  3 місяці тому

      Thanks for your valuable feedback. Do like share and subscribe our channel to grow codeonedigest family