Posts

Showing posts from July, 2018

Behavioral Patterns - Visitor Pattern Exercise

behavioral-patterns-visitor-pattern-exerciseThe 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 MaterialsUse 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 - titleadd 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 and the total count of media while the media is t…

Behavioral Patterns - Template Method Pattern Exercise

behavioral-patterns-template-method-pattern-exerciseThe 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 MaterialsUse 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)makeStartermakeEntrymakeDessert;afterFinish (hook)Make two concrete three-course dinners by using the Three-Course Dinner Template.Components:Abstract Class (The abstract class that defines the steps of algor…

Behavioral Patterns - Strategy Pattern Exercise

behavioral-patterns-strategy-pattern-exerciseThe 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 MaterialsUse the Strategy Pattern to create a Race Model that meets the following requirements:It defines the race traits which varies by each raceIt has the following two behaviors that could be considered strategies. DanceFightImplement at least 2 races with different behaviorsComponents:Context (The abstract class that defines the base of all races) - RaceConcrete Context (The implementations of the Race) - Human, Orc, TaurenStrategy (Different behavior interfaces) - DanceBehavior, FightBehavior.Concrete Strategy (The interchangeable strategie…