Quote:Original post by Whiles
Thank you for the suggestions!!
So.. Do you suggest to create simple classes such as WindowWin32, WindowLinux, etc ? I was looking for a way to develop the platform specific classes around an interface or something similar to not change the code in lots of parts, but if you think it's not a good design I'll avoid this method...
Uh, yeah, isn't that what you're already doing? Here's what I'm thinking:
enun WINDOW_TYPE{/*stuff*/};class IWindow;class IPlatform{ public: virtual IWindow* CreateWindow(int, int, int, int, WINDOW_TYPE) = 0; //and so on, all pure-virtual};class IWindow{ public: virtual int get_ypos() = 0; virtual int get_xpos() = 0; virtual int get_width() = 0; virtual int get_height() = 0; virtual void setPosition(int, int) = 0; //functions for binding menus, suchlike //again, all abstract};
The I* naming convention just indicates that the classes are pure interface. Notice there are no protected members. Now an implementation, very pseudo because I have no clue about windowing :D.
class Win32Window;class WindowsPlatform: public IPlatform{ IWindow* CreateWindow(int x, int y, int w, int w, WINDOW_TYPE type){ return (IWindow*) new Win32Window(x, y, w, h, type);//don't inline this } //notice how the return is still the interface type, but actually a real class is returned //same for all other funcs}class Win32Window: public IWindow{ Win32Window(int, int, int, int, WINDOW_TYPE); int get_xpos(); int get_ypos(); int get_width(); int get_height(); void setPosition(int, int);}