1.
What is the reason for studying design pattern?
Correct Answer
D. All of the above
Explanation
Studying design patterns is important because they allow for the reuse of solutions, saving time and effort in the development process. Additionally, patterns help with communication between analysts by providing a common language and understanding of design concepts. Furthermore, patterns give a broader perspective on problem-solving, allowing for more effective and efficient solutions. Therefore, all of the given reasons are valid explanations for studying design patterns.
2.
Patterns are the devices that allow programs to share knowledge about their ___
Correct Answer
B. Design
Explanation
Patterns are the devices that allow programs to share knowledge about their design. Design patterns provide solutions to common design problems and enable programmers to create reusable and maintainable code. By using design patterns, programmers can leverage existing knowledge and best practices to improve the overall quality and efficiency of their software designs.
3.
Which of the following are among ten things, which the basic templates of GoF design pattern include?
Correct Answer
D. All of the above
Explanation
The correct answer is "All of the above" because the basic templates of GoF design patterns include problem, context, and forces. These three elements are essential in understanding and applying design patterns effectively. The problem refers to the specific issue or challenge that the design pattern aims to solve. The context provides the background and environment in which the problem exists. The forces are the constraints and considerations that influence the design decisions. Therefore, all three elements are necessary components of the basic templates of GoF design patterns.
4.
-
Which are NOT the possible errors of using design patterns?
Correct Answer
B. Cohesion
Explanation
The possible errors of using design patterns include superficiality, fit, and misdiagnosis. However, cohesion is not considered an error when using design patterns. Cohesion refers to the degree to which the elements within a module or class belong together and work together towards a common goal. It is a desirable quality in software design and not considered an error.
5.
Design patterns have to be object oriented?
Correct Answer
B. False
Explanation
Design patterns do not have to be object-oriented. While many design patterns are commonly used in object-oriented programming, there are also design patterns that can be applied in other programming paradigms such as functional programming or procedural programming. Design patterns are general reusable solutions to common problems in software design, and they can be adapted and used in various programming paradigms depending on the specific problem at hand.
6.
Design patterns enables ____ reuse
Correct Answer
A. Design
Explanation
Design patterns enable code reuse.
7.
-
Which of following patterns is not used to create an object?
Correct Answer
B. Strategy
Explanation
The Strategy pattern is not used to create an object. The Strategy pattern is a behavioral design pattern that allows selecting an algorithm at runtime. It defines a family of algorithms, encapsulates each one, and makes them interchangeable. It is used to provide different strategies for solving a problem. However, it does not involve the creation of objects itself.
8.
Which design pattern is also called anti pattern?
Correct Answer
B. Singleton
Explanation
The Singleton design pattern is often referred to as an anti-pattern because it can introduce global state and tightly couple different parts of the codebase. It can make the code harder to test, maintain, and extend. The use of a Singleton can also hinder parallelism and make it difficult to achieve proper separation of concerns. Therefore, while the Singleton pattern can be useful in certain scenarios, it is generally considered an anti-pattern due to its potential drawbacks.
9.
What is the key strategy in the Abstract factory?
Correct Answer
D. All of the above
Explanation
The key strategy in the Abstract factory is to implement all of the given options. "Find what varies and encapsulate it" refers to identifying the varying parts of an object and encapsulating them into separate classes. "Favour aggregation over inheritance" suggests using composition and object aggregation instead of relying solely on inheritance. "Design to interfaces, not to implementations" emphasizes programming to interfaces rather than concrete implementations, allowing for flexibility and interchangeability. Implementing all of these strategies helps in creating a flexible and maintainable codebase.
10.
-
What is the factory implementation in C#?
Correct Answer
B. GetEnumerator()
Explanation
The GetEnumerator() method is the factory implementation in C#. This method is used to create and return an enumerator object, which allows for iterating over a collection of objects. It is commonly used in conjunction with the foreach loop to iterate through elements in a collection. The other options (GetObject(), GetType(), and None of the above) are not related to factory implementation in C#.