0% found this document useful (0 votes)
2 views3 pages

Sample Question

The document discusses the development of a logistics management application that currently supports only truck transportation. It highlights the limitations of the existing code structure, which is heavily coupled to the Truck class, making it difficult to add new transportation methods like ships and planes. The document suggests the need for a design pattern to facilitate the integration of additional transportation types without extensive code modifications.

Uploaded by

raiyanahmed.720
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Sample Question

The document discusses the development of a logistics management application that currently supports only truck transportation. It highlights the limitations of the existing code structure, which is heavily coupled to the Truck class, making it difficult to add new transportation methods like ships and planes. The document suggests the need for a design pattern to facilitate the integration of additional transportation types without extensive code modifications.

Uploaded by

raiyanahmed.720
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Name: ID: Section:

Imagine that you’re creating a logistics management application. The first version of
your app can only handle transportation by trucks, so the bulk of your code lives
inside the Truck class. Currently your code-base looks like the following:

#include <iostream>

#include <string>

using namespace std;

// Interface Or Abstract class

class Transport

public:

virtual ~Transport() {}; // Destructor

virtual string Delivery() const = 0; // Operation

};

class Truck : public Transport

public:

string Delivery() const override

return "Truck will be delivering your product!";

};

class RoadLogistic

public:

virtual ~RoadLogistic() {};

virtual Transport *Transportation() const = 0; // virtual function


Name: ID: Section:

string Order() const

Transport *transport = this->Transportation();

string result = "Your goods and products are shipped now ----- \n" +

transport->Delivery();

return result;

};

class TruckLogistic : public RoadLogistic

public:

Transport *Transportation() const override

return new Truck();

};

void ClientCode(const RoadLogistic &logistic)

cout << "Don't worry about your products and the transportation\n"

<< logistic.Order() << endl;

int main()

RoadLogistic *logistic1 = new TruckLogistic();


Name: ID: Section:

ClientCode(*logistic1);

Current Output:

Don't worry about your products and the transportation

Your goods and products are shipped now -----

Truck will be delivering your product!

After a while, your app becomes pretty popular. Each day you receive dozens of requests
from sea and plane transportation companies to incorporate sea and air logistics into the app.

Great news, right? But how about the code? At present, most of your code is coupled to the
Truck class. Adding Ships and Plane into the app would require making changes to the entire
code-base. Moreover, if later you decide to add another type of transportation to the app, you
will probably need to make all of these changes again. Which design pattern can we use to
solve this problem and our progarm output will be looking like the following:

Expected Output:

Don't worry about your products and the transportation

Your goods and products are shipped now -----

Truck will be delivering your product!

----------------------------------

Don't worry about your products and the transportation

Your goods and products are shipped now -----

Ship will be delivering your product!

------------------------------------

Don't worry about your products and the transportation

Your goods and products are shipped now -----

Plan will be delivering your product!

--------------------------------------

You might also like