programming design (another thread)

This is a discussion on programming design (another thread) within the C++ Programming forums, part of the General Programming Boards category; Hello I have another programming design question.. Lets say I have 3 classes like below: Code: class parser { }; ...

  1. #1
    l2u
    l2u is offline
    Registered User
    Join Date
    May 2006
    Posts
    630

    programming design (another thread)

    Hello

    I have another programming design question..
    Lets say I have 3 classes like below:

    Code:
    class parser {
    };
    
    class user {
    };
    
    class session {
    public:
    	std::list<user> m_list;
    };

    Session class is a 'main class' where most of the work is being done (in loop/s)..
    It has a list of user objects, where each user needs access to 1 particular parser object (parser class).

    I dont want each user to have its own parser object since that would be unneccessary..

    I wonder what is the best approach to make class user (user objects) be able to access data in one parser object?
    I know most of you would just pass parser object's reference to user class constructor, and then access data this way.

    Is there any better way/design pattern to achieve that?
    Maybe I shouldn't bother because this might be the best/easiest way?
    Or is there more 'professional' way?

    Another thing I'm unsure about..

    In case passing reference of parser object to user objects is the best way, where would you guys define parser object?

    Does this seem okay:

    Code:
    class session {
    public:
    	std::list<user> m_list;
    	parser m_parser;
    };
    Thanks for help
    Regards

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,328
    Is there one parser per session? Does the parser need to remain alive through multiple calls of session's functions? How many user functions require the parser? Does those functions require the same parser through different invocations?

    You could make the parser local to the session function that uses it if you only need it for that small lifetime.

    You could pass the parser by reference to the user functions instead of the class itself, if the user only needs it for certain functions.

  3. #3
    Massively Single Player AverageSoftware's Avatar
    Join Date
    May 2007
    Location
    Buffalo, NY
    Posts
    141
    How about giving the user class a static parser object?
    Code:
    class user
    {
    private:
        static parser yournamehere;
    };
    There is no greater sign that a computing technology is worthless than the association of the word "solution" with it.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Multithreading (flag stopping a thread, ring buffer) volatile
    By ShwangShwing in forum C Programming
    Replies: 3
    Last Post: 05-19-2009, 07:27 AM
  2. Replies: 2
    Last Post: 02-26-2009, 10:48 PM
  3. Win32 Thread Object Model Revisted
    By Codeplug in forum Windows Programming
    Replies: 5
    Last Post: 12-15-2004, 07:50 AM
  4. Simple thread object model (my first post)
    By Codeplug in forum Windows Programming
    Replies: 4
    Last Post: 12-12-2004, 10:34 PM
  5. How to make a thread sleep or std::recv timeout?
    By BrianK in forum Linux Programming
    Replies: 3
    Last Post: 02-26-2003, 09:27 PM

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