I just started learning about design patterns, and I'm having trouble with some should-be-simple concepts. The concepts of some of these patterns make sense, but I'm struggling with how I should implement them in C++.
Let's saying I'm working on a problem that implements an observer problem. Let's assume there is only a single observer. That leaves two objects that need to communicate: the subject and the observer.
Conceptually, what this pattern is attempting to do is very simple to understand. However, I'm getting bogged down by questions like: where do they objects live? Must they both live within some container? How do they actually make requests from one another?
Regarding that last question, is it necessary for each object to a have a data member that references the other object? As in, must the subject contain a pointer to the observer, and must the observer contain a pointer to the subject?
So stepping away from the observer. If I have any two objects that are dependent to each other (uni-directionally or bi-directionally), is it necessary that each object have a pointer to its respective object?
Thank you,
Aucun commentaire:
Enregistrer un commentaire