preview

Cs / 6310 Assignment 1 Assignment Two Design Patterns

Decent Essays

Alan Caulkins

CS-6310, Assignment #9

11/13/2017

Part 1: For this assignment, two design patterns will be covered: Observer and Visitor.

Pattern #1, Observer:

This design pattern provides a mechanism for one-to-many communication

between an entity acting as an information source, called the “subject”, and any number

of receiving entities, called “observers”. The pattern is also known by the the more

descriptive name “publish-subscribe”. The advantage of this pattern is that the developer

of the subject doesn’t need to know what or how many observers will be used ahead of

time. The number of observers can be determined at run time, or at a time well after the

subject has been written. This pattern allows observing entities to be added without

coupling them to the subject or requiring the author of the subject to know about them

ahead of time. The pattern is useful in situations where a (possibly unknown) number of

independent aspects of a system depend simultaneously on an object and need to be

informed of changes to it.

Pattern #2, Visitor:

This design pattern provides a mechanism for executing different operations on

nodes in a data structure, determined by node type or class. The advantage of this pattern

is that the operations don’t have to be known to the nodes, and the node classes are not

coupled to the operations. The Visitor class contains the different versions of a given

operation for all of the node types and an arbitrary number

Get Access