Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8058967
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:31:00+00:00 2026-06-05T09:31:00+00:00

This example is highly contrived so bear with me. I have two Java classes,

  • 0

This example is highly contrived so bear with me.

I have two Java classes, Chair and Desk, which are coming from a third party (i.e. I can’t change them).

public class Chair {
  //...
}

public class Desk {
  //...
}

For each of these classes, I need to run a method, doWork(), which depends on DatabaseService. My approach is to create an adapter which implements the OfficeFurniture interface for each class.

public class ChairAdapter implements OfficeFurniture {
  //...
}

public class DeskAdapter implements OfficeFurniture {
  //...
}

public interface OfficeFurniture {
  public doWork(DatabaseService databaseService);
}

Finally, the question: Is it better to pass DatabaseService in the doWork() call, or to pass it in the constructors for ChairAdapter and DeskAdapter and store an instance in the class fields? Or is there another better approach?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T09:31:02+00:00Added an answer on June 5, 2026 at 9:31 am

    It depends, should the client of the adapter know anything about the database service? Probably not, so you put it in the constructor. If the client has to know something about the database service, then passing it is better.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I got this for example (from java obfuscation) with a highly overflowed
$class = new Class; $foo = json_decode($_POST['array']); In this highly contrived example, I have
This example is copied from a book on Android. As you can see from
This example is taken from w3schools . CREATE TABLE Persons ( P_Id int NOT
Given this highly simplified example: abstract class Animal { } class Dog : Animal
I have an issue about type compatibility - check this example: GLbyte vShaderStr[] =
This is a highly general thought, but let's use C# in this example. Given
I realize this example is entirely contrived, but I'm looking for a general rule
This example on the usage of std::forward is puzzling me. This is my edited
This example in the documentation shows how to query the Rally WS API, using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.