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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:52:59+00:00 2026-05-20T18:52:59+00:00

Does anyone have any thoughts on passing full objects as variables as opposed to

  • 0

Does anyone have any thoughts on passing full objects as variables as opposed to only pointers to the functions of the full object?

For example, I have a Dice object with two methods:

  • RollDice(), randomizes the dice count
  • GetCount(), retrieves the value

Now, I need to utilize the dice for more than just player moving, other objects need to be able to look at the Dice as well. Now, it seems wrong to me to pass the whole Dice object to these other objects, since then those objects would ‘technically’ be able to re-roll the Dice. Is it good or bad programming to pass only the GetCount function pointer to these other objects? Essentially saying “I’m not giving you the Dice, but I’ll show you how to read them.”.

Thoughts?

  • 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-20T18:52:59+00:00Added an answer on May 20, 2026 at 6:52 pm

    It seems that its an excellent oportunity to use the OBSERVER PATTERN (GoF);

    public class Dice
    {
        private List<IDiceObserver> observers;
        public void RegisterObserver(IDiceObserver observer)
        {
            this.observers.Add(observer);
        }
    
        private Int32 count;
        public Int32 Count
        {
            get
            {
                return this.count;
            }
            private set
            {
                this.count = value;
                foreach (IDiceObserver observer in this.observers)
                    observer.DiceRolled(new DiceParameters(this.count));
            }
        }
    
        public void RollDice()
        {
            this.Count = new Random(DateTime.Now.Millisecond).Next();
        }
    
        public Dice()
        {
            this.observers = new List<IDiceObserver>();
        }
    }
    

    Do you need any further explanation on pattern, or other classes implementations????

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

Sidebar

Related Questions

Does anyone have any pointers to good resources concerning mesh networks? Maybe I'm not
Does anyone have any thoughts on this method? I have did some performance testing
Does anyone have any thoughts about making Simile read data from a database without
Does anyone have any idea what the practical differences are between the System.Collections.Specialized.StringDictionary object
Does anyone have any idea how to change the thickness of the text pointer
DOes anyone have any good information with regards to when to log, I was
Does anyone have any tips that could help speed up a process of breaking
Does anyone have any useful advice/links to information about working with mp3 files in
Does anyone have any advice or techniques for deploying SSIS packages to the Integration
Does anyone have any experience querying FlexLM? (At a minimum) I need to be

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.