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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:37:38+00:00 2026-05-23T00:37:38+00:00

I have a class of boxes that need to move around in a grid,

  • 0

I have a class of boxes that need to move around in a grid, but need to access that grid’s coordinates in its methods. I don’t want my classes to inherit the grid unless they need to. Do I need to pass the grid to the classes as a parameter, or make the box classes inherit from the grid class? Thanks.

This is the edit. Let me clarify. The classes of boxes need to know the length and width of the grid. Therefore, I need to call inside the class functions like Grid.length() and stuff. I need it though, to give me the length and width of the grid that was created.

  • 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-23T00:37:39+00:00Added an answer on May 23, 2026 at 12:37 am

    General rule would be parameter.

    The question is is-a vs. has-a:

     Is the box a grid? 
         yes: # if so, then is it really a box???
             The box should inherit grid
         no:
             The box should get a reference to the grid 
                #(generally through a setter or constructor parameter).
    

    Edit


    An example:

    class Grid:
        def __init__(self,width=1,height=1):
            this.width = width; this.height = height;
    
        def getDimensions(self):
            return (this.width, this.height)
    
    class Box:
        def __init__(self, grid):
            this.__grid = grid; this.x = 0; this.y = 0            
    
        def verify(self):
            width, height = this.__grid.dimensions()
            if this.x < width and this.y < height:
                 print( "A-OK!" ); 
            else
                 print( "I am off the grid!!!" )
    
    
    grid = Grid();
    box = Box(grid);
    box.verify();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CLickableBox class that creates boxes for me and now I need
I have multiple multi-select boxes with the same class and i want to unselect
I have class grades that I need to check if a specific grade is
I have a series of horizontal div boxes that I need to add the
I have class that extend FragmentActivity in it I add fragment to layout as
I have class Meat extends Food { $var = Food::foodFunction… } I need to
I have a set of classes that describe a set of logical boxes that
Winforms .net 3.5 app. In my app I have a generic class that looks
I have a list of information sources in a database that I need to
I have several edit in Place text boxes that sit within a generated table

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.