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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:52:37+00:00 2026-05-25T05:52:37+00:00

I have a main class called Main, in that Main class there is an

  • 0

I have a main class called Main, in that Main class there is an variable called State which is of int type. State variable contains a state ID which lets the program know in which state is it in (Menu, instructions screen…) In the Main class I have a object initiated from the Sprite class. Now my question is how to tell the object that the state has been switched (this one is easy, I can make this one pretty easily but the next part is giving me problems), and how can the object tell the Main class that he wants to switch states?

  • 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-25T05:52:37+00:00Added an answer on May 25, 2026 at 5:52 am

    This is what I understand from your question,

    • Main is the controller class that invokes Sprite instance methods
    • The State determines the method that is called on the Sprite instance

    In this case, the Sprite class should contain a static property called State (preferably this should be an enum rather than an int).

    It is the responsibility of the instance methods to update the state variable. On completion of execution of the instance method, the caller can check the state the instance is in and then appropriately determine the next course of action.

    A better approach is not to expose the state at all (unless it is required to be used by external objects). In your case, it appears that the state is only being used to determines the method that executes (I am guessing that you have a switch statement to do this).

    If you want to instance to execute a particular method based on its own state, then you could leave this decision to the instance itself, rather than having the controller decide. The instance could have a method (say Update() or Execute()) that execute the operation based on the context of the operation (like menu option, etc.). This method can decide which internal method to execute based on the static state member.

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

Sidebar

Related Questions

I have a main class in a program that launches another class that handles
I have a main window class built in Qt Designer and called Ui_MainWindow which
I have a file called hellowf.cs class MyFirstApp { static void Main() { System.Windows.Forms.MessageBox.Show(Hello,
I have the following code: class Program { static void Main(string[] args) { new
In my main Actionscript file i have a instance of a body class that
I have a main class that has a Sub procedure with no implementation. Any
I have made a helper class called Navigation that gets used on every page
I have a question about the 'Event Dispatch Thread'. I have a Main class
I have a small Java test app in Netbeans where the main() class reads
I am working on a class library using C#. I have designed 3 main

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.