Sample Exam

Section 1: Matching Questions – Design Patterns (30 marks)

 

There are FIFTEEN QUESTIONS in this section, each worth TWO MARKS. In each question, you will be presented with a description of a design pattern, and you need to indicate which pattern it describes. For your reference, a list of the Gang of Four design patterns follows:

 

Abstract Factory Adapter Bridge
Builder Chain of Responsibility Command
Composite Decorator Façade
Factory Method Flyweight Interpreter
Iterator Mediator Memento
Observer Prototype Proxy
Singleton State Strategy
Template Method Visitor  

 

  1. Which design pattern is used to ensure that a class has only one instance and provides a global point of access to it?

 

  1. Which design pattern involves defining a family of interchangeable algorithms?
  2. Which design pattern can also be referred to as a publish-subscribe system?
  3. If you wanted to assign additional behaviours to an object WITHOUT making changes to that object’s class, which design pattern might be appropriate?
  4. Which design pattern is used to provide a simplified interface to a complex system of classes, libraries, or frameworks?
  5. If you have some domain knowledge that enables you to outline the skeleton of an algorithm, which design pattern would enable you to encode this knowledge?
  6. Which design pattern encapsulates the traversal behaviour for a collection of objects?
  7. Which design pattern most accurately reflects this pattern of behaviour: “I don’t know, but I can ask my manager.”
  8. If you would like to treat objects and collections of objects using the same interface, which design pattern should you employ?
  9. Which of the creational design patterns is most appropriate for facilitating the creation of a variety of complex objects?
  10. Which design pattern encapsulates object creation in such a way that objects can be created without calls to a specific constructor?
  11. Which design pattern is most closely associated with the clone() method?
  12. Which design pattern would you use if you wanted to apply access control to an object?
  13. Which design pattern is best described by the following: turn a function call into an object?
  14. If you can describe a family of problems with a “little language”, what design pattern might you employ to solve these problems?

 

 

Section 2: Multiple Choice – Code smells and refactoring (30 marks)

 

There are FIFTEEN QUESTIONS in this section, each worth TWO MARKS. Each question will be followed by FOUR CHOICES, of which only ONE is correct. Select only ONE response for each question.

 

Question 1: Which of the following best describes a code smell?

  1. a) An unpleasant odor emitted by malfunctioning hardware
    b) Indications of poor code design or implementation
    c) A metaphorical term used in code documentation
    d) The physical deterioration of code over time

Question 2: Which of the following is NOT considered a common code smell?

  1. a) Duplicated code
    b) Long parameter lists
    c) Consistent naming conventions
    d) Large classes or methods

Question 3: Refactoring is best described as…

  1. a) Rewriting an entire software system from scratch
    b) A process of making incremental improvements to code
    c) A technique for obfuscating code to protect intellectual property
    d) Debugging and fixing errors in existing code

Question 4: Which of the following is an example of a code smell related to duplication?

  1. a) Long methods or functions
    b) Consistent variable naming conventions
    c) Modular code with clear responsibilities
    d) Copy-pasting the same code in multiple places

Question 5: Which refactoring technique is used to break down large methods into smaller, more manageable ones?

  1. a) Extract Method
    b) Inline Method
    c) Rename Method
    d) Pull Up Method

Question 6: The code smell “long class” refers to

  1. a) A class that exceeds a certain line limit
    b) A class that lacks proper indentation
    c) A class with no instance variables or methods
    d) A class that has excessive dependencies on other classes

Question 7: What is the purpose of refactoring?

  1. a) To introduce bugs and errors into the code
    b) To add new features and functionality to the code
    c) To improve the internal structure and quality of the code
    d) To rewrite the code entirely for performance optimization

 

 

Question 8: Which refactoring technique is used to extract a group of related methods and fields into a new class?

  1. a) Extract Class
    b) Extract Interface
    c) Extract Superclass
    d) Extract Variable

Question 9: Which of the following is a code smell related to maintainability?

  1. a) Inconsistent naming conventions
    b) Adequate unit test coverage
    c) Utilizing design patterns effectively
    d) Utilizing the appropriate data structures

Question 10: Which code smell refers to a method or function that has too many parameters?

  1. a) Long method
    b) Feature envy
    c) Shotgun surgery
    d) Long parameter list

Question 11: Which code smell refers to duplicate or nearly identical code in different parts of the system?

  1. a) Shotgun surgery
    b) Duplicated code
    c) Long class
    d) Magic number

Question 12: Which refactoring technique aims to combine multiple methods into a single one?

  1. a) Extract Method
    b) Inline Method
    c) Extract Class
    d) Inline Class

Question 13: What is a code smell related to a class that has too many responsibilities or methods?

  1. a) Long parameter list
    b) Feature envy
    c) Shotgun surgery
    d) Large class

Question 14: Which code smell refers to the use of a constant value without a clear explanation or context?

  1. a) Magic number
    b) Shotgun surgery
    c) Data clumps
    d) Long method

Question 15: What code smell occurs when a class is dependent on too many other classes or modules?

  1. a) Divergent change
    b) Shotgun surgery
    c) Large class
    d) Feature envy

Section 3: Short Answer – Object oriented programming principles (30 marks)

 

Name (2 marks each) and define (3 marks each) the four core principles of object-oriented programming.

 

 

 

 

 

 

 

 

 

 

 

 

 

 

What are some benefits of object-oriented software design, compared to other software design methodologies? Use the four core principles to guide your discussion. (10 marks)

 

 

Section 4: Short Answer – Design Patterns (30 marks)

 

There are FIVE QUESTIONS in this section, each worth SIX MARKS. In each question, I will suggest to you a combination of two or more design patterns. In the space below, describe a situation in which you might use those design patterns in combination (2 marks), and briefly describe what role each pattern would play in solving that problem (2 marks each).

Question 1: Composite and Iterator

 

 

Question 2: Command and Memento

 

 

Question 3: Abstract Factory and Singleton

 

Question 4: State and Flyweight

 

 

Question 5: Observer and Mediator