visitor

package
v0.0.0-...-6db54d9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 15, 2021 License: MIT Imports: 0 Imported by: 0

README

Посетитель (Visitor)

Паттерн Visitor относится к поведенческим паттернам уровня объекта.

Паттерн Visitor позволяет обойти набор элементов (объектов) с разнородными интерфейсами, а также позволяет добавить новый метод в класс объекта, при этом, не изменяя сам класс этого объекта.

Требуется для реализации:

  1. Абстрактный класс Visitor, описывающий интерфейс визитера;
  2. Класс ConcreteVisitor, реализующий конкретного визитера. Реализует методы для обхода конкретного элемента;
  3. Класс ObjectStructure, реализующий структуру(коллекцию), в которой хранятся элементы для обхода;
  4. Абстрактный класс Element, реализующий интерфейс элементов структуры;
  5. Класс ElementA, реализующий элемент структуры;
  6. Класс ElementB, реализующий элемент структуры.

[!] В описании паттерна применяются общие понятия, такие как Класс, Объект, Абстрактный класс. Применимо к языку Go, это Пользовательский Тип, Значение этого Типа и Интерфейс. Также в языке Go за место общепринятого наследования используется агрегирование и встраивание.

-- THE END --

Documentation

Overview

Package visitor is an example of the Visitor Pattern.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BurgerBar

type BurgerBar struct {
}

BurgerBar implements the Place interface.

func (*BurgerBar) Accept

func (b *BurgerBar) Accept(v Visitor) string

Accept implementation.

func (*BurgerBar) BuyBurger

func (b *BurgerBar) BuyBurger() string

BuyBurger implementation.

type City

type City struct {
	// contains filtered or unexported fields
}

City implements a collection of places to visit.

func (*City) Accept

func (c *City) Accept(v Visitor) string

Accept implements a visit to all places in the city.

func (*City) Add

func (c *City) Add(p Place)

Add appends Place to the collection.

type People

type People struct {
}

People implements the Visitor interface.

func (*People) VisitBurgerBar

func (v *People) VisitBurgerBar(p *BurgerBar) string

VisitBurgerBar implements visit to BurgerBar.

func (*People) VisitPizzeria

func (v *People) VisitPizzeria(p *Pizzeria) string

VisitPizzeria implements visit to Pizzeria.

func (*People) VisitSushiBar

func (v *People) VisitSushiBar(p *SushiBar) string

VisitSushiBar implements visit to SushiBar.

type Pizzeria

type Pizzeria struct {
}

Pizzeria implements the Place interface.

func (*Pizzeria) Accept

func (p *Pizzeria) Accept(v Visitor) string

Accept implementation.

func (*Pizzeria) BuyPizza

func (p *Pizzeria) BuyPizza() string

BuyPizza implementation.

type Place

type Place interface {
	Accept(v Visitor) string
}

Place provides an interface for place that the visitor should visit.

type SushiBar

type SushiBar struct {
}

SushiBar implements the Place interface.

func (*SushiBar) Accept

func (s *SushiBar) Accept(v Visitor) string

Accept implementation.

func (*SushiBar) BuySushi

func (s *SushiBar) BuySushi() string

BuySushi implementation.

type Visitor

type Visitor interface {
	VisitSushiBar(p *SushiBar) string
	VisitPizzeria(p *Pizzeria) string
	VisitBurgerBar(p *BurgerBar) string
}

Visitor provides a visitor interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL