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 1110845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:27:17+00:00 2026-05-17T02:27:17+00:00

Since a few years, common sense seems to dictate that it’s better to program

  • 0

Since a few years, common sense seems to dictate that it’s better to program against interfaces rather than against implementations. For high-level code this indeed seems logical, e.g. if I have a complex solver in my application, it seems better to have something like this:

ISolver *solver = solverFactory.getSolver();
solver->solve(inputdata);

Rather than

Solver solver;
solver.solve(inputdata);

In the first code it is also easier to mock the solver, and thus, to unit test.

But my question is: at which level doesn’t it make sense anymore to use interface. E.g. if I have a ComplexNumber class (or String class, or whatever) in my application, then writing this:

IComplexNumber *complexNumber = complexNumberFactory.create(1,2);   // 1+2i

Seems much more complex (especially regarding performance) than writing:

ComplexNumber complexNumber(1,2);   // 1+2i

So, which elements are important in deciding whether something should be put behind an interface and when it shouldn’t be put behind 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-05-17T02:27:18+00:00Added an answer on May 17, 2026 at 2:27 am

    Reasons to move to an interface are when it makes things simpler or reduces coupling. (Thats what an interface is for).

    Reasons to move away from an interface are if it makes things more complicated or kills performance (but profile that to be sure). I’d argue that your IComplexNumber class actually makes the class heirarchy more complex unless you’re introducing a MockComplexNumber, but I doubt such a class would be usefull… and it will probably make make things slower, but I’d measure that.

    But don’t think you need to do everything one way, or that your decisions are fixed in stone. It’s pretty easy to convert to/from using an interface.

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

Sidebar

Related Questions

It's been a few years since my computer-language class and so I've forgotten the
Here is the code that cause me problem since few hours: TabItem newTab =
Since a few weeks I started playing with Symfony2. It seems a very powerful
It's been a few years since I've had to parse any files which were
I installed SQL Server Express 2005 a few years ago. Since then I've installed
Since a few years i am developing with IDEA again, and i am happy
I must admit it's been a few years since my RegEx class and since
I've had a blog since 2003. A few years ago, I moved it from
I'm using Lithium with phpActiveRecord using li3_activerecord. It's been a few years since I
Quite a few years ago, I remember that I struggled with a multiple site

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.