217k views
2 votes
Question 3: 20 Marks) Think of a scenario in which you are required to develop a software system for an insurance company. The main objective is that the clients should be able to get policy and the details of it. After completing the requirement analysis and design, the development team have concluded that initially the application should support creating three policy types such as motor insurance, health insurance and travel insurance. The management wishes the application to add more policy types in the future. 3.1 Suggest an appropriate architectural design pattern for the above scenario and describe 5 Marks how it works. 3.2 Illustrate your answer using appropriate diagrams (initial stage diagram/s and extended 10 Marks stage diagram/s] 3.3 Justify the reason for suggesting the design pattern for the scenario. 5 Marks

1 Answer

3 votes
3.1 Suggested Architectural Design Pattern: The appropriate architectural design pattern for the given scenario is the "Factory Method" pattern.

How it works:
- The Factory Method pattern provides an interface for creating objects, but the subclasses decide which class to instantiate.
- In this scenario, we can create a PolicyFactory interface that defines a method to create different policy types, and then implement this interface for each policy type (MotorInsurance, HealthInsurance, TravelInsurance).
- The client code will use the PolicyFactory to create instances of the policies without being aware of the specific implementation.

3.2 Diagrams:
a) Initial Stage Diagram:
```
+------------------+
| PolicyFactory |
+------------------+
| +createPolicy() |
+--------|---------+
/_\
|
+------------------+
| MotorInsurance |
+------------------+
| +getDescription()|
+------------------+

+------------------+
| HealthInsurance |
+------------------+
| +getDescription()|
+------------------+

+------------------+
| TravelInsurance |
+------------------+
| +getDescription()|
+------------------+
```

b) Extended Stage Diagram (After adding more policy types):
```
+------------------+
| PolicyFactory |
+------------------+
| +createPolicy() |
+--------|---------+
/_\
|
+------------------+
| MotorInsurance |
+------------------+
| +getDescription()|
+------------------+

+------------------+
| HealthInsurance |
+------------------+
| +getDescription()|
+------------------+

+------------------+
| TravelInsurance |
+------------------+
| +getDescription()|
+------------------+

+------------------+
| LifeInsurance |
+------------------+
| +getDescription()|
+------------------+

+------------------+
| HomeInsurance |
+------------------+
| +getDescription()|
+------------------+
```

3.3 Justification for suggesting the Factory Method pattern:
- In the given scenario, the requirement is to create different policy types and add more policy types in the future.
- The Factory Method pattern provides a flexible way to add new policy types without modifying existing client code.
- It promotes loose coupling between the client and the policy classes, making it easier to maintain and extend the application over time.
- By using the Factory Method pattern, the client code doesn't need to know the specific policy class implementations, allowing for better separation of concerns and scalability in the long run.

Hope this helps, Benny.
willkiddhill
User Jason Etheridge
by
8.1k points

No related questions found