Code Monkey home page Code Monkey logo

visitor-pattern-java's Introduction

Visitor-Pattern-Java

Loyola University Chicago

COMP 373/473 - Objects/Frameworks/Patterns

Spring 2016 - Project 4 Visitor Pattern

The purpose of the visitor pattern is to represent an operation to be executed on elements of an object structure while allowing the programmer to define new operations without having to change the classes that interact with the elements. In this example, there are two kinds of items to buy (Fruit and Book), which represent concrete elements. These two concrete elements implement an Accept operation with an input parameter of the ShoppingCartVisitor. The classes, along with the Item element interface, form the ObjectStructure that can iterate through a collection of items and allows the visitor to visit its elements. The ShoppingCartVisitor is a visitor interface that declares a visit operation for each concrete element in the object. structure. The visitor interface is implemented in ShoppingCartVisitorImpl, which implements the visit operation on each concrete element and returns the cost of that particular item. The visitor pattern is useful for this example because it creates a data model and separates it from the visitor that performs operations upon the data. This separation allows for the program to easily be expanded to allow for other operations on the same concrete elements. Other than calculating the total cost in a customer's shopping cart, another visitor could assist with store inventory.

Run main method in

src/main/java/VisitorPattern

Run tests in

src/test/java/VisitorPatternTest

Resources:

visitor-pattern-java's People

Contributors

csoulakian avatar

Watchers

James Cloos avatar Farhad Nasimi avatar  avatar

Forkers

dnarasi1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.