Skip to content

Design Pattern

SWE · Midterm · Fall 26

Paper 2 of 2Batch 43Switch

Batch 43

Paper 2 of 2

This browser can’t show the PDF here

Open it, and your phone’s PDF viewer takes it, or download it.

Read the questions as text

Read off the PDF by AI, so it may have mistakes. The PDF is the original.

Daffodil International University Faculty of Science & Information Technology Department of Software Engineering Mid Term Examination, Fall 2026 Course Code: SE311; Course Title: Design Pattern Sections & Teachers: NML(A,B,C,D), HBM(E,F,G,H), AAZ(I,J,K,L), MAB(M,N), AHR(O) Time: 1:30 Hrs. Marks: 25 Answer ALL Questions [The figures in the right margin indicate the full marks and corresponding course outcomes. All portions of each question must be answered sequentially.] 1. a) A university has two separate roles: a Teacher can conduct classes and evaluate students, while a Researcher can conduct research and publish papers. A special academic performs both teaching and research activities. Construct a Java code to represent this structure. Define the two roles separately, enable academic to perform all four activities, and create an Academic object to demonstrate them. [Marks-4] CLO-1 Level-3 1. b) Apply your knowledge of code smells and refactoring to complete the following tasks. For each case, write the smelly code first and then refactor the same code using the specified remedy, without changing its functionality. [Marks-8] i. Apply Inappropriate Naming and refactor the code using meaningful names. ii. Apply Large Class and refactor the code using Extract Class. iii. Apply Long Method and refactor the code using Replace Temp with Query. iv. Apply Black Sheep and refactor the code using Replace Inheritance with Composition. 1. c) Demonstrate key difference between runtime and compile time polymorphism [Marks-3] 2. a) A web application has a ConfigurationManager class that stores database settings and application configurations. Two threads call the getInstance() method at almost the same time during application startup. The developer notices that multiple configuration objects may be created, potentially causing inconsistent settings. The developer needs to implement a thread-safe to ensure both threads access the same configuration object. Finally, verify that both threads receive the same instance. [Marks- 1+1+3] CLO-2 Level-3 Now, you have to complete the following tasks: i. Identify the name of design pattern that ensures only one ConfigurationManager object is created. ii. Explain how two threads can create separate objects when they call the getInstance() method at nearly the same time. iii. Modify the getInstance() method to make it thread-safe, and write a complete Java program using two threads to verify that both threads receive the same object 2. b) A creative software company develops an AI story generation application named DreamHablu. Users can generate stories in three styles: Fantasy, Mystery, and ScienceFiction. Every story generator must implement the generateStory() method. The company wants to create story generators using a StoryFactory instead of directly instantiating concrete generator classes. The main application receives the selected style and requests an appropriate object from the factory. The returned object then generates a story using its own implementation. The application should use polymorphism to execute the correct method. The development team also wants to examine what happens if the factory receives a style that it does not support. [Marks- 3+1+1] Now, you have to complete the following tasks: i. Build the Java implementation of the Factory Pattern for story generation. ii. Determine the output when the user selects Mystery. iii. Examine why the main application does not need separate if-else statements for every story generator.