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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:00:31+00:00 2026-06-16T01:00:31+00:00

Is it bad practice for a class to pass itself to its own objects?

  • 0

Is it bad practice for a class to pass itself to its own objects?

For example:

public class MainView extends SurfaceView {
    Stack<GameObject> objs;

    public MainView() {
         new GameObject(this);
    }

    public void Add(GameObject obj) {
         objs.push(obj)
    }

    public void Remove(GameObject obj) {
         objs.pop(obj)
    }
}

public class GameObject {
    MainView parent;
    int state; 

    public GameObject(MainView parent) {
        this.parent = parent;
        parent.Add(this);
    }

    public void doStuff() {
        if(state == 1) {
              new GameObject(parent);
        } 
        else if(state == 2) {
              parent.Remove(this);
        } 
    }
}

I made an effort to remove static methods/variables. Now i have to pass the view to it’s own objects.
Is this a bad practice?
Should objects have logic or should the SurfaceView contain all the logic?

  • 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-16T01:00:32+00:00Added an answer on June 16, 2026 at 1:00 am

    Are you developing a game? If so I’d suggest you have a read this and this. The surfaceview should only have the job of rendering your game objects to the screen. Each game object however should hold the logic (its behavior) and a reference to a canvas to draw to which will eventually be drawn to the surfaceview. The overall logic of the game should however be in a class (eg. named world) that takes care of all the generating and managing of all the game objects.

    I hope this helps.

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

Sidebar

Related Questions

is this bad practice? using System.Web.Mvc; namespace WebInventaris.Utils.Session { public static class SessionControllerExtensions {
Is using an instance of a class to access static methods considered bad practice?
Is it bad practice to concatenate objects when used in this context: $this->template->head .=
Is it a bad practice to use domain objects in Sets or as keys
Would it be considered a bad practice to nest a private static class inside
Is it bad practice to use mutable objects as Hashmap keys? What happens when
Are circular class dependencies bad from a coding style point of view? Example: In
Is this a bad practice? like: function boo(){ require_once(class.moo.php); } ... ?
Is it a bad practice to use IoC container inside Factory Pattern? for example:
Is it bad practice to declare a typedef at class scope? Is it better

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.