How to organize classes for correct access

I'm fairly new to OOP, and right now i'm stuck on the correct way to allow multiple classes to have the correct access rights to each other.

So, i have three classes:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
  Class Controller;
//Handles communication outwards, keeps track of internal state
  public: 
    UpdateControllerState();
  private:
    ManageResponse(); etc.

  Class EventRecord;
// Keeps a pre-defined number of events in a list, keeps track of when and how many times these events occur
  Public: 
    UpdateEvents();
    GetEventData(); etc.
  Private:
    RegisterEventTrigger();

  Class EventHistory;
// Keeps a separate list of the history of the events triggered.
  Public:
    RegisterTriggeredEvent();
    ClearEventHistory();
    GetEventHistory();


So, the class Controller needs access to both the EventRecords and EventHistory to read out these lists, and to trigger UpdateEvents().
Meanwhile, EventHistory needs access to the RegisterTriggeredEvent() method to register a triggered event in the history list.

How do i organize this in a coherent way? Do i make an "EventHistory" object as a public member of EventRecords, and access it "through" EventRecords from the controller, or do i do it in another way? Or do i simply include the functionality of "EventHistory" in the EventRecords class instead of making a separate class for it?
Last edited on
You forgot to mention who owns what. From your second paragraph I assume that an EventRecord holds some number of EventHistories.

It seems that RegisterEventTrigger() is the only private member function that needs to be accessed by other classes. Is there any reason why it should be private?
As for how a Controller should access EventHistories, the question is: should Controller know about EventHistory, or is the existence of EventHistory an implementation detail of EventRecord?
Topic archived. No new replies allowed.