Grip in OO Design

I have two objects. Meeting object and Action object (action raised in a meeting). An action may also exist independently of the Meeting. I have two ways to relate the action raised in the Meeting:

  • I have a method in a meeting where I pass an Action object, for example, "addToMeeting (Action)". Inside the organization of the meeting, I then associate the action with the meeting. For this approach, although the meeting object needs to know about and use the methods in action, the object becomes connected.
  • I have a method at the Meeting where I just passed the action number to be bound as "addToMeeting (int actionID)". Great, now the meeting object does not need to know anything about the action but ...... now the code that adds the actions for the meeting should know how to get the identifier of the action, so it turned from this "meeting.addToMeeting (action)" to this " Meeting.addToMeeting (action.getID ()). "

For a good OO design, which approach should I use? Or is there a third way ...

+3
source share
4 answers

If you think that you are ever planning to bind to instances Meeting, these are actions, then it would be most advisable to make Meetingaware of Action, and not vice versa.

Actions, Meeting, , , . addAction(Action a) Meeting.

, , , " ".

Meeting Action , , IMeetingItem, , Meeting . Action IMeetingItem, - :

meeting.addItem( action );  // action treated as an IMeetingItem in this context

, Meeting, , , .

+5

, "Identifiable" getID() , Action

:

addToMeeting(Identifiable action);

do

this.actionId = action.getID();
+1

- , . , " factory", . Action, (, , ). , , factory .

0

I would go with option No. 1 - the connection is not bad, in your case, since there is a clear connection between the objects. I would go with option number 1. This gives you the opportunity for the meeting to have a property MeetingActions[]or something similar.

0
source

Source: https://habr.com/ru/post/1782311/


All Articles