# Project classing

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

## Recommended Posts

Im wondering how to go about the following task I have my application consisting of one class, lets say AppClass, this object contains 4 windows, yet all these windows need access to the data from the Appclass.

class Appclass
{
HWND a,b,c,d;
}


The windows all get made from the AppClass::constructor(), and all have their own wndProcs(), now the only way i can see of doing this is to have a global pointer to the Appclass object, which all the wndProcs() can access. But then this would involve having all the data in the Appclass needing to be public, unless i have a getFunction() for each variable, which will be silly. Any ideas?

hmmm, Anyone?

##### Share on other sites
How will the data from AppClass be used? What is AppClass for, anyway (it has a pretty undescriptive name as far as I can tell)? Why do these windows need to know about this data?

##### Share on other sites
Separate Model from View. Create a data model that does not know anything about views (such as windows). Then, create a View composed of four windows, which references a data model and displays the data from it.

##### Share on other sites
Thanks for the replies guys, i'll describe it a little more.

Ive basically created a class that is part of my game, that works on the particle effects, and the windows used above play no part in the actual running of the class, and are only used to display debug information. With the information being split into four sections, hence the four windows.

So basically the windows are just being used to display information from the class, the windows also have a few buttons and spinners etc to act on this data, so that when some interacts with the buttons, the information needs to be sent back to the class object so that it can adjust things as needed.

So the windows arent needed for the running of the class, they're just another way to interact with it

But with the way windows and wndprocs work, i cant come up with a way to pass the information back and forth from the wndproc to the class object.

take for example

class Appclass{HWND a,b,c,d;float speed;}wndprocForWindowA{case spinner://adjust speed}

Quote:
 Separate Model from View. Create a data model that does not know anything about views (such as windows). Then, create a View composed of four windows, which references a data model and displays the data from it.

I know i forgot to mention in my first post, but the windows also need to adjust data in the class, so do you mean have each windproc have a reference to the class object?

##### Share on other sites
Quote:
 Original post by wforlBut with the way windows and wndprocs work, i cant come up with a way to pass the information back and forth from the wndproc to the class object.

Quote:
 I know i forgot to mention in my first post, but the windows also need to adjust data in the class, so do you mean have each windproc have a reference to the class object?
The WindProc should forward messages to the appropriate member function of the view (which is now technically a view/controller mix, but it's not problematic), which can then manipulated the model.

##### Share on other sites
ah, thats great, thanks

so,

-Data class doesn't know about view class

-View class has four windows
-Each window gets a pointer to the view class as USER_DATA
-Each Window has its own wndProc,
-When a window receives a message, it casts that USER_DATA to the ViewClass pointer, and does something like (suedo)

(viewClass*)USER_DATA->SendMessage(message, p1, p2, p2)

-View class receives this message, and then with its Data reference, adjusts the data, in the data class, but isnt this still going to require the data classes varibles to all be public, unless i define a setfunction for each one?

##### Share on other sites
Quote:
 Original post by wforl-View class receives this message, and then with its Data reference, adjusts the data, in the data class, but isnt this still going to require the data classes varibles to all be public, unless i define a setfunction for each one?

If your data model is an elementary aggregation (that is, a group of fully independent variables with no constraints between them), then you can use a POD aggregate (a structure with public members) to represent it. It will be simpler than having to define set functions everywhere.

If your data model has additional constraints (such as variable "left" being smaller than variable "right", or things like that), then you cannot 'set' individual values anyway (that would break the constraints) so you will need functions that are able to change several values at a time.

Ultimately, your underlying data model ideally exposes exactly zero data, and instead exposes functions which can be used to change the state of the data model (not the data).

##### Share on other sites
Thanks for your help toothVyk, (easier to say than ToohrVyk :) )

1. 1
2. 2
3. 3
4. 4
5. 5
Rutin
17

• 9
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631420
• Total Posts
2999990
×