Adapter Pattern — Concept Check
Questions on Adapter Pattern. Converts the interface of a class into another interface clients expect, enabling incompatible interfaces to work together.
Questions in this quiz
8 questions on Adapter Pattern — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer needs to integrate a third-party payment SDK with their existing PaymentGateway interface. Which design pattern should they use to ensure compatibility?
- AFactory Pattern
- BObserver Pattern
- CSingleton Pattern
- DAdapter Pattern
2.You are using the Adapter Pattern to integrate a third-party library with your application. What is a common approach in Java for implementing this pattern?
- AModifying the Adaptee's source code
- BUsing multiple inheritance
- CUsing composition to wrap the Adaptee
- DDirectly implementing the Adaptee's methods
3.A service uses the Adapter Pattern to integrate with a legacy XML API. What might be a reason for choosing this pattern?
- ATo convert XML data to JSON format
- BTo replace the legacy API with a new one
- CTo improve the performance of the API
- DTo directly modify the legacy API
4.A developer claims that using the Class Adapter pattern in Java allows for more flexibility than the Object Adapter. Why might this be incorrect?
- AJava does not support multiple inheritance for classes
- BJava interfaces cannot be adapted
- CClass Adapter is more efficient
- DClass Adapter requires less code
5.What is a potential drawback of using the Class Adapter pattern in languages that support multiple inheritance?
- AIt limits flexibility by tightly coupling to the Adaptee
- BIt cannot be used with interfaces
- CIt requires changing the Adaptee
- DIt increases code complexity
6.In the provided example, how does the StripePaymentAdapter handle currency conversion when charging a user?
- AConverts rupees to dollars before creating a StripeChargeRequest
- BUses a fixed conversion rate to dollars
- CDirectly charges in rupees without conversion
- DConverts rupees to paise before creating a StripeChargeRequest
7.A developer is adapting a third-party SDK to their PaymentGateway interface. They decide to use multiple inheritance. Why might this be problematic in Java?
- AIt requires modifying the third-party SDK
- BMultiple inheritance is less efficient
- CJava does not support multiple inheritance for classes
- DIt increases the risk of runtime errors
8.Which of the following is an example of the Adapter Pattern in the Java Standard Library?
- AStringBuilder for mutable strings
- BArrays.asList() adapting an array to a List
- CThread for concurrent execution
- DHashMap for key-value pairs