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

  • Home
  • SEARCH
  • 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 7872673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:16:32+00:00 2026-06-03T02:16:32+00:00

Firstly, let me disclose that I’m NOT a Java developer, I currently develop in

  • 0

Firstly, let me disclose that I’m NOT a Java developer, I currently develop in C#, so any assumptions or statements I make regarding Java may be incorrect or ill informed.

When writing unit tests in .Net with mocked objects, 99% of the time we mock interfaces. It’s possible to mock classes but you’re only going to be able to have control over the virtual (thus mockable) methods.

In Java, as methods are virtual by default then I imagine that mocking a class is going to be just the same as mocking an interface because everything is going to be overridden with mocking behaviour.

So, is it still best practice to have dependencies on interfaces (and consequently mock interfaces in unit tests) in Java, or do most Java developers use classes to reduce the number of types (no need for an interface)?

  • 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-03T02:16:34+00:00Added an answer on June 3, 2026 at 2:16 am

    I’d mock interfaces in Java as well. I think that’s the whole idea: clients only know about the interface reference type. You can inject in a mock implementation behind it and the client is none the wiser.

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

Sidebar

Related Questions

Firstly, let me start by saying that I haven't ever directly used SQL views.
Firstly, let me say that I've been searching the Internet, rewriting scripts and I
Firstly, I do not have any malicious intent out of this question. I would
Firstly, let me introduce general architecture of a project. It is hierarchical. We develop
Well, the question is not intended to be that big. Let me explain the
Firstly, let me say that I've been on this issue for pretty much 2
Firstly, let me say that I know that http://sphinxsearch.com/docs/current.html#conf-sql-attr-string says strings can only be
Firstly, let me just say that I'm very new to JSR-170 and Jackrabbit/Lucene in
Possible Duplicate: Unrecognized attribute 'targetFramework'. Note that attribute names are case-sensitive Firstly, let me
Firstly, I was wondering if there was some kind of built in function that

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.