Posts

Showing posts from July, 2018

Behavioral Patterns - Visitor Pattern Exercise

behavioral-patterns-visitor-pattern-exercise The Visitor Pattern represents an operation to be performed on elements of an object structure. Visitor lets you define a new operation without changing the classes of the elements on which it operates. In this exercise, we will create a bookstore inventory structure that collects books, movies, and music. We will add shared behaviors across this hierarchical structure by using the Visitor Pattern. Reading Materials https://en.wikipedia.org/wiki/Visitor_pattern (15 minutes reading) Practice Materials Use the Visitor Pattern to create a bookstore inventory that meets the following requirements: the bookstore inventory collects books , movies , and music . all these three media types have their own members and one common member - title add one behavior to the media so that the operation can print out all the titles. add second behavior to the media so that the operation can print out details of all media an

Behavioral Patterns - Template Method Pattern Exercise

behavioral-patterns-template-method-pattern-exercise The Template Method Pattern defines the skeleton of an algorithm in a method, deferring some steps to subclasses. Template Method lets subclasses redefine certain steps of an algorithm without changing the algorithm’s structure. In this exercise, we will use the Template Method Pattern to create a Three Course Dinner Template for training restaurant staff for preparing the meal. Reading Materials https://en.wikipedia.org/wiki/Template_method_pattern (10 minutes reading) Practice Materials Use the Template Method Pattern to create a Three-Course Dinner Template that meets the following requirements: It defines a set of steps in the following order: beforeStart (hook) serveBeverage (optional) makeBeverage (only if serveBeverage is true) makeStarter makeEntry makeDessert ; afterFinish (hook) Make two concrete three-course dinners by using the Three-Course Dinner Template. Components:

Behavioral Patterns - Strategy Pattern Exercise

behavioral-patterns-strategy-pattern-exercise The Strategy Pattern defines a family of algorithms, encapsulates each one, and makes them interchangeable. Strategy lets the algorithm vary independently from clients that use it. In this exercise, we will use the Strategy Pattern to create a simplified Race model from the popular game World of Warcraft . Reading Materials https://en.wikipedia.org/wiki/Strategy_pattern (15 minutes reading) Practice Materials Use the Strategy Pattern to create a Race Model that meets the following requirements: It defines the race traits which varies by each race It has the following two behaviors that could be considered strategies. Dance Fight Implement at least 2 races with different behaviors Components: Context (The abstract class that defines the base of all races) - Race Concrete Context (The implementations of the Race) - Human , Orc , Tauren Strategy (Different behavior interfaces) - DanceBehavior ,