Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!