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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T06:31:53+00:00 2026-06-08T06:31:53+00:00

Is it better to control variables and parameter only (mostly) in the upper areas

  • 0

Is it better to control variables and parameter “only” (mostly) in the upper areas of the call hierarchy

or

to save each class individually against wrong parameters, because you don’t know who may call it in the future.

I am in the moment a little ambivalent. But i tend to write some more ifs than leave classes unprotected.

What do you think?

  • 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-08T06:31:54+00:00Added an answer on June 8, 2026 at 6:31 am

    If your method is part of the public interface of a class (either public or protected) then you cannot trust the parameters that you are receiving, and therefore you should validate them. On the other hand if the method is private, you are in total control of the arguments you are passing and if you are sure you never pass invalid data then you can safely assume that they are right all the time and avoid any code to validate them.

    Now, what exactly is part of the public interface of your system may not be evident to anyone but yourself. Even when a class has public methods, the class where they are declared is totally encapsulated and inaccessible to other users, it may may be impossible to extend it or use it outside a given context, in those cases, your level of encapsulation could help you decide if you are truly in control of what is being passed as parameter and then you can decide if it is safer to validate the data or not in a given context. But in the moment you believe you can lose sight of what is being passed as parameter, then you should validate it, IMHO.

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

Sidebar

Related Questions

Which one is better (implicit control flow via return or control flow via if
Is there a better way to control the space between certain block elements.. i
I'm writing a simple calendar control for better understanding of WPF. I have a
Or is there any better suited 3rd party control for this purpose?
Which one is better from performance view user control or custom control? Right now
I'm creating a line chart control, and I need to write (or better say
what is the best free/open source WinForms progress bar control? (i.e. want a better
EDITED FOR BETTER UNDERSTANDING I made a custom control with propertise for some global
Main question: Is there a better way to accomplish creating a reusable control? So
I have a Treeview control with each item having a checkbox. At root level

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.