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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:17:59+00:00 2026-05-28T01:17:59+00:00

Let’s assume I have a class and whenever I set certain attributes bla ,

  • 0

Let’s assume I have a class and whenever I set certain attributes bla, foo (which can be set externally and internally) I want to call another method of the class, let’s call it onChangeFunction().

Would it be a good way to simply call onChangeFunction() when setting internal values directly, e.g.

function someFunction()
  // Some Calculations here ...
  this.bla = some_value;
  this.onChangeFunction()
end

or would it be better to also set those variables bla and foo ONLY by using the internal setter-methods because there is a certain action triggered with it and thus it would be a more clearly arranged code.

I even go a step further: Let’s say I don’t need an extern setter which can be called from outside (access type = public), would it than still be good to invent a private setter to do the same approach and only use the setter because of the triggered set-action?
EDIT: What I mean is the following: Even if I would NOT have a public setter (because there should not be a public access to set the variable, because it’s only an internal variable) would it be still good to have a setter which is private-only just because of the triggered action thing?

Thanks in advance!

  • 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-28T01:18:00+00:00Added an answer on May 28, 2026 at 1:18 am

    I think in the long term it is much less error-prone to always use a setter, and to call onChangeFunction() from within the setter.

    You don’t specify which programming languages you have in mind, but some languages allow one to define a “property” that looks like a data member but always calls a function when an attempt is made to change it. See, for example, property et al in Python.

    As to your second question, I don’t think there’s anything wrong with having a private setter.

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

Sidebar

Related Questions

Let's say you have a class called Customer, which contains the following fields: UserName
Let's say I have a dataset, which can be neatly classified using weka's J48
Let's say on a page I have alot of this repeated: <div class=entry> <h4>Magic:</h4>
Let's see if I make myself clear. I have an old set of scripts
Let's say I have the following entity: public class Store { public List<Product> Products
Let's say, I have a .NET 2 installed. Can I programmatically install version 4
Let's say I have a main folder in my website named test which contains
Let's suppose I have a Discussion model, and that a discussion can be tagged.
Let's say I have the string: hello world; some random text; foo; How could
Let's imagine I have a Java class of the type: public class MyClass {

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.