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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:35:02+00:00 2026-05-22T03:35:02+00:00

I have a quick question on best practice and if getters and setters are

  • 0

I have a quick question on best practice and if getters and setters are the best option in a specific case. The case is when I have class ‘A’ instantiating classes ‘B’ and ‘C’. Class A contains public getters and setters for classes B and C to access so data is centralised.

Is this best practice or would it be best to pass the data to classes B and C through parameters?

Thanks

Chris

  • 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-22T03:35:03+00:00Added an answer on May 22, 2026 at 3:35 am

    The short answer: it depends

    The long one: if you B and C classes encapsulate data and/or functionality that might be useful outside of the class A and A is “only” client of B and C, let them be instantiable independent of A and set into A with setters like setA/setB. This way other classes can possible use B and C for whatever reason. You could also take advantage of inheritance where instances with enhanced functionality get induced into class A during runtime (for example through Inversion of Control frameworks like JohnReeeves stated).

    If they only make sense in the context of class A, encapsulate functionality that only A directly uses, hide them from the outside world and parametrize by means of class A methods/properties. This gives you the freedom to change implementation of B and C so that no code outside get upset. A is a public interface so to say, B and C are internal implementation.

    And generally the more you can hide from your implementation the better, let the outside world know only as little as it neccessarily needs to know to function properly.

    So think about the extact goal of A, B and C, their relationship to each other and to the outside world and make you decision.

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

Sidebar

Related Questions

A quick question about best practice with PHP classes. I have seen people use
I just have a quick best practice question regarding custom cells in a UITableView.
Quick question on best practice. I have an AJAX application where there are 4
I have a quick question - is there a best practice in SQL Table
I have a quick question about encapsulating specific types with typedef . Say I
Have a quick question about what would be the best way to implement iterators
Hello $mostamazingforumforfastanswersever. I have a quick silly question; what is the best way to
I have read the following question Javascript and Anchor Tags, Best Practice? And it
I have a very quick question about how to utilise Zend_Db_Table with user specific
I have a quick question on the best way to show a particular message

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.