Free Ultimate Design Pattern Question and Answers — Questions and Answers
Question 1: In a communication diagram, the sequence number is always followed immediately by a(n) _______.
- Colon (Correct answer)
- Dash
- equal sign
- Semicolon
Correct answer: Colon
In a communication diagram (formerly collaboration diagram), the sequence number indicates the order of messages in an interaction. A colon always immediately follows the sequence number to separate it from the message name and arguments, for example, '1: messageName()'.
Question 2: Which of the following pertains to a view layer class's duties?
- Process all business rules with appropriate logic
- Prepare persistent classes for storage to the database
- Display electronic forms and reports (Correct answer)
- Establish and maintain connections to the database
Correct answer: Display electronic forms and reports
The view layer, also known as the presentation layer, is responsible for all aspects of user interaction. Its primary duties include displaying electronic forms, reports, and other visual elements to the user, as well as capturing user input. It acts as the interface between the user and the application's underlying logic.
Question 3: Which of the following is a domain layer class's duty?
- Establish and maintain connections to the database
- Capture input events such as clicks, rollovers, and key entry
- Process all business rules with appropriate logic (Correct answer)
- Display electronic forms and reports
Correct answer: Process all business rules with appropriate logic
The domain layer, or business logic layer, is where the core business rules and logic of an application reside. Its primary duty is to process all business rules with appropriate logic, ensuring that the application behaves correctly according to the defined requirements. It encapsulates the 'what' and 'how' of the business operations.
Question 4: Which of the following pertains to a data access layer class's duties?
- Process all business rules with appropriate logic
- Disconnect gracefully from the database (Correct answer)
- Accept input data
- Create problem domain (persistent) classes
Correct answer: Disconnect gracefully from the database
The data access layer is responsible for interacting with the persistent storage, typically a database. Its duties include establishing and maintaining connections to the database, performing CRUD (Create, Read, Update, Delete) operations, and gracefully disconnecting from the database to manage resources efficiently.
Question 5: Retrieve and update attribute values using ___ methods.
- Get and set (Correct answer)
- Constructor
- Data
- Overloaded
Correct answer: Get and set
In object-oriented programming, 'get' (accessor) methods are used to retrieve the value of an attribute, while 'set' (mutator) methods are used to update its value. These methods provide controlled access to an object's internal state, adhering to the principle of encapsulation.
Question 6: A behavioral object-level pattern is the ___ pattern.
- Bridge
- Singleton
- Strategy (Correct answer)
- Proxy
Correct answer: Strategy
The Strategy pattern is a behavioral design pattern that defines a family of algorithms, encapsulates each one, and makes them interchangeable. It is an object-level pattern because it deals with how objects interact and behave, allowing clients to choose an algorithm from a family of algorithms at runtime.
Question 7: It is a ___ pattern, the prototype pattern.
- behavioral object-level
- creational class-level
- structural class-level
- creational object-level (Correct answer)
Correct answer: creational object-level
The Prototype pattern is a creational pattern because its primary purpose is to create new objects. It is an object-level pattern because it creates new objects by cloning existing instances (prototypes), rather than relying on class-level instantiation methods. This allows for dynamic object creation based on existing objects.
In a communication diagram, the sequence number is always followed immediately by a(n) _______.