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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:31:14+00:00 2026-06-05T19:31:14+00:00

I’d like some guidance on which class should hold certain information. If I have

  • 0

I’d like some guidance on which class should hold certain information. If I have a ‘Mobile Object’ that moves around within a ‘Space Object,’ does the Mobile Object really care where it is within the Space Object, how fast it’s moving, and in which direction?

It certainly seems convenient to assign a property to the Mobile Object for ‘Location,’ but I don’t think it really has any concern for that. So I’ve come up with:

class Mobile
    {        
        //some properties/fields/etc

        event EventHandler<MovementEventArgs> move;

        public void Move(Vector direction)
        {
            raiseMove(direction);
        }

        private raiseMove(Vector direction)
        {
            EventHandler<MovementEventArgs> handler = move;
            if (move != null)
                handler(this, New MovementEventArgs(direction));
        }
    }

class Space
    {
        Mobile someObject;
        Vector someObjectLocation;

        public Space()
        {
            someObject = new someObject();
            someObject.Move += HandleMobileMove;
        }

        public void MoveSomeObject(Vector direction)
        {
            someObject.Move(new Vector(1,0));
        }

        private void HandleMobileMove(object sender, MovementEventArgs e)
        {
            someObjectLocation += e.Direction;
        }
    }

That’s a bit hastily written… but I hope it gets my point across. In summary: should the Mobile hold a location, or the Space? Who should control the movement?

  • 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-05T19:31:15+00:00Added an answer on June 5, 2026 at 7:31 pm

    In WPF, the Canvas object is responsible for knowing the location of its children. That would lend credence to your approach (which uses a similar structure as an Attached Property).

    If you are uncomfortable with the location being stored in the Space object, you could also use the Decorator pattern to attach additional information to the Mobile objects. This would give you the option of positioning an object or not, without the object itself caring.

    When getting the collection of children, you could filter out only those objects which employ your location decorator (perhaps using the OfType extension method) and do what you need with them. You’ll have to convert to using interfaces rather than hard class references. That would probably be a good thing, though.

    In the end, though, it depends on what your Space and Mobile objects are doing. If the Space object is displaying the Mobile objects (like Canvas), then it needs to know location information but the Mobiles don’t. On the other hand, if the Mobiles themselves are using their location information to track something or perform some task (and the Space object doesn’t care, perhaps only providing bounds, etc.), then it may be best to store that information with them.

    To drive the point home a bit further, ask yourself this question: if I change the location, who cares? A Control is WPF is generally not affected by its Top and Left coordinates but its container control is, so it makes sense to store that information in the container. If you change the location of a Mobile, does that have any effect on the Mobile or how it does its job? Does Space behave differently if Mobile X moves from Y to Z?

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I have some data like this: 1 2 3 4 5 9 2 6
For some reason, after submitting a string like this Jack’s Spindle from a text
I have just tried to save a simple *.rtf file with some websites and
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from

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.