Jump to content
  • Advertisement
Sign in to follow this  
YoYoFreakCJ

putting methods/properties in a sub class

This topic is 3259 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I made a few classes which have many properties and methods, so I was thinking of a way to group them. My idea looks like this: Let's say I have a GUI component class, having several properties for BackColor, ForeColor and some more. To see all of those Color-properties in one hit, I would put all of them in a new public sub class called "Colors". In that class, I simply have all the Colors, and I refer to them in the main class. Putting methods in there would be the same way, except that I also pass an instance of the main class to the sub class in the ctor, so the methods have something to work with. Here is an example:
public class Label
{
    public class Colors
    {
        public Color BackColor { get; set; }
        public Color ForeColor { get; set; }
    }

    public class Methods
    {
        private Label _instance;

        internal Methods(Label instance)
        {
            _instance = instance;
        }

        public void SetText(string newText)
        {
            _instance.Text = newText;
        }
    }

    public string Text { get; set; }
    private Colors _colors;
    private Methods _methods;

    public Label()
    {
        _colors = new Colors();
        _methods = new Methods(this);
    }

    public void Draw()
    {
        drawText(Text, _colors.ForeColor);
    }
}

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!