Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Recall that we used the example of a bunch of superheroes in the last session on Creational design patterns. Let's take the same example here

Recall that we used the example of a bunch of superheroes in the last session on Creational design patterns. Let's take the same example here and try to create a Bridge pattern considering the following scenario:
Lets consider 2 superheroes for now: The Magician and Avon The Slayer. There are 3 functions that will be done by these two - Appear, Attack and Retreat. There will be 2 types of actions for each of the superheroes - AvonAction and TheMagicianAction.
There will be 3 pre-actions: onActivate, apply and onDeactivate. These 3 pre-actions will be defined for the Superhero Action class. These 3 pre-actions will define when the superhero will perfom his/her action.
You can refer the following steps to create the solution for the problem:
1. Create an interface which declares the 3 superhero actions
2. Create 2 classes: The Magician and Avon the Slayer which defines all 3 actions declared in the Revenger interface
3. Create the interface class for the Superhero Action which will declare the 3 pre-actions
4. Create the implementation of the 3 pre-actions for both the superheroes
5. Write the client code for the 3 actions
Create 2 hierarchies of the superheroes and the impact of their actions, and subsequently make appropriate function calls such that the console output looks like this-
The Magician receives a call from the victim.
The Magician has appeared from nowhere! (on calling the appear function/method)
The Magician is in action. (on calling the appear function/method which calls the onActivate function)
The Magician flies and punches the villain in the face. (on calling the attack function/method)
The punch from The Magician goes through the face of the villain and paralyzes the villain. (on calling the attack function/method which calls the apply function)
The Magician disappears. (on calling the retreat function/method)
The Magician prepares for her next attack. (on calling the retreat function/method which calls the onDeactivate function)
Avon the Slayer is being called.
Avon The Slayer has appeared from nowhere! (on calling the appear function/method)
Avon The Slayer is in action. (on calling the appear function/method which calls the onActivate function)
Avon the Slayer swings his sword swiftly to attack the villain. (on calling the attack function/method)
Avon's sword is deadly and cuts of the villain's arm. (on calling the attack function/method which calls the apply function)
Avon The Slayer disappears. (on calling the retreat function/method)
Avon the Slayer prepares for his next attack. (on calling the retreat function/method which calls the onDeactivate function)
Note: The action of the superhero and the impact of the action are to be separated using the concepts of the Bridge pattern.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beginning VB 2008 Databases

Authors: Vidya Vrat Agarwal, James Huddleston

1st Edition

1590599470, 978-1590599471

More Books

Students also viewed these Databases questions

Question

Describe the difference between a swap broker and a swap dealer.

Answered: 1 week ago

Question

=+1. I would not have honored the patients request.

Answered: 1 week ago

Question

What are the outcomes the client wants?

Answered: 1 week ago

Question

What has been done before?

Answered: 1 week ago