Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given 4 abstract classes, which are Leg, Arm, Body, and Head, as follows: class Leg { public: Leg() { cout < < Make Leg. <

Given 4 abstract classes, which are Leg, Arm, Body, and Head, as follows:

class Leg

{

public:

Leg()

{

cout << "Make Leg." << endl;

}

virtual void action() = 0;

};

////////////////////////////////////

class Arm

{

public:

Arm()

{

cout << "Make Arm." << endl;

}

virtual void action() = 0;

};

////////////////////////////////////

class Body

{

public:

Body()

{

cout << "Make Body." << endl;

}

virtual void action() = 0;

};

////////////////////////////////////

class Head

{

public:

Head()

{

cout << "Make Head." << endl;

}

virtual void action() = 0;

};

create concrete classes RobotLeg, RobotArm, RobotBody, and RobotHead. You can

override the action() function to do whatever you think is reasonable for a robot.

For example,

class RobotLeg: public Leg

{

public:

RobotLeg()

{

cout << "Make Robot Leg." << endl;

}

void action() { cout << Robot leg moves. << endl; }

};

Then create concrete classes AnimalLeg, AnimalArm, AnimalBody, and AnimalHead. You

can override the action() function to do whatever you think is reasonable for an animal.

Now use Abstract Factory design pattern to create an abstract class ToyFactory, a

concreate class RobotToyFactory, and a concrete class AnimalToyFactory class.

With the RobotToyFactory, clients can make RobotLeg objects, RobotArm objects,

RobotBody objects, and RobotHead objects.

With the AnimalToyFactory, clients can make AnimalLeg objects, AnimalArm objects,

AnimalBody objects, and AnimalHead objects.

Finally, create a client class, which contains a main() function, to build a Robot toy (with

leg, arm, body, head) and an Animal toy (with leg, arm, body, head).

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

Database In Depth Relational Theory For Practitioners

Authors: C.J. Date

1st Edition

0596100124, 978-0596100124

More Books

Students also viewed these Databases questions

Question

How is slaked lime powder prepared ?

Answered: 1 week ago

Question

Why does electric current flow through acid?

Answered: 1 week ago

Question

What is Taxonomy ?

Answered: 1 week ago

Question

1. In taxonomy which are the factors to be studied ?

Answered: 1 week ago