Sign in to follow this  
Quat

drawing program design

Recommended Posts

I am working on a drawing program with various tools that lets the user manipulate geometric objects. I have a class for each tool and the application keeps a pointer to the "active" tool. I store the data (a list of geometric objects) in a "document" class instance. 1. The various tools need access to the list of objects (so they can select and manipulate). So I am going to pass a reference to my application's document instance. Should I make the Tool classes friends with the document class, or provide a public interface? 2. Each tool has a graphical depiction as well. I was going to have each tool class responsible for loading its graphic resource. Is this a good idea, or should I allocate the resources in one place and pass references to the resources to each tool?

Share this post


Link to post
Share on other sites
Quote:

1. The various tools need access to the list of objects (so they can select and manipulate). So I am going to pass a reference to my application's document instance. Should I make the Tool classes friends with the document class, or provide a public interface?

I would recommend against using friend classes, if it can be avoided. I personally would go with the second option, or even provide a separate manager class used to store and manage the list of objects. ...This is assuming I understand the question completely.

Quote:

2. Each tool has a graphical depiction as well. I was going to have each tool class responsible for loading its graphic resource. Is this a good idea, or should I allocate the resources in one place and pass references to the resources to each tool?

It is usually better to have all resources managed within a single location, and have the other classes request resources as needed. So, I would go with your second option here.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this