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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started