Questions tagged [adapter]

25 questions
32
votes
6 answers

How do I test a system where the objects are difficult to mock?

I am working with the following system: Network Data Feed -> Third Party Nio Library -> My Objects via adapter pattern We recently had an issue where I updated the version of the library I was using, which, among other things, caused timestamps…
26
votes
4 answers

How should I add functionality to an object that already exists?

I have an interface that has a certain amount of well-defined functionality. Let's say: interface BakeryInterface { public function createCookies(); public function createIceCream(); } This works well for most implementations of the interface,…
user8
16
votes
1 answer

Unit testing an API client and wrappers

I've been going round in circles trying to figure out the best way to unit test an API client library I'm developing. The library has a Client class which basically has a 1:1 mapping with the API, and an additional Wrapper class which provides a…
Joseph Mansfield
  • 439
  • 3
  • 11
7
votes
3 answers

How to use 'Adapter' without any changes in the existing code in c++

Here we have TV class and DVD class as example: class TV { public: TV(); virtual ~TV(); void on() const; void off() const; }; class DVDPlayer { public: DVDPlayer(); ~DVDPlayer(); void SetCD() const; void…
Anton
  • 91
  • 6
6
votes
2 answers

To which Clean Architecture layer should repositories implementations belong?

It's very common to see this use of repository in projects using clean architecture: interface Hero { } interface HeroRepository { findById(id: number): Hero; } class FetchHeroUseCase { constructor(private heroRepository: HeroRepository)…
6
votes
1 answer

I need to be able to adapt my type to theirs, and theirs to mine

I have a situation where I have an external library. In short, I need to be able to adapt my type to theirs, and theirs to mine. The library has a collection like so: interface IExternalCollection { void Add(IExternal item); IExternal…
Chris Wohlert
  • 529
  • 3
  • 15
5
votes
1 answer

DDD: Viable approaches to integrating with external systems (Adapters, ACLs, Bounded Contexts)

Our team have been debating approaches to integrating external or third party systems when using DDD. The literature is extensive, but sometimes contradictory. Just like a UL helps us better understand and communicate about the domain, we wanted to…
5
votes
3 answers

Is there an efficient way to adapt data from a structure to another in c++?

I'm writing an interface between two configuration models that use different structures. While I know that there is no "magic" way to do the translation from a structure type to another, I wandered if there might be some best practices or an…
Alex Garcia
  • 388
  • 2
  • 10
3
votes
2 answers

C# Adapter pattern - Condition based execution

I am building a solution for the recruitment division of an organization. The requirement is to create new employee records in the organization's database for the applicants who have cleared the interviews and are joining the organization. I have…
Dinny
  • 141
  • 4
3
votes
1 answer

C# Dependency Injection with Adapter Pattern

In the following code sample, I have a client that works through a controller. In my specific case the controller establishes a session to an address on a GPIB bus. An instance of this is then injected into the client class, which in my case is a…
2
votes
1 answer

Is this a valid GoF Adapter example?

After visit dozens of pages searching a "non-sockets-or-iphone-conceptual-example" of Adapter Pattern, I have found this one: Lloyds bank is an international bank offers services worldwide. For offshore account holders, the tax rate is 0.03%.…
celsowm
  • 243
  • 1
  • 11
2
votes
0 answers

Manage web service with different version

My vendor can log in to a master management system (System A) which manage multiple subscriptions of a SaaS (System B). Each System B is hosted separately on an isolated server. System A and system B communicate through REST API. My vendor holds the…
kingwei
  • 147
  • 2
2
votes
1 answer

Is an Adapter pattern a Proxy pattern? If not, why not?

A common use of the adapter pattern is to support functionality that isn't actually supported in an underlying class. For example, if I use an API to interact with a Samsung Smart TV, I might want to add functionality not available through the API.…
moonman239
  • 2,023
  • 4
  • 18
  • 23
2
votes
2 answers

Should one define an interface and code an adapter for it whenever a dependency is found?

Given a particular third-party class/library you want to make use of, the simplest thing to do would be to just hardcode API calls to it through your application. On the other hand you have the possibility of defining a interface that generically…
deprecated
  • 3,297
  • 3
  • 20
  • 26
1
vote
1 answer

Adapt very different adapters to an Interface

I'm building a service to send push notifications to the user. At first, I designed an Interface for the push notification adapters, something like this: interface PushNotificationAdapterInterface { /** * @throws NotificationException …
1
2