OOP Design

This is a discussion on OOP Design within the C++ Programming forums, part of the General Programming Boards category; I have a question regarding design of an application in an OOP sense... In the case that I am creating ...

  1. #1
    Registered User filler_bunny's Avatar
    Join Date
    Feb 2003
    Posts
    87

    OOP Design

    I have a question regarding design of an application in an OOP sense...

    In the case that I am creating a real time windows app (either a game or a graphical simulation) - I have a class which is the application class, CApp.

    Now most of the action occurs in the windows procecure, in this case AppWndProc(). And I am unsure how to make the Graphics class (which is probably going to be called frequently in response the WM_PAINT messages) communicate with the rest of the program.

    Now, my actual question is - what would be the best way to have the graphical part of the app interact with the windows procedure contained within the main app - would it be best to create an instance of the class as a private member of the CApp class? Or is it best to keep this object seperate?

    Thanks
    Code:
    class CApp
    {
    private:
        CGraphics cg;
    
    public:
         LRESULT CALLBACK AppWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
    };
    Visual C++ .net
    Windows XP profesional

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    I make the graphics objects members of my window class.

    The heirarchy I use is roughly:

    Code:
    struct rectangle {
    };
    
    struct windowbase : rectangle {
    };
    
    struct window : windowbase {
    hbrush brush;
    hbitmap bitmap;
    hpen pen;
    hfont font;
    hmenu menu;
    };
    
    struct wndclassex : WNDCLASSEX {
    };
    
    struct application : wndclassex, window {
    MSG msg;
    };
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  3. #3
    Registered User filler_bunny's Avatar
    Join Date
    Feb 2003
    Posts
    87
    Excellent, thanks for that - that is very helpful!
    Visual C++ .net
    Windows XP profesional

  4. #4
    Registered User filler_bunny's Avatar
    Join Date
    Feb 2003
    Posts
    87
    Actually, I have another question, (of course!) and it's related to the same app.

    I have created a logging class, essentially it takes a string describing an error and writes it to a file along with a time stamp. It outputs the info with some formatting data to HTML.

    Now - I new the methods in this class would probably end up being called by almost every object in the program. So I created the class with static methods (obviously never instantiating it) and called the methods using the scope resolution operator as such:
    Code:
    CLog::writeError("This is an error");
    Is this normally the way that most people would deal with an object like this? I couldn't think of a way of allowing each object to communicate with the logging object without inheriting from it (which would mean many instances of the one class and a bit of code bloat). It would also mean I would be opening and reopenning the file many times creating a performance hit.
    Visual C++ .net
    Windows XP profesional

  5. #5
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Originally posted by filler_bunny
    Actually, I have another question, (of course!) and it's related to the same app.

    I have created a logging class, essentially it takes a string describing an error and writes it to a file along with a time stamp. It outputs the info with some formatting data to HTML.

    Now - I new the methods in this class would probably end up being called by almost every object in the program. So I created the class with static methods (obviously never instantiating it) and called the methods using the scope resolution operator as such:
    Code:
    CLog::writeError("This is an error");
    Is this normally the way that most people would deal with an object like this? I couldn't think of a way of allowing each object to communicate with the logging object without inheriting from it (which would mean many instances of the one class and a bit of code bloat). It would also mean I would be opening and reopenning the file many times creating a performance hit.
    You could make your error logging class a singleton and then just have the single global copy and use it everywhere.
    "...the results are undefined, and we all know what "undefined" means: it means it works during development, it works during testing, and it blows up in your most important customers' faces." --Scott Meyers

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Mapping and Moving Relationships
    By Mario F. in forum Tech Board
    Replies: 7
    Last Post: 12-14-2006, 10:32 AM
  2. Implementing Inheritence into your design
    By bobthebullet990 in forum C++ Programming
    Replies: 6
    Last Post: 08-05-2006, 05:40 PM
  3. OOP design question
    By codec in forum C++ Programming
    Replies: 3
    Last Post: 05-12-2004, 03:48 PM
  4. Java and OOP design help???
    By mart_man00 in forum Tech Board
    Replies: 10
    Last Post: 08-24-2003, 05:52 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21