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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:01:45+00:00 2026-06-07T02:01:45+00:00

I am making a game that has several classes and each one do some

  • 0

I am making a game that has several classes and each one do some kind of specific task.

I am completely new to OOP and I was wondering what I should do to make my class instances communicate between each other without recurring to static classes, methods and properties, which seems like an awful thing to do.

I am self-taught programmer, and I realize I do a lot of bad practices. So far I managed to make this work making both classes static but I wanted to know what I should do to make my code as good as possible.

Also, it would be nice if you could recommend me some resources/books/articles so I can read more about this topic (communcation between instances).

Here is some piece of code so you understand what I am talking about.

class Program
{
    static void Main(string[] args)
    {
        Class1 instance1 = new Class1();
        Class2 instance2 = new Class2();

        // infinite loop
        while (true)
        {
            instance1.UpdateMethod(someValue);
            instance2.UpdateMethod();
        }
    }
}

class Class1
{
    int Property;
    UpdateMethod(int argument)
    {
        Property += argument;
        if(Property == 3000)
        {
            // I should change the state of instance2
        }
    }
}

class Class2
{
    UpdateMethod()
    {
        if(Time.GetTime() == SomeTime)
        {
            // here I want to change the state of instance1
        }
    }
}
  • 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-07T02:01:48+00:00Added an answer on June 7, 2026 at 2:01 am

    For an overview of common design patterns, I recommend

    http://en.wikipedia.org/wiki/Category:Software_design_patterns

    If there is a natural relationship between Class1 and Class2, it’s quite common for an instance of one to hold a reference to an instance of another. For example, if you have a Player class, and the player has a Weapon, define your class like this:

    public class Player
    {
        public Weapon Weapon { get; set; }
        // Other properties
    }
    

    Specifically in your case, it looks like you want to update an instance of Class1 from an instance of Class2. I would suggest that you define a property on Class2 that holds the related instance of Class1, just as in the example above.

    This is called the Composite Pattern.

    In software engineering, the composite pattern is a partitioning
    design pattern. The composite pattern describes that a group of
    objects are to be treated in the same way as a single instance of an
    object. The intent of a composite is to “compose” objects into tree
    structures to represent part-whole hierarchies. Implementing the
    composite pattern lets clients treat individual objects and
    compositions uniformly.

    Another pattern frequently used to act on an object instance is the Command Pattern.

    In object-oriented programming, the command pattern is a design
    pattern in which an object is used to represent and encapsulate all
    the information needed to call a method at a later time. This
    information includes the method name, the object that owns the method
    and values for the method parameters. Three terms always associated
    with the command pattern are client, invoker and receiver. The client
    instantiates the command object and provides the information required
    to call the method at a later time. The invoker decides when the
    method should be called. The receiver is an instance of the class that
    contains the method’s code. Using command objects makes it easier to
    construct general components that need to delegate, sequence or
    execute method calls at a time of their choosing without the need to
    know the owner of the method or the method parameters.

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

Sidebar

Related Questions

I'm making a mobile game that has some complex game logic. I'd like to
I am making a game that has its own level editor. The editor simply
I'm making a multiplayer flash game that has a lot of graphics/code. I'm having
I am making an android game that should delete some falling images from the
I'm making a new game that generates a huge grid (lets say 1000x1000). The
Let's say I'm making an Use Case for a game that has a scoring
I'm developing an Android game that has to download some assets to the SD
I am making a game that has a table (attack bonuses). What is the
i need some advice. i have 2 classes for a game that i am
I am making a game. The game has 1 main loops: //draws a new

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.