182k views
2 votes
"South West Car Wash Company" is deciding to automate its services billing system. Currently the company is providing services of

Exterior Wash Rinse
Triple Poly Shine Wax
Underbody Spray
Car Dry (Hand Dry and Interior vacuum)
Window cleaning
Mats and upholstery cleaning.

Triple Poly Shine Wax contains mixture of three waxes; Gold class Liquied Wax, Ultrashine Wax and Sentitized Wax , with the cost of 20$, 15$, 18$ respectively. Client can demand the combination of all three waxes or he can combine any two.
Underbody Spray costs $15, Window cleaning $10, Mats and upholstery cleaning $14. For Car Dry service, Hand dry has $12 OR client can get drying service of Interior Vaccume at $13 (Any one at a time).
If a client wants and Exterior Wash then extra cost of soap $2 needs to be added for each exterior wash, otherwise client can simple avail the Rinse service having cost $5.
You have to provide a software solution in which total costs of availed services can be calculated.
a. Apply "Bridge Pattern on above scenario. Draw its structure.
b. Give Jave code (Hand written) of your designed structure.

1 Answer

1 vote

Final answer:

The Bridge pattern is a design pattern that decouples an abstraction from its implementation, allowing the two to vary independently. In the scenario of automating the billing system for South West Car Wash Company, we can apply the Bridge pattern to separate the services provided by the company from the way those services are billed. The Bridge pattern structure consists of an Abstraction, Refined Abstraction, Implementor, and Concrete Implementor. Java code examples are provided to illustrate the implementation of the Bridge pattern.

Step-by-step explanation:

Bridge Pattern Structure:

The Bridge pattern is a design pattern that decouples an abstraction from its implementation, allowing the two to vary independently. In the scenario of automating the billing system for South West Car Wash Company, we can apply the Bridge pattern to separate the services provided by the company from the way those services are billed.

Bridge Pattern Structure:

  1. Abstraction: Represents the interface that clients use to interact with the services. In this case, it could be an interface called 'CarWashService'.
  2. Refined Abstraction: Implements the Abstraction interface and acts as a wrapper for the concrete implementations. It could be a class called 'BasicCarWashService'.
  3. Implementor: Defines the interface for the service implementations. It could be an interface called 'ServiceImplementation'.
  4. Concrete Implementor: Implements the Implementor interface and provides the actual implementation for different services. Examples could be classes like 'ExteriorWashRinse', 'TriplePolyShineWax', 'UnderbodySpray', etc.

Javacode:

CarWashService.java:

public interface CarWashService {
void calculateCost();
}

BasicCarWashService.java:

public class BasicCarWashService implements CarWashService {
private ServiceImplementation serviceImplementation;

public BasicCarWashService(ServiceImplementation serviceImplementation) {
this.serviceImplementation = serviceImplementation;
}

public void calculateCost() {
serviceImplementation.calculateCost();
}
}

ServiceImplementation.java:

public interface ServiceImplementation {
void calculateCost();
}

ExteriorWashRinse.java:

public class ExteriorWashRinse implements ServiceImplementation {
public void calculateCost() {
// Calculate cost for exterior wash and rinse service
}
}

TriplePolyShineWax.java:

public class TriplePolyShineWax implements ServiceImplementation {
public void calculateCost() {
// Calculate cost for Triple Poly Shine Wax service
}
}

UnderbodySpray.java:

public class UnderbodySpray implements ServiceImplementation {
public void calculateCost() {
// Calculate cost for underbody spray service
}
}

Similarly, you can create classes for other services like window cleaning, mats and upholstery cleaning, hand dry, etc.

User Shreyas Jadhav
by
9.0k points