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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:53:25+00:00 2026-05-26T08:53:25+00:00

i am thinking about design for such simple exercise as Man in Maze. I

  • 0

i am thinking about design for such simple exercise as Man in Maze.

I would like to make Maze object, put some Man objects inside it and call solve() for each to get out of Maze.
Man should know nothing about Maze. It just can try to go and find way out.

Here is how i see it:

    maze = Maze.new

    man1 = Man.new
    man2 = Man.new
    man3 = Man.new

    maze.put(man1,man2,man3)

    maze.men.each do |man| { man.solve }

But how to implement body of these classes?
How can man know how to walk inside Maze unless I give Maze instance to him?
But if i do that:

    maze.put(man1(maze),man3(maze),man2(maze))

What the reason to put men inside Maze if I can just give Maze instance to them?

This is what i don’t understand and can’t find elegant solution.

  • 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-26T08:53:25+00:00Added an answer on May 26, 2026 at 8:53 am

    Think of it this way: what data belongs with each class? What methods belong with it to work with that data? This is object-orientation: the bundling of data and relevant code.

    The Maze class doesn’t need to know about any men. It’s a maze. All it is are some walls, some structure. Build it as such, as if nothing outside of it exists. Make some methods to obtain information about the maze, such as whether there’s a wall at some point, a corner, a junction…

    The Man class is, in your case, conceived for a single purpose: find his way out of the maze. A Man therefore should have a position in the maze (part of his data) and some methods that help him look for the exit. Some depth-first search algorithm, for example.

    Of course, you could have some collection of all men currently in a Maze embedded in the maze itself. But that’s not necessary. You could use any other collection to hold the men and iterate over them.

    maze = Maze.new
    
    man1 = Man.new(maze)
    ...
    men = Array.new
    men[0] = man1
    ...
    
    men.each do |man| {man.solve}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am thinking about the design of an iPhone app I'd like to create.
I've been thinking about this object oriented design question for a while now and
How would it be possible to design an online-antivirus service. I was thinking about
I am thinking about a DB Design Problem. For example, I am designing this
I'm thinking about SEDA. We design at the moment an application (which is running
Maybe the need to do this is a 'design smell' but thinking about another
As I am learning more about rails, and breaking my design thinking from ASP.Net
I'm new to DDD and am thinking about using this design technique in my
One way of thinking about this is: if we care about the design of
I'm thinking about attempting to design a new framework architecture aimed at allowing 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.