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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:37:43+00:00 2026-06-06T09:37:43+00:00

I work on developing an external API. I added a method to my public

  • 0

I work on developing an external API. I added a method to my public interface :

public void AddMode(TypeA mode);
public void AddMode(TypeB mode); // the new method, TypeB and TypeA are not related at all

It looked good, until one test broke that was passing a null . That made the compiler confused with ambiguous call. I fixed the test with casting the null.

However my question is :

  • Should I change the name just because of this?
  • Or should let the client do the cast as I did? (if they pass null for whatever reason)

What is the best in this case while designing APIs ?

Edit :

the call was like this AddMode(null) , not like :

TypeA vl = null; 
AddMode(v1); // this doesn't cause a problem
  • 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-06T09:37:45+00:00Added an answer on June 6, 2026 at 9:37 am

    An API should be designed so that it’s easy to use correctly and hard to use incorrectly.
    Your API is easy to use correctly:

    AddMode(new TypeA());
    

    does compile.

    It’s harder to use incorrectly:

    AddMode(null);
    

    does not compile. The user ist forced to do something like

    AddMode((TypeA)null);
    

    Which should make him think, whether this is expected usage. So I think your API is OK as it is.

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

Sidebar

Related Questions

I'm new in Infopath developing, please help. :( So I'm developing work-flow with custom
I have 5 years of work experience in developing WEB and WIN application using
I work in Dreamweaver and Eclipse when developing. I think Dreamweaver has a really
I'm developing a web application for a company which I work for. My team
I'm developing web app that user can save his/her work to server. The data
I'm developing a script generator to automatize some processes at work. It has a
I'm developing an application on two different machines (home and work) and while the
I am currently developing an application to work with WAV files. I want to
In my work, I'm developing a Viewer client for a Offshore simulation server, using
Hi I am developing an application that needs to work with a complex domain

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.