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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T09:04:36+00:00 2026-06-14T09:04:36+00:00

Take the following code: private var m_iQuanitity:int; public function get quantity():int { return m_iQuantity;

  • 0

Take the following code:

private var m_iQuanitity:int;
public function get quantity():int
{
    return m_iQuantity;
}

That seems to make perfect sense. You can see what the quantity is from an outside class without any problems, but you can’t really mess with it at all. Now take the following code:

private var m_acUsers:ArrayCollection = new ArrayCollection();
public function get users():ArrayCollection
{
    return m_acUsers;
}

In that case you can’t really set the variable directly, but you can still do just about everything else under the sun to it without any problems. You can call its AddItem and RemoveItemAt functions, which can do quite a bit to “set” the variable.

Does it still make sense to do this? I know you can create a duplicate ArrayCollection and just pass the duplicate back to avoid allowing it to be set, but doing stuff like that all over the place, purely for defensive programming, can waste a lot of CPU time. So I guess I’m asking if it still makes sense anyway, how so, and if I’m missing the point of using get and set completely? Thanks!

  • 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-14T09:04:37+00:00Added an answer on June 14, 2026 at 9:04 am

    Syntactically there is nothing wrong with what you’ve got, but the second example does break down the concept of ‘get’ by making more than a read only property. If you need to adhere to a read only policy, then you’ve broken that since now you can manipulate the ArrayCollection.

    In the end it comes down to what it is you’re tying to do. Does it matter for the project that you can change the value? If you’re working on a project with more than a few people, this type of coding will require you to either add a comment or have you explain what you’re doing. When ever you do something outside of the norm, that can add confusion, so it’s always best to simplify and stick to what is expected, avoiding having to explain something.

    Also, I can think of a few ways this could cause problems – changing values outside of the function if you pass the returned property off to other classes that don’t know where it came from and having internal code in the original class fail.

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

Sidebar

Related Questions

Take the following code: public static string ReverseIt(string myString) { char[] foo = myString.ToCharArray();
Take the following C code as an example: char buffer1[5]; int* ret; printf(Buffer1 is:
Take the following lines of code that would work fine in a c# asp.net
Take a look that the following code snippet: A a = null try {
I have the following code to take a screenshot of a window, and get
take a look at the following code var a = new View(); a =
Ok, consider the following code: private const int THRESHHOLD = 2; static void Main(string[]
Take the following code: public interface InterfaceA { } public interface InterfaceB { }
I have the following code: private static HashSet<SoloUser> soloUsers = new HashSet<SoloUser>(); public void
Let's take the following code: public class Test { class A { public A()

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.